Question(7) (a) Write two functions in C++ called readData and findAverage The first function should take a reference to an ifstream object and a reference to an array of double, read data into the array from the file and return the number of values read. It should stop reading when the end of the file is reached. The data file contains prices of an unspecified item, one per line. The second function takes a reference to an array of double, and an int indicating the number of elements in the array and then calculates and returns the average of the values in the array
Explanation / Answer
#include #include #include #include using namespace std; const int MAX = 50; // a function called GetData to read and store data into two arrays, void GetData(ifstream& infile,string name[],int scores[][5],int& n) { n = 0; int i=0; int j=0; while(!infile.eof()) { infile >> name[i]; for(int j=0; j> scores[i][j]; i++; } n = i; } char determineGrade(double avg) { if(avg>=90 && avg=80 && avg=70 && avg=60 && avg=50 && avg