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
|
#include <iostream>
#include <string>
using namespace std;
class StudentRecord
{
private:
int quiz1;
int quiz2;
int midtermExam;
int finalExam;
double averageScore;
char letterGrade;
void calculateAverageScore();
void calculateLetterGrade();
public:
StudentRecord();
StudentRecord(int quiz1, int quiz2, int midtermExam, int finalExam);
void setQuiz1(int quiz1);
int getQuiz1()const;
void setQuiz2(int quiz2);
int getQuiz2()const;
void setMidtermExam(int midtermExam);
int getMidtermExam()const;
void setFinalExam(int finalExam);
int getFinalExam()const;
double getAverageScore()const;
char getLetterGrade()const;
};
StudentRecord::StudentRecord() :
quiz1(0),
quiz2(0),
midtermExam(0),
finalExam(0),
averageScore(0.0),
letterGrade('z') {};
StudentRecord::StudentRecord(int quiz1, int quiz2, int midtermExam, int finalExam)
{
quiz1 >= 0 ? this->quiz1 = quiz1 : this->quiz1 = 0;
quiz2 >= 0 ? this->quiz2 = quiz2 : this->quiz2 = 0;
midtermExam >= 0 ? this->midtermExam = midtermExam : this->midtermExam = 0;
finalExam >= 0 ? this->finalExam = finalExam : this->finalExam = 0;
}
void StudentRecord::setQuiz1(int quiz1)
{
quiz1 >= 0 ? this->quiz1 = quiz1 : this->quiz1 = 0;
}
int StudentRecord::getQuiz1() const
{
return quiz1;
}
void StudentRecord::setQuiz2(int quiz2)
{
quiz2 >= 0 ? this->quiz2 = quiz2 : this->quiz2 = 0;
}
int StudentRecord::getQuiz2() const
{
return quiz2;
}
void StudentRecord::setMidtermExam(int midtermExam)
{
midtermExam >= 0 ? this->midtermExam = midtermExam : this->midtermExam = 0;
}
int StudentRecord::getMidtermExam() const
{
return midtermExam;
}
void StudentRecord::setFinalExam(int finalExam)
{
finalExam >= 0 ? this->finalExam = finalExam : this->finalExam = 0;
}
int StudentRecord::getFinalExam() const
{
return finalExam;
}
double StudentRecord::getAverageScore() const
{
return averageScore;
}
char StudentRecord::getLetterGrade() const
{
return letterGrade;
}
void StudentRecord::calculateAverageScore()
{
const int TOTAL_SCORE = 220;
const double TOTAL_PERCENT = 100;
double receivedScore =
this->quiz1 +
this->quiz2 +
this->midtermExam +
this->finalExam;
this->averageScore = receivedScore / TOTAL_SCORE * TOTAL_PERCENT;
}
void StudentRecord::calculateLetterGrade()
{
if (averageScore < 60) this->letterGrade = 'F';
else if (averageScore < 70) this->letterGrade = 'D';
else if (averageScore < 80) this->letterGrade = 'C';
else if (averageScore < 90) this->letterGrade = 'B';
else if (averageScore <= 100) this->letterGrade = 'A';
}
void gradeOutput(int q1, int q2, int midterm, int final, double avg, char letter)
{
cout << "Quiz 1: " << q1 << endl;
cout << "Quiz 2: " << q2 << endl;
cout << "Midterm Exam: " << midterm << endl;
cout << "Final Exam: " << final << endl;
cout << "Average: " << avg << endl;
cout << "Letter Grade: " << letter << endl;
}
int inputInteger(string prompt, int startRange, int endRange)
{
double min;
double max;
if (startRange > endRange)
{
min = endRange;
max = startRange;
}
else
{
min = startRange;
max = endRange;
}
int input;
do
{
cout << prompt;
if (!(cin >> input))
{
cout << "ERROR-3A: Invalid input. Must be an integer type.\n";
cin.clear();
cin.ignore(999, '\n');
}
else if (!(input >= min && input <= max))
cout << "ERROR-3A: Invalid input. Must be from " << startRange << "..." << endRange << ".\n";
else
break;
} while (true);
return input;
}
int main()
{
StudentRecord studentGrades;// (quiz1, quiz2, midtermExam, finalExam);
studentGrades.setQuiz1(inputInteger("Enter quiz1 score: ", 0, 10));
studentGrades.setQuiz2(inputInteger("Enter quiz2 score: ", 0, 10));
studentGrades.setMidtermExam(inputInteger("Enter midterm exam score: ", 0, 100));
studentGrades.setFinalExam(inputInteger("Enter final exam score: ", 0, 100));
cout << endl;
gradeOutput(
studentGrades.getQuiz1(),
studentGrades.getQuiz2(),
studentGrades.getMidtermExam(),
studentGrades.getFinalExam(),
studentGrades.getAverageScore(),
studentGrades.getLetterGrade());
}
|