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
|
#include <fstream>
#include <iomanip>
using namespace std;
char calcFunction(double totalNumGrade, char grade, double midWeight, double midterm, double finalWeight,
double final, double researchWeight, double research, double groupWeight, double group,
double participationWeight, double participation);
int main()
{
ifstream inFile;
ofstream outFile;
int studentID;
double midterm, final, research, group, participation;
char grade;
double midWeight = 0.25, finalWeight = 0.25, researchWeight = 0.2;
double groupWeight = 0.2, participationWeight = 0.1;
double totalNumGrade = 0;
inFile.open("studentRec.txt");
outFile.open("studentLetterGrade.txt");
inFile >> studentID >> midterm >> final >> research >> group >> participation;
outFile << fixed << setprecision(2);
while(inFile)
{
if((totalNumGrade > -1) && (totalNumGrade < 101))
{
totalNumGrade = (midWeight * midterm) + (finalWeight * final) + (researchWeight *
research) + (groupWeight * group) + (participationWeight * participation);
grade = calcFunction(totalNumGrade, grade, midWeight, midterm, finalWeight,
final, researchWeight, research, groupWeight, group,
participationWeight, participation);
}
else
{
outFile << "Invalid grade entries" << endl;
}
outFile << studentID << " " << totalNumGrade << " " << grade << endl;
inFile >> studentID >> midterm >> final >> research >> group >> participation;
}
return 0;
}
char calcFunction(double totalNumGrade, char grade, double midWeight, double
midterm, double finalWeight, double final, double researchWeight, double research,
double groupWeight, double group,
double participationWeight, double participation)
{
totalNumGrade = (midWeight * midterm) + (finalWeight * final) + (researchWeight *
research) + (groupWeight * group) + (participationWeight * participation);
if (totalNumGrade >= 90)
{grade = 'A';}
else if (totalNumGrade >= 80)
{grade = 'B';}
else if (totalNumGrade >= 70)
{grade = 'C';}
else if (totalNumGrade >= 60)
{grade = 'D';}
else
{grade = 'F';}
return grade;
};
|