Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ write a program that first reads an integer for the array size, then reads n

ID: 3768579 • Letter: C

Question

C++

write a program that first reads an integer for the array size, then reads numbers into the array, computes their average, and finds out how many numbers are above average.

Hint: Use the new operator to create new memory. In addition to the requirements listed with the exercise:

Display the contents of the array, the average, and the number of values above the average.

Test the program using any values you pick for two cases:

array size = 4

array size = 8

Turn in a copy of the program as well as the output for the two test cases

Explanation / Answer

The code for your requirement is:

#include <iostream>
using namespace std;

int NumbersAboveAverage(int Array[], int size, double avg)
{
int count = 0;
for(int i = 0; i < size; i++)
if(Array[i] > avg)
{
cout<<Array[i]<<" ";
count++;
}
return count;
}
double findAverage(int Array[], int size)
{
double sum = 0;
for(int i =0; i < size; i++)
sum += Array[i];
return sum/size;
}
int main()
{
int sizeOfArray, Array[20];
double average;
cout<<"Enter the size of the array: ";
cin>>sizeOfArray;
cout<<"Enter "<<sizeOfArray<<" elements into the array: ";
for(int i = 0; i < sizeOfArray; i++)
cin>>Array[i];
average = findAverage(Array, sizeOfArray);
cout<<"The average of the given numbers is: "<<average<<endl;
cout<<"Numbers above the average are: ";
int count = NumbersAboveAverage(Array, sizeOfArray, average);
cout<<endl;
cout<<"Total numbers above the average are: "<<count<<endl;
}

If you have any further queries, just get back to me.....

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote