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
|
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
float calculateExams (float[]);
float calculateFinal (float);
float calculateProjects (float[]);
float calculateQuizzes (float[]);
void letterGrade (float[], int&, int&, int&, int&, int&, char&);
int main ()
{
ifstream inFile;
ofstream outFile;
inFile.open ("myInput.txt");
outFile.open ("result.txt");
int A = 0, B = 0, C = 0, D = 0, F = 0, x = 0, t;
char letter;
string first, last;
float exams[3], final, projects[8], quizzes[5], average[5];
while (x < 10)
{
t = 0;
inFile >> first >> last;
for(int m = 0; m < 3; m++)
{
inFile >> exams[m];
if (exams[m] < 0)
{
t++;
}
}
inFile >> final;
if (final < 0)
{
t++;
}
for(int m = 0; m < 8; m++)
{
inFile >> projects[m];
if (projects[m] < 0)
{
t++;
}
}
for (int m = 0; m < 5; m++)
{
inFile >> quizzes[m];
if (quizzes[m] < 0)
{
t++;
}
}
if (t > 0)
{
outFile << "Incorrect data for " << first << ' ' << last << endl << endl;
x++;
continue;
}
average[0] = calculateExams(exams);
average[1] = calculateFinal (final);
average[2] = calculateProjects (projects);
average[3] = calculateQuizzes (quizzes);
letterGrade (average, A, B, C, D, F, letter);
outFile << fixed << showpoint << setprecision(2)
<< first << ' ' << last << " has a(n) " << letter << " with a "
<< average[4] << "% for this course. His/Her grades are: " << endl
<< "Percentage of exams: " << average[0] << "%" << endl
<< "Percentage of final: " << average[1] << "%" << endl
<< "Percentage of projects: " << average[2] << "%" << endl
<< "Percentage of quizzes: " << average[3] << "%" << endl << endl;
x++;
}
outFile << "Total A's: " << A << endl
<< "Total B's: " << B << endl
<< "Total C's: " << C << endl
<< "Total D's: " << D << endl
<< "Total F's: " << F << endl;
return 0;
}
float calculateExams (float ex[])
{
float sum = 0;
for (int k = 0; k < 3; k++)
sum += ex[k];
return (sum/300) * 30;
}
float calculateFinal (float fin)
{
return (fin/100)* 30;
}
float calculateProjects (float proj[])
{
float sum = 0;
for (int k = 0; k < 8; k++)
sum += proj[k];
return (sum/400) * 30;
}
float calculateQuizzes (float q[])
{
float sum = 0;
for (int k = 0; k < 5; k++)
sum += q[k];
return (sum/100) * 10;
}
void letterGrade (float scr[], int& A, int& B, int& C, int& D, int& F, char& l)
{
scr[4] = scr[0] + scr[1] + scr[2] + scr[3];
int factor = int(scr[4]/10);
switch (factor)
{
case 10: case 9: {l = 'A';
A++;
}
break;
case 8: {l = 'B';
B++;
}
break;
case 7: {l = 'C';
C++;
}
break;
case 6: {l = 'D';
D++;
}
break;
default: {l = 'F';
F++;
}
}
}
|