Question: rewrite this program without using an array. Calculate the average,then close and reopen the input file and count the number of values greater than the

rewrite this program without using an array. Calculate the average,then close and reopen the input file and count the number of values greater than the averages. did you need to clear the eofbit before reading the file for a second time?

/*--------------------------------*/ /* Program Chapter 7_3* /

/* this program reads at most 100 values from the data */ /* file and determines the number of values greater han the average*/

#include #include #include

using namespace std ;

int main() { //define max array size constant const int N = 100 ; //declare and initialize objects string filename ; int count=0, numberOfValues ; double y[N] , yAve , sum=0 ; ifstream lab; //prompt user for name of input file cout<< "Enter name of the input file" ;\ cin>> filename ; //open data file and read data into an array //compute a sume of the values. lab.open(filename.c_str()) ; if (lab.fail()) { cerr << "error opening input file " ; return (1); } /*file has been opened. */ /* read number of data values. */ lab >>numberOfValues ; //dont exceed the bound of the array. if(numberOfValues > N) { cerr << "Number of data values." <> y[k]; sum += y[k]; } //compute average and count values that are greater //than the average. yAve = sum/numberOfValues; for (int k=0; k yAve) count++; } //print count. cout << count << "values greater than the average "; //close file and exit program. lab.close(); return 0; }

/*----------------------------------------------------------------------*/

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!