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
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
double calAverage(double &first,double &second,double &third);
int findHighest(double first, double second, double third);
int findLowest(double first, double second, double third);
int main() {
ifstream infile;
string fileName;
double totalAverage = 0;
cout << "Enter the file name: " << endl;
cin >> fileName;
infile.open(fileName.c_str());
if(infile){
string name;
double score1 = 0;
double score2 = 0;
double score3 = 0;
while (infile >> name >> score1 >> score2 >> score3){
calAverage(score3, score2, score3);
findHighest(score1,score2,score3);
findLowest(score1,score2,score3);
}
}
else
cout << "Error cannot open file";
infile.close();
return 0;
}
// Calculates the average of the numbers in the parameters
double calAverage(double &first,double &second,double &third)
{
return (first + second + third) / 3.0;
}
// This function determines and returns the highest of the three scores passed as parameters
int findHighest(double first, double second, double third){
if(first >= second && first >= third)
return first;
else if(second >= third && second >= first)
return second;
else
return third;
}
// This function determines and returns the lowest of the three scores passed as parameters
int findLowest(double first, double second, double third){
if(first <= second && first <= third)
return first;
else if(second <= third && second <= first)
return second;
else
return third;
}
|