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 89 90 91 92 93
|
#include <iostream>
#include <fstream>
using namespace std;
string contestantName(ifstream&);
int getJudgeData();
void calcScore(ofstream&, string ,int ,int, int, int, int);
double findLowest(int, int, int, int, int);
double findHighest(int, int, int, int, int);
int main(int argc, const char * argv[])
{
ifstream inFile;
inFile.open("starsearch.docx");
ofstream outFile;
outFile.open("results.docx");
int number;
inFile >> number;
for (int count = 1; count <= number; count ++)
{
string name = contestantName(inFile);
int score1 = getJudgeData();
int score2 = getJudgeData();
int score3 = getJudgeData();
int score4 = getJudgeData();
int score5 = getJudgeData();
calcScore(outFile, name, score1, score2, score3, score4, score5);
}
inFile.close();
outFile.close();
return 0;
}
string contestantName(ifstream& inFile)
{
string name;
inFile >> name;
return name;
}
int getJudgeData(int &score, ifstream& inFile)
{
inFile >> score;
return score;
}
void calcScore(ofstream& outFile,string name, int score1,int score2,int score3,int score4,int score5)
{
double lowScore = findLowest(score1, score2, score3, score4, score5);
double highScore = findHighest(score1, score2, score3, score4, score5);
double average = (score1 + score2 + score3+ score4 + score5 - lowScore - highScore)/3;
outFile << name << "\t" << average << endl;
}
double findLowest(int score1, int score2, int score3,int score4, int score5)
{
int lowScore = score1;
if (score2 < lowScore)
lowScore = score2;
if (score3 < lowScore)
lowScore = score3;
if (score4 < lowScore)
lowScore = score4;
if (score5 < lowScore)
lowScore = score5;
return lowScore;
}
double findHighest(int score1, int score2, int score3, int score4, int score5)
{
int highScore = score1;
if (score2 > highScore)
highScore = score2;
if (score3 > highScore)
highScore = score3;
if (score4 > highScore)
highScore = score4;
if (score5 > highScore)
highScore = score5;
return highScore;
}
|