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 155 156 157 158 159 160 161 162 163 164
|
#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, AvgAttendanceA = 0.0, AvgAttendanceB = 0.0, AvgAttendanceC = 0.0, AvgAttendanceD = 0.0, AvgAttendanceF = 0.0;
double TotalCountA = 0, TotalCountB = 0, TotalCountC = 0, TotalCountD = 0, TotalCountF = 0.0;
int ID = 0;
int NumA = 0;
int NumB = 0;
int NumC = 0;
int NumD = 0;
int NumF = 0;
int CountAm = 0, CountBm = 0, CountCm = 0, CountA = 0, CountB = 0, CountC = 0, CountD = 0, CountF = 0, CountAp = 0, CountBp = 0, CountCp = 0;
int TotalAm = 0, TotalBm = 0, TotalCm = 0, TotalA = 0, TotalB = 0, TotalC = 0, TotalD = 0, TotalF = 0, TotalAp = 0, TotalBp = 0, TotalCp = 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;
cout << "Letter" << '\t' << "Count" << '\t' << "AvgAttendance" << 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);
if (LetterGrade >= 97 && LetterGrade <= 100)
{
Grade = " A+ ";
NumA++;
CountAp++;
TotalAp++;
}
else if (LetterGrade >= 93 && LetterGrade < 97)
{
Grade = " A ";
NumA++;
CountA++;
TotalA++;
}
else if (LetterGrade >= 90 && LetterGrade < 93)
{
Grade = " A- ";
NumA++;
CountAm++;
TotalAm++;
}
else if (LetterGrade >= 87 && LetterGrade < 90)
{
Grade = " B+ ";
NumB++;
CountBp++;
TotalBp++;
}
else if (LetterGrade >= 83 && LetterGrade < 87)
{
Grade = " B ";
NumB++;
CountB++;
TotalB++;
}
else if (LetterGrade >= 80 && LetterGrade < 83)
{
Grade = " B- ";
NumB++;
CountBm++;
TotalBm++;
}
else if (LetterGrade >= 77 && LetterGrade < 80)
{
Grade = " C+ ";
NumC++;
CountCp++;
TotalCp++;
}
else if (LetterGrade >= 73 && LetterGrade < 77)
{
Grade = " C ";
NumC++;
CountC++;
TotalC++;
}
else if (LetterGrade >= 70 && LetterGrade < 73)
{
Grade = " C- ";
NumC++;
CountCm++;
TotalCm++;
}
else if (LetterGrade >= 60 && LetterGrade < 70)
{
Grade = " D ";
NumD++;
CountD++;
TotalD++;
}
else if (LetterGrade >= 0 && LetterGrade < 60)
{
Grade = " F ";
NumF++;
CountF++;
TotalF++;
}
cout << "Letter Count Avg " <<
"Letter Count Attendance" << endl;
cout << " A" << '\t' << CountAp + CountA + CountAm << '\t' << ( TotalAp + TotalA + TotalAm )/ (CountAp + CountA + CountAm) << endl;
cout << " B" << '\t' << CountBp + CountB + CountBm << '\t' << (TotalBp + TotalB + TotalBm) / (CountBp + CountB + CountBm) << endl;
cout << " C" << '\t' << CountCp + CountC + CountCm << '\t' << (TotalCp + TotalC + TotalCm) / (CountCp + CountC + CountCm) << endl;
cout << " D" << '\t' << CountD << '\t' << TotalD / CountD << endl;
cout << " F" << '\t' << CountF << '\t' << TotalF / CountF<< endl;
outputGrades << ID << '\t' << setprecision(2) << fixed << LetterGrade << '\t' << '\t' << Grade << 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;
}
|