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

SP Homework 7 using arrays Read 12 values (more if you feel like entering the da

ID: 3680888 • Letter: S

Question

SP Homework 7 using arrays

Read 12 values (more if you feel like entering the data) into an array.

Find the average of the values; print this out

Determine how many values in the list are greater than the average value. Print this out.

Pseudocode solution:

start

max = 12 (or whatever you wish)

for k = 0, max

   read vals[k];

end for loop

sum = 0

for k=0, max

sum = sum + vals[k]

end for loop

average = sum/max

count = 0

for k=0, max

   if (vals[k]>average)

count = count + 1

   endif

end for loop

print "the average value is", value, " and there are ",count," values greater than the average."

end

values can represent whatever you wish. Remember you are supposed to imagine something, related to civil engineering, that could be stored in an array.

Explanation / Answer

#include <iostream>
#define max 12
using namespace std;

int main()
{
int a[max],i,k,j,count,sum;
int average=0;
cout << "Enter " << max << "array elements" << endl;
for(i=0;i<max;i++)
{
cin >> a[i];
}
sum=0;
for(k=0;k<max;k++)
{
sum=sum+a[k];
}
average=sum/max;
count=0;
for(j=0;j<max;j++)
{
if(a[j]>average)
count++;
}
cout << "the average value is = " << average << " and there are " <<count <<" values are grater than the average." <<endl;
return 0;
}