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

write a program to - read a file of integers -numbers must be stored in an array

ID: 3619927 • Letter: W

Question

write a program to
- read a file of integers
-numbers must be stored in an array
-creat functions:
* Compute and display the average of all numbers
* Compute and display the number of integers in the file that are higher than the average and this must be a value-returning function (returns a number of ints higher than average)

-Here is a sample of the function calls in main:
* getNumbers(numbers);
* getAverage(numbers, avg);
* cout << "there are " <<aboveAvg(numbers,avg) << "numbers higher than the average, which is " <<avg<<endl;

Explanation / Answer

please rate - thanks message me if any problem #include <iostream>
#include <fstream>
using namespace std;
int aboveAvg(int[],double);
void getNumbers(int[]);
void getAverage(int[],double& );
   int main()
   {int numbers[50];
   double avg;

    getNumbers(numbers);
    getAverage(numbers, avg);
    cout << "there are " <<aboveAvg(numbers,avg) << "numbers higher than the average, which is " <<avg<<endl;
    
    
         system("pause");
         return 0;
     }
int aboveAvg(int a[],double avg)
{int i=0,count=0;
while(a[i]!=-99999)
     {if(a[i]>avg)
         count++;
      i++;
      }
return count;
}
void getNumbers(int a[])
{int i=0;
ifstream input;
   input.open("input.txt");           //open file
   if(input.fail())             //is it ok?
       { cout<<"file did not open please check it ";
        system("pause");
        system("exit");
        }
   input>>a[i];
   while(input)
       {i++;
       input>>a[i];
       }
   a[i]=-99999;
    input.close();
   return;
}
void getAverage(int a[],double& avg )
{int tot=0,i=0;
while(a[i]!=-99999)
    {tot+=a[i];
    i++;
    }
avg=(double) tot/i;
}