Question

Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a...

Question: In C++

Write a correct and complete C++ program th... Bookmark In C++ Write a correct and complete C++ program that inputs 20 integer values from the user and performs three calculations. In the main function, input the values from the user. As part of your answer, write a sub-function, named calcAvg (), which takes two arguments and returns the average of all the integers. Also write another sub-function, named reverseArray (), which takes two arguments and reverses the order of the numbers. That is, for example, if the input numbers were 5,3,7, then reverseArry would change the order to 7,3 ,5. Include a final sub-function named printArray (), which takes two arguments and prints the array. Assumptions to be made: you do not have to check errors in the input values, i.e., all input values can be stored as type int.

Please Show the output

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for you:

#include <iostream>
using namespace std;
//Include a final sub-function named printArray (), which takes two arguments and prints the array.
void printArray(int numbers[], int size)
{
for(int i = 0; i < 20; i++)
cout<<numbers[i]<<" ";
cout<<endl;
}
//Write another sub-function, named reverseArray (), which takes two arguments and reverses the order of the numbers.
void reverseArray(int numbers[], int size)
{
for(int i = 0; i < size/2; i++)
{
int temp = numbers[i];
numbers[i] = numbers[size-i-1];
numbers[size-i-1] = temp;
}
}
//Write a sub-function, named calcAvg (), which takes two arguments and returns the average of all the integers.
double calcAvg(int numbers[], int size)
{
double sum = 0.0;
for(int i = 0; i < size; i++)
sum += numbers[i];
return sum / size;
}
int main()
{
//In the main function, input the values from the user.
int numbers[20];
for(int i = 0; i < 20; i++)
{
cout<<"Enter #"<<i+1<<": ";
cin>>numbers[i];
}
printArray(numbers, 20);
cout<<"The average of the elements in the array are: "<<calcAvg(numbers, 20)<<endl;
reverseArray(numbers, 20);
printArray(numbers, 20);
}

And the output screenshot is:

Add a comment
Know the answer?
Add Answer to:
Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C only Please! This lab is to write a program that will sort an array...

    In C only Please! This lab is to write a program that will sort an array of structs. Use the functions.h header file with your program. Create a source file named functions.c with the following: A sorting function named sortArray. It takes an array of MyStruct's and the length of that array. It returns nothing. You can use any of the sorting algorithms, you would like though it is recommended that you use bubble sort, insertion sort, or selection sort...

  • c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers...

    c++ no pointers just follow instructions Write a program (array.cpp) that read positive floating point numbers into an array of capacity 100. The program will then ask for one of three letters(A, M or S). if the user inputs something other than one of these letters, then the program should ask for that input until an A, M, or S is entered. A do-while loop should be used for this. If the user inputs an A, then the program should...

  • You must write a C program that prompts the user for two numbers (no command line...

    You must write a C program that prompts the user for two numbers (no command line input) and multiplies them together using “a la russe” multiplication. The program must display your banner logo as part of a prompt to the user. The valid range of values is 0 to 6000. You may assume that the user will always enter numerical decimal format values. Your program should check this numerical range (including checking for negative numbers) and reprompt the user for...

  • 1) Translate the following equation into a Python assignment statement 2) Write Python code that prints...

    1) Translate the following equation into a Python assignment statement 2) Write Python code that prints PLUS, MINUS, O ZERO, depending on the value stored in a variable named N. 3) What is printed by: 3 - 1 while 5: while 10 Print ) Page 1 of 9 4) Write a Python while loop that reads in integers until the user enters a negative number, then prints the sum of the numbers. 1-2 of 9 4) Write a Python while...

  • Write a C++ program that simulates playing the Powerball game. The program will generate random numbers...

    Write a C++ program that simulates playing the Powerball game. The program will generate random numbers to simulate the lottery terminal generated numbers for white balls and red Powerball. The user will have the option to self-pick the numbers for the balls or let the computer randomly generate them. Set the Grand Prize to $1,000,000,000.00 in the program. Project Specifications Input for this project: Game mode choice – self pick or auto pick Five numbers between 1 and 69 for...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

  • C++ this program will get two integers from the user. The program will 1. call getProduct...

    C++ this program will get two integers from the user. The program will 1. call getProduct (int, int, int &); where the first two arguments are the two input integers and third one is the product of these 2 integers. 2. call printEvenAscending (int, int); where the two arguments are the two input integers. This function will print all -even numbers between the two arguments in an ascending order. Note, the two input integers could be in any order (such...

  • c++ program Exercise #1: Index of the Minimum Write a function main() that prompts the user...

    c++ program Exercise #1: Index of the Minimum Write a function main() that prompts the user to input a positive integer n, then calls the function generate() which generates n random numbers in the range [11, 217] inclusive. The function main() also calls the function indexMin() which finds the smallest random number and its index. The function main() prints the random numbers and the two values produced by the function indexMin(). Sample input/output: How many integers: 9 The 9 random...

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • Write a complete program that uses the functions listed below. Except for the printOdd function, main...

    Write a complete program that uses the functions listed below. Except for the printOdd function, main should print the results after each function call to a file. Be sure to declare all necessary variables to properly call each function. Pay attention to the order of your function calls. Be sure to read in data from the input file. Using the input file provided, run your program to generate an output file. Upload the output file your program generates. •Write a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT