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.
so far this is what i have for the question. but the averages dont seem to work when using a txt file
#include
const int N = 100 ;
//declare and initialize objects string filename ; int count=0, numberOfValues ; double y , 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." < } int k; for (k=0; k lab >> y; sum += y; } //compute average and count values that are greater //than the average. yAve = sum/numberOfValues; lab.seekg(0, ios::beg); lab >>numberOfValues ; for (k=0; k
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started