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
|
#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;
const int PGM_POINTS = 905;
const int QUIZ_POINTS = 120;
const int MAX_SUM = 20;
const double EXAM_POINTS = 300;
class student{
public:
student (const char [], int, int, int, double);
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:
char name [50];
int pgmPts;
int quizPts;
int sum2Low;
double examPts;
};
int main(){
student s1 = student ("Rando", 767 , 106, 10, 286.50);
student s2 = student ("Pat Jones", 474, 53, 0, 218.50);
student s3 = student ("Chris Wilson", 905, 120, 20, 300.00);
student s4 = student ("Jarret Jack", 906, 121, 21, 301);
cout << "The First Student" << endl;
s1.printStudent();
cout << "The Second Student" << endl;
s2.printStudent();
cout << "The Third Student" << endl;
s3.printStudent();
cout << "The Fourth Student" << endl;
s4.printStudent();
s4 = student ("Jarret Jack", 639, 107, 8, 211.50);
s4.printStudent();
return 0;
}
void student::setPgmPts(int newPgmPts){
if (pgmPts < 0 or pgmPts > PGM_POINTS){
newPgmPts = 0;
cout << "Errror in setPgmPts: argument is invalid" << endl;;
}
else {
newPgmPts = pgmPts;
}
}
void student::setQuizPts(int newQuizPts){
if (quizPts < 0 && quizPts > QUIZ_POINTS){
newQuizPts = 0;
cout << "Error in setQuizPts: argument is invalid" << endl;
}
else {
newQuizPts = quizPts;
}
}
void student::setSum2Low(int newSum2Low){
if (sum2Low < 0 && sum2Low > MAX_SUM){
newSum2Low = 0;
cout << "Error in setSum2Low: argument is invalid" << endl;
}
else {
newSum2Low = sum2Low;
}
}
void student::setExamPts(double newExamPts){
if (examPts < 0 && examPts > EXAM_POINTS){
newExamPts = 0;
cout << "Error in setExamPts: argument is invlid" << endl;
}
else {
newExamPts = examPts;
}
}
double student::calcPgmAverage(){
double i;
i = (pgmPts / PGM_POINTS) * 100;
return i;
}
double student::calcExamAndQuizAverage(){
double i;
i = (examPts+quizPts-sum2Low)/(EXAM_POINTS+QUIZ_POINTS-MAX_SUM) * 100;
return i;
}
double student::calcCourseAverage(){
double i;
i = (.30 *((pgmPts / PGM_POINTS) * 100)) + (.70 *((examPts+quizPts-sum2Low)/(EXAM_POINTS+QUIZ_POINTS-MAX_SUM) * 100));
return i;
}
char student::letterGrade(){
double i;
char f;
i = (.30 *((pgmPts / PGM_POINTS) * 100))+ (.70*((examPts+quizPts-sum2Low)/(EXAM_POINTS+QUIZ_POINTS-MAX_SUM) * 100));
if (i >= 90 && i <= 100){
f = 'A';
}
else if (i >= 80 && i <=90){
f = 'B';
}
else if (i >= 70 && i<= 80){
f = 'C';
}
else if (i >= 60 && i <= 70){
f = 'D';
}
else {
f = 'F';
}
return f;
}
void student::printStudent(){
for (int i = 0; i < strlen(name); i++){
cout << name[i];
}
cout << endl << " Program Average: " << calcPgmAverage () << endl;
cout << " Exam + Quiz Average: " << calcExamAndQuizAverage() << endl;
cout << " Course Average: " << calcCourseAverage() << endl;
cout << " Letter Grade: " << letterGrade() << endl;
}
student::student(const char [], int pgmPts, int quizPts, int sum2Low, double examPts){
strcpy (name, "Rando");
setPgmPts(pgmPts);
setQuizPts(quizPts);
setSum2Low(sum2Low);
setExamPts(examPts);
}
|