Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #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 , 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> y; if(y>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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Databases On The Web Learn To Create Web Pages That Interface With Database Engines

Authors: Robert Papaj, Donald Burleson

11th Edition

1576100995, 978-1576100998

More Books

Students also viewed these Databases questions