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
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
//Put the Student class definition after this line
class Student
{
public: //public data and methods
Student(char[], int, int, int, double); //Constructor
void setPgmPts( int newPgmPts );
void setQuizPts( int newQuizPts );
void setSum2Low( int newSum2Low );
void setExamPts( double newExamPts );
double calcPgmAverage();
double calcExamAndQuizAverage();
double calcCourseAverage();
char letterGrade();
void printStudent();
private: //private data members
char StudentName[50];
int ProgramPoints;
int QuizPoints;
int SumTwoLowest;
double ExamPoints;
static const int MAX_PGM_PTS;
static const int MAX_QUIZ_PTS;
static const int MAX_SUM2LOW_PTS;
static const double MAX_EXAM_PTS;
};
const int Student::MAX_PGM_PTS = 905;
const int Student::MAX_QUIZ_PTS = 120;
const int Student::MAX_SUM2LOW_PTS = 20;
const double Student::MAX_EXAM_PTS = 300;
int main()
{
Student student1("Ronak Patel",767,106,10,286.50);
Student student2("Peter Laviolette",474,53,0,218.50);
Student student3("Joel Quenneville",905,120,20,300.00);
Student student4("Ken Hitchcock",-1,-2,-3,-4.00);
cout << "The first Student object" << endl;
student1.printStudent();
cout << "The second Student object" << endl;
student2.printStudent();
cout << "The Third Student object" << endl;
student3.printStudent();
cout << "The fourth Student object" << endl;
student4.printStudent();
return 0;
}
Student::Student(char StudentName[],int ProgramPoints,int QuizPoints, int SumTwoLowest, double Exampoints)
{
strcpy(StudentName,"Ronak Patel");
setPgmPts(ProgramPoints);
setQuizPts(QuizPoints); // it has to match the setQuizPts declaration
setSum2Low(SumTwoLowest); // same as above
setExamPts(ExamPoints); // same as above
}
void Student::setPgmPts( int newPgmPts )
{
if (newPgmPts < 0 && newPgmPts > MAX_PGM_PTS)
{
cout <<"Error in setPgmPts: argument is invalid";
ProgramPoints = 0;
}
else
{
ProgramPoints = newPgmPts;
}
}
void Student::setQuizPts( int newQuizPts )
{
if (newQuizPts < 0 && newQuizPts > MAX_QUIZ_PTS)
{
cout <<"Error in setQuizPts: argument is invalid";
QuizPoints = 0;
}
else
{
QuizPoints = newQuizPts;
}
}
void Student::setSum2Low( int newSum2Low )
{
if (newSum2Low < 0 && newSum2Low > MAX_SUM2LOW_PTS)
{
cout <<"Error in setSum2Low: argument is invalid";
SumTwoLowest = 0;
}
else
{
SumTwoLowest = newSum2Low;
}
}
void Student::setExamPts( double newExamPts )
{
if (newExamPts < 0 && newExamPts > MAX_EXAM_PTS)
{
cout <<"Error in setExamPts: argument is invalid";
ExamPoints = 0;
}
else
{
ExamPoints = newExamPts;
}
}
double Student::calcPgmAverage()
{
double pgmAverage;
pgmAverage = ProgramPoints / MAX_PGM_PTS * 100;
return pgmAverage;
}
double Student::calcExamAndQuizAverage()
{
double examAndQuizAverage;
examAndQuizAverage = (ExamPoints + QuizPoints - SumTwoLowest/
MAX_EXAM_PTS + MAX_PGM_PTS - MAX_SUM2LOW_PTS) * 100;
return examAndQuizAverage;
}
double Student::calcCourseAverage()
{
double courseAverage;
courseAverage = .35 * calcPgmAverage() + .65 * calcExamAndQuizAverage();
return courseAverage;
}
char Student::letterGrade()
{
char letterGrade;
if(calcCourseAverage() >= 90.00 && calcCourseAverage() <= 100.00)
{
letterGrade = 'A';
}
else if (calcCourseAverage() >= 80.00 && calcCourseAverage() <= 90.00)
{
letterGrade = 'B';
}
else if (calcCourseAverage() >= 70.00 && calcCourseAverage() <= 80.00)
{
letterGrade = 'C';
}
else if (calcCourseAverage() >= 60.00 && calcCourseAverage() <= 70.00)
{
letterGrade = 'D';
}
else if (calcCourseAverage() < 60.00)
{
letterGrade = 'F';
}
else if (calcPgmAverage() < 55.00 && calcExamAndQuizAverage() < 55.00)
{
letterGrade = 'F';
}
return letterGrade;
}
void Student::printStudent()
{
for (int i = 0; i <strlen(StudentName); i++)
{
cout << StudentName[i];
}
cout << setprecision(5)<<"Program Average: " << calcPgmAverage();
cout << setprecision(5)<< "Exam + Quiz Average: " << calcExamAndQuizAverage();
cout << setprecision(5)<<"Course Average: " << calcCourseAverage();
cout << setprecision(5)<< "Letter Grade: " << letterGrade();
}
|