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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <string>
using namespace std;
string contestantName( ifstream & );
double getJudgeData( ifstream & );
double findLowest(double &lowestScore);
double findHighest(double &highestScore);
void CalcScore(string&,double&, double&, double&, double&, double&, double&);
string contName;
double score1, score2, score3, score4, score5, lowestScore, highestScore, totalScore;
int main(){
ifstream inputFile;
inputFile.open("starsearch.dat");
for (int count = 0; count < 2; count++){
string contestantName(contName);
getJudgeData(inputFile);
CalcScore(contName,score1,score2,score3,score4,score5,totalScore);
ofstream outputFile;
outputFile.open ("results.dat");
outputFile << contName << totalScore;
}
system("pause");
return 0;
}
string contestantName (string contName){
ifstream inputFile;
const int size = 81;
char name[size];
inputFile.open("starsearch.dat");
contName = name;
inputFile >> contName;
return contName;
}
void getJudgeData(double &score1, double &score2, double &score3, double &score4, double &score5){
ifstream inputFile;
inputFile.open("starsearch.txt");
if(!inputFile)
{
cout<<"Error!File not found.";
exit(1);
}
inputFile>>score1>>score2>>score3>>score4>>score5;
}
double findLowest(double &lowestScore){
if ((score1 <= score2) && (score1 <= score3) && (score1 <= score4) && (score1 <= score5))
{
lowestScore = score1;
}
else if ((score2 <= score1) && (score2 <= score3) && (score2 <= score4) && (score2 <= score5))
{
lowestScore = score2;
}
else if ((score3 <= score1) && (score3 <= score2) && (score3 <= score4) && (score3 <= score5))
{
lowestScore = score3;
}
else if ((score4 <= score1) && (score4 <= score2) && (score4 <= score3) && (score4 <= score5))
{
lowestScore = score4;
}
else if ((score5 <= score1) && (score5 <= score2) && (score5 <= score3) && (score5 <= score4))
{
lowestScore = score5;
}
return lowestScore;
}
double findHighest(double &highestScore){
if ((score1 >= score2) && (score1 >= score3) && (score1 >= score4) && (score1 >= score5))
{
highestScore = score1;
}
else if ((score2 >= score1) && (score2 >= score3) && (score2 >= score4) && (score2 >= score5))
{
highestScore = score2;
}
else if ((score3 >= score1) && (score3 >= score2) && (score3 >= score4) && (score3 >= score5))
{
highestScore = score3;
}
else if ((score4 >= score1) && (score4 >= score2) && (score4 >= score3) && (score4 >= score5))
{
highestScore = score4;
}
else if ((score5 >= score1) && (score5 >= score2) && (score5 >= score3) && (score5 >= score4))
{
highestScore = score5;
}
return highestScore;
}
double CalcScore (double &totalScore){
double findLowest(double lowestScore);
double findHighest(double highestScore);
totalScore = (((score1+score2+score3+score4+score5)-(lowestScore+highestScore))/3);
return totalScore;
}
|