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.
//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
----------------------------------------------------------------------------------------------
grades.txt
------------------------------------------------------------------------------------------------
%%%%%%%%%%%% Please Give Rating %%%%%%%%%%%%%%%%%%%
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: (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 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...
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 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...