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
|
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include "GradeAnalysis.h"
using namespace std;
int GetInput(ifstream&, string&, string&, int&, int&, int&, int&, int&, int&);
int AnalyzeGrade(ifstream&, string&, string&, int&, int&, int&, int&, int&,
int&, int&);
void WriteOutput(ifstream&, ofstream&, string&, string&, int&, int&);
/*
*
*/
int main()
{
ifstream infile;
ofstream outfile;
infile.open("./ProgGrades2.txt");
outfile.open("./GradeReporttest.txt");
string lastName, firstName;
int score1, score2, score3, score4, score5;
int max, location;
while(GetInput(infile, lastName, firstName, score1, score2, score3, score4,
score5, max))
{
if (score1 == -99)
break;
cout << lastName << " " << firstName << " " << score1 << endl;
AnalyzeGrade(infile, lastName, firstName, score1, score2, score3,
score4, score5, max, location);
WriteOutput(infile, outfile, lastName, firstName, max, location);
}
infile.close();
outfile.close();
return 0;
}
int GetInput(ifstream& infile, string& lastName, string& firstName, int& score1,
int& score2, int& score3, int& score4, int& score5, int& max)
{
char firstChar;
string last1, last2, firstChar1;
infile >> firstChar;
if (isupper(firstChar))
{
infile >> last1 >> firstName;
firstChar1 = firstChar;
lastName = firstChar1 + last1;
}
else if (islower(firstChar))
{
infile >> last1 >> last2 >> firstName;
firstChar1 = firstChar;
lastName = firstChar1 + last1 + " " + last2;
}
infile >> score1 >> score2 >> score3 >> score4 >> score5;
return ;//What should I return?
}
int AnalyzeGrade(ifstream& infile, string& lastName, string& firstName,
int& score1, int& score2, int& score3, int& score4, int& score5,
int& max, int& location)
{
int score[5];
max = 0;
score[0] = score1;
score[1] = score2;
score[2] = score3;
score[3] = score4;
score[4] = score5;
for (int i = 0; i < 5; i++)
{
if (score[i] > max)
{
max = score[i];
location = i+1;
i=i-1;
}
}
fill_n(score, 6, 0);
return ;//What should I return?
}
void WriteOutput(ifstream& infile, ofstream& outfile, string& lastName,
string& firstName, int& max, int& location)
{
string studentID = lastName + " " + firstName;
outfile << "\n" << setw(19) << studentID << setw(14) << location << " " <<
max;
}
|