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
|
#include<fstream>
#include<iomanip>
#include<string>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
ifstream sampleGrades4("sampleGrades4.txt");
ofstream outputGrades("outputgrades.txt");
string firstLine;
int TotalStudents;
double ID = 0.0, Attendance, hw1, hw2, hw3, hw4, hw5, hw6, hw7, exam1, exam2, finalExam,CourseGradePercentage;
float LetterGrade;
int NumA = 0;
int NumB = 0;
int NumC = 0;
int NumD = 0;
int NumF = 0;
string Grade = "";
if (sampleGrades4.is_open())
{
getline(sampleGrades4, firstLine);
sampleGrades4 >> TotalStudents;
cout << "No. of students: " << TotalStudents << endl;
cout << firstLine << endl;
cout << "ID" << setw(18) << "Course Grade" << setw(16) << "Letter Grade" << endl;
outputGrades << "ID" << setw(18) << " Course Grade" << setw(16) << "Letter Grade" << endl;
while ( !sampleGrades4.eof() )
{
sampleGrades4 >> ID >> Attendance >> hw1 >> hw2 >> hw3 >> hw4 >> hw5 >> hw6 >> hw7 >> exam1 >> exam2 >> finalExam;
CourseGradePercentage = Attendance*0.10 / 25 + (hw1 + hw2 + hw3 + hw4 + hw5 + hw6 + hw7)*0.35 / 700 + exam1*0.15 / 25 + exam2*0.15 / 25 + finalExam * 0.25 / 40;
CourseGradePercentage = CourseGradePercentage*100;
cout << ID << setw(14) << CourseGradePercentage;
outputGrades << ID << setw(14) << CourseGradePercentage;
if (LetterGrade >= 97 && LetterGrade <= 100)
{
Grade = " A+ ";
NumA++;
}
else if (LetterGrade >= 93 && LetterGrade < 97)
{
Grade = " A ";
NumA++;
}
else if (LetterGrade >= 90 && LetterGrade < 93)
{
Grade = " A- ";
NumA++;
}
else if (LetterGrade >= 87 && LetterGrade < 90)
{
Grade = " B+ ";
NumB++;
}
else if (LetterGrade >= 83 && LetterGrade < 87)
{
Grade = " B ";
NumB++;
}
else if (LetterGrade >= 80 && LetterGrade < 83)
{
Grade = " B- ";
NumB++;
}
else if (LetterGrade >= 77 && LetterGrade < 80)
{
Grade = " C+ ";
NumC++;
}
else if (LetterGrade >= 73 && LetterGrade < 77)
{
Grade = " C ";
NumC++;
}
else if (LetterGrade >= 70 && LetterGrade < 73)
{
Grade = " C- ";
NumC++;
}
else if (LetterGrade >= 60 && LetterGrade < 70)
{
Grade = " D ";
NumD++;
}
else if (LetterGrade >= 0 && LetterGrade < 60)
{
Grade = " F ";
NumF++;
}
cout << setw(15) << Grade << endl;
outputGrades << setw(15) << Grade << endl;
}
outputGrades << setw(10) << ID << setw(14) << CourseGradePercentage << setw(14) << LetterGrade << 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;
}
|