#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include<string>
#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
ifstream infile;
ofstream outfile;
int num;//number of grades
int Hi;//highest test grade
int Low;//lowest test grade
sting stat;//status of grade, whether higher or lower than avverage
infile.open ("grades.txt");
outfile.open ("gradeOutput");
double number;//the grades as in the infile
while (getline(infile,number,'\n'))
{
cout<<"The number of test scores : "<<num<<endl;
double average = (number/num);//average of all the grades
cout<<"The average of the test scores : "<<average<<endl;
cout<<"The highest test score was "<<Hi<<" and the lowest test grade was "<<Low<<endl;
cout<<"Grade "<<setw(5)<<"Status"<<endl;
if (number<average)
{
cout<<number<<setw(5)<<" Below"<<endl;
}
else if (number>average)
{
cout<<number<<setw(5)<<" Above"<<endl;
}
return 0;
}
The assignment is as follows:
Write a c++ program USING FUNCTIONS, that will read in an unknown number (not
more than 60) of test grades from a text file named "functest.txt"(make your own). The
program is to calculate and output the following:
1. Number of Test Grades
2. Average of the Test Grades ( 2 decimal places)
3. The Highest and Lowest Test Grades
4. A list of the grades and whether the grade is ABOVE or BELOW the
average.
The grade and status should take the following format:
Grade Status
XX ABOVE
XX BELOW
etc.
5. Output the results of all the calculations
You may assume that no grade will be exactly equal to the average.
A few things:
1. How can you determine the number of grades in the infile?
2. How can you create a function for just reading in the information from the infile?
3. To see which of the grade is higher and lower...i'm sure that a series of if/else statements could work, but it wouldn't be practical is you had several hundred records. How do you find out the highest and lowest grade from the infile?
4. With regards to the output, to get it formatted as is requested (above)...i'm familiar with using something like
if (i%2==0)
print<<endl;
info.....
But in this case how could I use that to manipulate the headers Grade & Status?
My infile is as follows:
69
57
94
67
46
Thank you.