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
  • For this assignment, you are to write a program that does the following: (C++) • read exam scores...

    For this assignment, you are to write a program that does the following: (C++) • 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...

  • For this assignment, you are to write a program that does the following:  read temperatures...

    For this assignment, you are to write a program that does the following:  read temperatures from a file name data.txt into an array, and  after reading all the temperatures, output the following to the monitor: the average temperature, the minimum temperature, and the total number of temperatures read. In addition, the program must use the following functions: //precondition: fileName is name of the file to open, inFile is the input file //postcondition: inFile is opened. If inFile cannot...

  • // This program will read in a group of test scores (positive integers from 1 to...

    // This program will read in a group of test scores (positive integers from 1 to 100) // from the keyboard and then calculate and output the average score // as well as the highest and lowest score. There will be a maximum of 100 scores. // #include <iostream> using namespace std; float findAverage (const int[], int); // finds average of all grades int findHighest (const int[], int); // finds highest of all grades int findLowest (const int[], int); //...

  • C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the r...

    C++ Write a function parseScores which takes a single input argument, a file name, as a string. Your function should read each line from the given filename, parse and process the data, and print the required information. Your function should return the number of student entries read from the file. Empty lines do not count as entries, and should be ignored. If the input file cannot be opened, return -1 and do not print anything.     Your function should be named...

  • Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that...

    Program 7 File Processing and Arrays (100 points) Overview: For this assignment, write a program that will process monthly sales data for a small company. The data will be used to calculate total sales for each month in a year. The monthly sales totals will be needed for later processing, so it will be stored in an array. Basic Logic for main() Note: all of the functions mentioned in this logic are described below. Declare an array of 12 float/doubles...

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