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
|
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
ifstream sampleGrades4("sampleGrades4.txt");
ofstream outputGrades("outputgrades.txt");
string firstRow;
int TotalStudents;
double Attendance;
double hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam;
double LetterGrade, AvgAttendance;
double TotalA, TotalB, TotalC, TotalD, TotalF;
int ID = 0;
int NumA = 0;
int NumB = 0;
int NumC = 0;
int NumD = 0;
int NumF = 0;
int CountA = 0, CountB = 0, CountC = 0, CountD = 0, CountF = 0;
string Grade = "";
if (sampleGrades4.is_open())
{
getline(sampleGrades4, firstRow);
sampleGrades4 >> TotalStudents;
cout << "Number of Students: " << TotalStudents << endl;
cout << firstRow << endl;
outputGrades << "ID" << setw(14) << "Course Letter" << setw(17) << "Letter Grade" << endl;
while ( !sampleGrades4.eof() )
{
sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
Grade = "Error: This is wrong !";
LetterGrade = 100*(Attendance*0.10/25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)/700*0.35 + exam1/25*0.15 + exam2/25*0.15 + finalExam/40*0.25);
AvgAttendance = Attendance/25*CountA;
cout << "Letter" << '\t' << "Count" << '\t' << "AvgAttendance" << endl;
if (LetterGrade >= 97 && LetterGrade <= 100)
{
Grade = " A+ ";
NumA++;
CountA++;
}
else if (LetterGrade >= 93 && LetterGrade < 97)
{
Grade = " A ";
NumA++;
CountA++;
}
else if (LetterGrade >= 90 && LetterGrade < 93)
{
Grade = " A- ";
NumA++;
CountA++;
}
else if (LetterGrade >= 87 && LetterGrade < 90)
{
Grade = " B+ ";
NumB++;
CountB++;
}
else if (LetterGrade >= 83 && LetterGrade < 87)
{
Grade = " B ";
NumB++;
CountB++;
}
else if (LetterGrade >= 80 && LetterGrade < 83)
{
Grade = " B- ";
NumB++;
CountB++;
}
else if (LetterGrade >= 77 && LetterGrade < 80)
{
Grade = " C+ ";
NumC++;
CountC++;
}
else if (LetterGrade >= 73 && LetterGrade < 77)
{
Grade = " C ";
NumC++;
CountC++;
}
else if (LetterGrade >= 70 && LetterGrade < 73)
{
Grade = " C- ";
NumC++;
CountC++;
}
else if (LetterGrade >= 60 && LetterGrade < 70)
{
Grade = " D ";
NumD++;
CountD++;
}
else if (LetterGrade >= 0 && LetterGrade < 60)
{
Grade = " F ";
NumF++;
CountF++;
}
outputGrades << ID << '\t' << setprecision(2) << fixed << LetterGrade << '\t' << '\t' << Grade << endl;
cout << Grade << '\t' << Count << '\t' << AvgAttendance << endl;
}
outputGrades << endl;
outputGrades << "The # of A's: " << NumA << endl;
outputGrades << "The # of B's: " << NumB << endl;
outputGrades << "The # of C's: " << NumC << endl;
outputGrades << "The # of D's: " << NumC << endl;
outputGrades << "The # of F's: " << NumF << endl;
sampleGrades4.close();
outputGrades.close();
}
else
cout << "Unable to open file";
return 0;
}
|