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 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
#include <iostream> // listing all header files
#include <fstream>
#include <string>
#include <ctime>
#include <cmath>
using namespace std;
int flipcoin();
void OpenFile(ifstream& infile);
void getjudgescore(ifstream& infile, int& judgescore);
void getphonescore(ifstream& infile, int& phonescore);
void findwinner(int judgescore1, int totalphone1, int judgescore2, int totalphone2);
int main()
{
string textfile; // textfile name is stored here
ifstream infile;
int judgescore = 0, // judge and phone scores labeled here
totalphone = 0,
judgescore1 = 0,
totalphone1 = 0,
judgescore2 = 0,
totalphone2 = 0,
contestant = 0;
double temp; // used for average judgescore
int winner;
int contestent = 1;
unsigned int seed;
seed = static_cast<unsigned>(time(NULL));
srand(seed);
winner = flipcoin();
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
cout << "Welcome to Tallahassee Idol! Where Stars are Born!!!" << endl;
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
cout << endl;
cout << "Enter the name of the file (no blanks!) -> ";
cin >> textfile;
cout << endl;
infile.open(textfile.c_str());
while (!infile)
{
cout << endl;
cout << "The file name you gave is invalid. Please try again." << endl;
cout << "Enter the name of the file(no blanks!) -> ";
cin >> textfile;
cout << endl;
infile.open(textfile.c_str());
}
cout << "Processing Judge Data for Contestant 1" << endl;
cout << "== == == == == == == == == == == == == == == == == == =" << endl;
cout << "Judge Scores are: ";
getjudgescore(infile, judgescore1);
cout << endl;
cout << "Average Judge Scores are: " << judgescore1;
cout << endl;
cout << endl;
cout << "Processing Phone Data for Contestant 1" << endl;
cout << "== == == == == == == == == == == == == == == == == == =" << endl;
getphonescore(infile, totalphone1);
cout << "Total of Phone Calls for all Regions: " << totalphone1 << endl << endl;
cout << endl;
cout << "Processing Judge Data for Contestant 2" << endl;
cout << "== == == == == == == == == == == == == == == == == == =" << endl;
cout << "Judge Scores are: ";
getjudgescore(infile, judgescore2);
cout << endl;
cout << "Average Judge Scores are: " << judgescore2 << endl;
cout << endl;
cout << "Processing Phone Data for Contestant 2" << endl;
cout << "== == == == == == == == == == == == == == == == == == =" << endl;
getphonescore(infile, totalphone2);
cout << "Total of Phone Calls for all Regions: " << totalphone2 << endl << endl;
cout << "Final Results Summary" << endl;
cout << "--------------------" << endl;
cout << "Judges winner is: ";
findwinner (judgescore1, judgescore2, totalphone1, totalphone2);
cout << endl;
cout << "Phone Call Winner is: ";
findwinner(judgescore1, judgescore2, totalphone1, totalphone2);
cout << endl;
cout << endl;
cout << endl << endl << endl << endl << endl << endl;
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
cout << "Thanks for visiting our show!!!" << endl;
cout << "Execution Terminated Normally." << endl;
cout << "*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-" << endl;
cout << endl;
return 0;
}
void getjudgescore(ifstream& infile, int& judgescore)
{
int value,
min,
max;
double average;
infile >> value;
cout << value << " ";
judgescore += value;
min = value;
max = value;
for (int i = 0; i < 4; i++)
{
infile >> value;
cout << value << " ";
judgescore += value;
if (value > max)
max = value;
if (value < min)
min = value;
}
judgescore = judgescore - min - max;
average = (double)judgescore / 3.0;
judgescore = ceil(average);
}
void getphonescore(ifstream& infile, int& phonescore)
{
int value,
i;
for (int i = 0; i < 4; i++)
{
infile >> value;
cout << "Phone Call for Region " << i + 1 << ": " << value << endl;
phonescore += value;
}
}
void findwinner(int judgescore1, int totalphone1, int judgescore2, int totalphone2)
{
int contestant1 = 0,
contestant2 = 0;
if (judgescore1 > judgescore2)
{
cout << "Contestant 1" << endl;
contestant1++;
return;
}
else if (judgescore1 < judgescore2)
{
cout << "Contestant 2" << endl;
contestant2++;
return;
}
if (totalphone1 > totalphone2)
{
cout << "Contestant 1" << endl;
contestant1++;
return;
}
else if (totalphone1 < totalphone2)
{
cout << "Contestant2" << endl;
contestant2++;
return;
}
if (contestant1 = contestant2)
{
cout << "Contestants are tied!!!" << endl;
cout << "We will now flip a coin to see who wins." << endl;
int winner = flipcoin(); // this function is called if the contestants tie
if (winner == 1) // if the coin rolls a 1, contestant 1 wins
cout << "Contestant 1 is the winner!" << endl << endl;
if (winner == 2) // if the coin rolls a 2, contestant 2 wins
cout << "Contestant 2 is the winner!" << endl << endl;
}
else if (contestant1>contestant2) //compare the Advantage Points
cout << "Contestant 1 is the winner!";
else if (contestant2 >contestant1)
cout << "Contestant 2 is the winner!";
return;
}
int flipcoin()
{
const int max = 2;
double x = 1 + 1.0;
int y;
y = static_cast<int> (1 + rand() * max);
return y;
}
|