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 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
|
//
// Created by Ren Cummings on 11/11/15.
/*Write a C++ program to determine the winner of the “Sinclair’s Got Talent” contest.
The contest has five judges, each of whom awards a score between 1 and 10 for each of the performers. Fractional scores are not allowed. A contestant’s final score is determined by dropping the highest and lowest scores received, then averaging the three remaining scores (the average should be rounded to two decimal places). The winner is the contestant with the highest average score. If there is a tie, the winner will be the first contestant judged.*/
//
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
void Jdata(double & Sval);
double lowestScore(double a, double b, double c, double d, double e, double low);
double highestScore(double a, double b, double c, double d, double e, double high);
double calcAVG(double low, double high, double a, double b, double c, double d, double e, double avgval);
int main(int argc, const char * argv[]) {
string name;
double score, j1, j2, j3, j4, j5, low = 0, high = 0, contestant = 0,contestant2 = 0;
double AVG = 0.0,AVG2 = 0.0, avgval, max=0.0;
string select= "go";
ifstream in;
ofstream out;
ofstream avgout;
ifstream avgin;
out.open("info.txt");//open file
while(select != "Done" && select !="done"){
cout<<"Please enter Contestant's first name.\n";
cin>> name;
out<<name <<" ";
//get judge data
Jdata(score);
j1 = score;
Jdata(score);
j2 = score;
Jdata(score);
j3 = score;
Jdata(score);
j4 = score;
Jdata(score);
j5 = score;
//finding hi and low
low = lowestScore(j1, j2, j3, j4, j5, low);
high = highestScore(j1, j2, j3, j4, j5, high);
//presentation standards
cout<< fixed <<showpoint <<setprecision(2);
// average calculations
AVG = calcAVG(low, high, j1,j2,j3,j4,j5, avgval);
out<<AVG;
cout<<name<<": "<<AVG;
out<< "\n";
cout<<"\n";
contestant++;
cout<<"\n";
//reset loop
cout<<"Press any key to continue... \n(Input 'Done' when there are no more contestants.) \n";
cin>> select;
}
out.close();//close
//end reading to file
//begin reading from file
in.open("info.txt");//open in
// Display contestants
while(contestant > contestant2) {
in>>name;
cout<<"Contestant: "<<name<<"\n";
in>>AVG2;
cout<<"Average: "<<AVG2<<"\n";
max = AVG2;
if (AVG2 > max) {
max = AVG2;
}
contestant2++;
}
//Display winning Average to correlate to contestant above...
cout<<"Winner has an average of: "<< max <<"\n";
cout<<"\n";
cout<<"In the case of a tie, the winner will be the first Contest Judged\n \n";
return 0;
}
void Jdata(double & Sval){
cout<< "Enter Judge's score: \n";
cin>> Sval;
if (Sval < 1 ) {
cout<<"Invalid input, pleas re-enter score between 1 - 10: \n";
cin>> Sval;
}
else if (Sval > 10){
cout<<"Invalid input, pleas re-enter score between 1 - 10: \n";
cin>> Sval;
}
};
double lowestScore(double a, double b, double c, double d, double e, double low){
low = a;
if (b < low)
low = b;
if (c < low)
low = c;
if (d < low)
low = d;
if (e < low)
low = e;
return low;
};
double highestScore(double a, double b, double c, double d, double e, double high){
high = a;
if (b > high)
high = b;
if (c > high)
high = c;
if (d > high)
high = d;
if (e > high)
high = e;
return high;
};
double calcAVG(double low, double high, double a, double b, double c, double d, double e, double avgval){
low = lowestScore(a, b, c, d, e, low);
high = highestScore(a, b, c, d, e, high);
avgval = ((a + b + c + d + e)-(high + low))/3;
return avgval;
};
|