Question

For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the mon...

For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the monitor: the average score and the total number of scores. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file 2 of 2 //postcondition: inFile is opened. If inFile cannot be opened, a message is // written to cout and the program exits void openFile(string filename, ifstream& inFile); //precondition: a score array, size is a’s length //postcondition:avg contains score score average float calculateAverage(float a, int size) Remember to perform all required operations on the files, otherwise you receive a significant deduction. Failure to conform to the specification will result in significant deductions (up to 50 points). Finally, every function must be commented with preconditions and post conditions. Failure to include these things will result in a 20 point deduction. Each line of the data file will contain a score. You can assume that each non-empty line in the file contains a score and nothing else. You can assume that there will be no more than 25 scores in the file, but there may be any number from two to 25.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//program following that exam scores file name data.txt

//the code follows as

#include<iostream>
#include<fstream>
#include<cstdlib>
using namespace std;
float calculateAverage(float a, int size)
{
return a/size;
}
void openFile(string filename, ifstream& inFile)
{
inFile.open(filename);
if(!inFile)
{
cout<<"Unable to open the file exiting the prgram."<<endl;
exit(0);
}
float scores[25],sum=0;
int count=0;
while(inFile>>scores[count])
{
sum+=scores[count];
count++;
}
cout<<"Sum of all the score grade is :"<<sum<<endl;
cout<<"Avrage of the score is : "<<calculateAverage(sum,count)<<endl<<endl;
}


int main()
{
ifstream inFile;
openFile("grades.txt",inFile);
return 1;
}

----------------------------------------------------------------

Output

Sum of all the score grade is :1307.5 Avrage of the score is : 81.7188 Press any key to continue .. . - 01:37 26-04-2019 3 O----------------------------------------------------------------------------------------------

grades.txt

grades-Notepad File Edit Format View Help 7 8 1 8 9 9 8 8 8 6 6 6 99 8 7 8 85.5 Lni, Col 1 O Type here to search rP ^后偏恒di) E------------------------------------------------------------------------------------------------

%%%%%%%%%%%% Please Give Rating %%%%%%%%%%%%%%%%%%%

Add a comment
Know the answer?
Add Answer to:
For this assignment, you are to write a program that does the following: • read exam scores from a file name data.txt into an array, and • after reading all the scores, output the following to the mon...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT