1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
//function prototpes.
void ProcessOverall(string, int, int, int, int& min, int& max, float& avg);
int main ()
{
//variable
string name;
int test1, test2, test3;
float avg;
int min, max;
double overall;
//read file from data.txt
ifstream inputFile;
inputFile.open("data.txt");
cout << fixed << setprecision(2);
cout << "Name \tScore 1 \tScore 2 \tScore 3 \tLow \tHigh \tAverage" << endl;
cout << "--------------------------------------------------------------------------------------------------------" << endl;
while (inputFile >> name >> test1 >> test2 >> test3)
{
ProcessOverall(name, test1, test2, test3, min, max, avg);
}
cout << "__________________________________________________________________________________________________________" << endl;
cout << "Overall average of the class is: " << overall << endl;
//close
inputFile.close();
return 0;
}
void ProcessOverall(string name, int test1, int test2, int test3, int& min,int& max, float& avg)
{
double overall;
min = test1;
max = test1;
if (test2 > max)
max = test2;
if (test2 < min)
min = test2;
if (test3 > max)
max = test3;
if (test3 < min)
min = test3;
avg = ((test1 + test2 + test3) / 3.0);
overall = (avg / 6.0);
avg = ((test1 + test2 + test3) / 3.0);
overall = (avg / 6.0); //are there a way that i dont need to put 6.0 here?
cout << name
<< setw(15) << test1
<< setw(16) << test2
<< setw(16) << test3
<< setw(16) << min
<< setw(16) << max
<< setw(19) << avg << endl;
//calculating overall average.
}
|