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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
// Programmer: G**** E******
// Program: Program Assignment 1
// Class: 152, Fall, 2010
// Compiler: Bloodshed DevC++
// Date: Oct 1, 2010
// Filename: E******G****Assignment2.cpp
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <string>
using namespace std;
void printHeading ();
string getStatus (int, double, double &, double &);
void printSummary (int, double, double, double, double, double);
int getQualPts (char);
int getHoursPassed (char, int);
int main()
{
ifstream in ("SemGrades.txt");
string lastName = "?",
firstName = "?",
iD = "?",
status = "?";
int students = 0,
hours = 0,
attHours = 0,
totalHoursAttempted = 0,
hoursPassed = 0,
studentHoursPassed = 0,
totalHoursPassed = 0,
qualPts = 0,
totalQualPts = 0;
char letterGrade = '?';
double GPA = 0.0,
semesterGPA = 0.0,
totalGPA = 0.0,
honors = 0,
probation = 0;
if (in.fail())
cout << "Can't open input file \n" << endl;
else cout << "Input file is open \n" << endl;
printHeading ();
while (in.peek() != EOF)
{
attHours = 0;
qualPts = 0;
studentHoursPassed = 0;
in >> lastName >> firstName >> iD;
students++;
while (in.peek() != '\n')
{
in >> hours >> letterGrade;
qualPts += hours * getQualPts(letterGrade);
hoursPassed = getHoursPassed(letterGrade, hours);
studentHoursPassed += hoursPassed;
attHours += hours;
}
totalHoursPassed += studentHoursPassed;
totalQualPts += qualPts;
totalHoursAttempted += attHours;
GPA = static_cast<double>(qualPts) / attHours;
status = getStatus(studentHoursPassed, GPA, honors, probation);
cout << lastName << " "
<< setw(1) << firstName
<< setw(18) << iD
<< setw(5) << attHours
<< setw(7) << studentHoursPassed
<< setw(7) << qualPts;
cout << fixed << showpoint << setprecision(3);
cout << setw(7) << GPA
<< setw(20) << status << "\n";
in.ignore(1, '\n');
}
double averageSemesterGPA = static_cast<double>(totalQualPts) / totalHoursAttempted;
printSummary (students, totalHoursAttempted, totalHoursPassed, averageSemesterGPA, honors, probation);
system("pause");
return 0;
}
void printHeading ()
{
cout << setw(46) << "Semester Grade Report\n\n";
cout << setw(37) << "Att"
<< setw(10) << "Passed"
<< setw(6) << "Qual"
<< setw(17) << "Academic\n";
cout << "Student Name"
<< setw(20) << "Student ID"
<< setw(7) << "Hours"
<< setw(7) << "Hours"
<< setw(6) << "Pts"
<< setw(6) << "GPA"
<< setw(11) << "Status\n\n";
}
string getStatus (int hoursPassed, double GPA, double & honors, double & probabtion)
{
string status = "?";
if (GPA == 4.0 && hoursPassed >= 12)
{
status = "President's List";
honors++;
return status;
}
if (3.5 <= GPA && GPA <= 3.999 && hoursPassed >= 12)
{
status = "Dean's List";
honors++;
return status;
}
else if (GPA < 2.0)
{
status = "Probation";
probabtion++;
return status;
}
else status = " ";
}
void printSummary (int students, double totalHoursAttempted, double totalHoursPassed, double avgSemGPA, double honors, double probation)
{
double averageHours = totalHoursAttempted;
double averageHoursPassed = totalHoursPassed;
averageHours /= students;
averageHoursPassed /= students;
honors = (honors / students) * 100;
probation = (probation / students) * 100;
cout << "\nSUMMARY STATISTICS\n";
cout << "Total # students enrolled: " << students << endl;
cout << fixed << showpoint << setprecision(1);
cout << "Average # hours attempted: " << averageHours << endl;
cout << setw(27) << "Average # hours passed: " << averageHoursPassed << endl;
cout << fixed << showpoint << setprecision(3);
cout << setw(27) << "Average GPA: " << avgSemGPA << endl;
cout << fixed << showpoint << setprecision(1);
cout << setw(27) << "Students with Honors: " << honors << "%\n";
cout << setw(27) << "Students on Probation: " << probation << "%\n\n";
}
int getQualPts (char letter)
{
int QualPts = 0;
switch (letter)
{
case 'A' : QualPts = 4;
break;
case 'B' : QualPts = 3;
break;
case 'C' : QualPts = 2;
break;
case 'D' : QualPts = 1;
break;
case 'F' : QualPts = 0;
break;
default : QualPts = 0;
}
return QualPts;
}
int getHoursPassed (char letter, int hours)
{
int hoursPassed = 0;
switch (letter)
{
case 'A' :
case 'B' :
case 'C' :
case 'D' :
return hoursPassed = hours;
default : hoursPassed = 0;
}
return hoursPassed;
}
|