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
|
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int ReadInputRecord(int&, int&, int&, int&, int&, int&, string&, ifstream&);
int Math(int&, int&, bool&);
void WriteOutputRecord(int, int, int, string team, ofstream &output);
int main()
{
int num1, num2, num3, num4, num5, num6, score_total, success_amount;
bool passcount = true;
int column = 0;
ifstream rawdata;
string team;
rawdata.open("RawScore.dat");
if (rawdata)
{
ofstream output("output.dat");
while (ReadInputRecord(num1, num2, num3, num4, num5, num6, team, rawdata) == 1)
{
//successful = Success(num1, num2, num3, num4, num5, num6);
num1 = Math(num1, num4, passcount);
num4 = Math(num1, num4, passcount);
num2 = Math(num2, num5, passcount);
num5 = Math(num2, num5, passcount);
num3 = Math(num3, num6, passcount);
num6 = Math(num3, num6, passcount);
score_total = num1 + num2 + num3;
success_amount = num4 + num5 + num6;
column++;
WriteOutputRecord(column, score_total, success_amount, team, output);
}
rawdata.close();
output.close();
}
else
{
cout << "Can't open the input file.\n";
}
}
int ReadInputRecord(int &num1, int &num2, int &num3, int &num4, int &num5, int &num6, string &team, ifstream &rawdata)
{
if (rawdata >> num1)
{
rawdata >> num2;
rawdata >> num3;
rawdata >> num4;
rawdata >> num5;
rawdata >> num6;
rawdata >> team;
return(1);
}
return(0);
}
int Math(int &seconds, int &attempts, bool &firstpass)
{
static int TIME_PENALTY = 1200;
if (seconds > 0 && firstpass == true)
{
seconds = seconds + attempts * TIME_PENALTY - TIME_PENALTY;
firstpass = false;
return(seconds);
}
if (seconds > 0 && firstpass == false)
{
firstpass = true;
return(1);
}
return(seconds);
}
void WriteOutputRecord(int column, int score_total, int success_amount, string team, ofstream &output)
{
output << setw(3) << column << ": " << left << setw(40) << team << right << setw(2) << success_amount << setw(7) << score_total << endl;
}
|