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
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." <
/*----------------------------------------------------------------------*/
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
