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
|
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
//hw scores and the class participation score, maximum 50.
float compute_hw_participation(istream& infile)
{
float hw, part, hwp; float total=0;
cout << " Scores are: ";
for(int i=1; i <= 11; i++)
{
infile >> hw;
infile >> part;
hwp = hw + part;
cout << hwp << endl;
}
return total;
}
//score on the tests, maximum 50.
float compute_tests(float tests, istream& infile)
{
infile >> tests;
cout << " tests are " << tests << endl;
return 0.0;
}
float hwp, tests;
//homework and participation + tests, maximum 100.
float compute_totalscore(float totalscore)
{
totalscore = hwp + tests;
cout << " Total score is " << totalscore << endl;
return 0.0;
}
char GetGrade(float totalscore)
{
char grade;
if (totalscore >= 90)
{
grade = 'A';}
else
{
if (totalscore >= 80)
{
grade = 'B';}
else
{
if (totalscore >= 70)
{
grade = 'C';}
else
{
if (totalscore >= 60)
{
grade = 'D';}
else
{
if (totalscore < 60)
{
grade = 'F';}
}
}
}
}
return grade;
}
void printRecord (char name[20], char Id[8], float hwp, float tests, float totalscore, float grade, ostream& outfile)
{
outfile << "Name: "<< name << endl
<< "Id: "<< Id << endl
<< "Homework/Participation: " << hwp << endl
<< "Tests: " << tests << endl
<< "Total course score: " << totalscore << endl
<< "Letter Grade: " << grade << endl
<<"-------------------------------------------------"<<endl<< endl;
}
int main()
{
ofstream outfile;
ifstream infile;
char file_name[21], name[20], Id[20];
float hwp, tests, totalscore;
int deductions;
cout << "Please enter name of input file: ";
cin >> file_name;
infile.open(file_name);
if ( !infile)
{
// abandons operation with error mesg
cout << "Could not open input file \n";
return 0;
}
outfile.open("ScoreResult");
if ( !outfile)
{
cout << "Could not open output file \n";
return 0;
}
infile >> name;
while(!infile.eof())
{
infile >> Id;
cout << name << " " << Id << endl;
hwp = compute_hw_participation(infile);
tests = compute_tests(tests, infile);
totalscore = compute_totalscore(totalscore);
char grade = GetGrade(totalscore);
// grade
printRecord(name, Id, hwp, tests, totalscore, grade, outfile);
infile >> name;
}
return 0;
}
|