-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAC2313.cpp
181 lines (171 loc) · 4.27 KB
/
MAC2313.cpp
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
#include "MAC2313.h"
//constructor initializes everything to -1
MAC2313::MAC2313() {
participation = -1;
finals = -1;
for (int i = 0; i < 27; i++) {
if (i < 20) {
exams[i] = -1;
}
if (i < 13) {
quizzes[i] = -1;
tempQuizzes[i] = -1;
}
webAssign[i] = -1;
tempWebAssign[i] = -1;
}
}
//these methods take in a new grade value and change or set the existing value
void MAC2313::updateParticipation(double newScore) {
participation = newScore;
}
void MAC2313::updateWebAssign(int assignmentNumber, double newScore) {
webAssign[assignmentNumber] = newScore;
tempWebAssign[assignmentNumber] = newScore;
}
void MAC2313::updateQuiz(int quizNumber, double newScore) {
quizzes[quizNumber] = newScore;
tempQuizzes[quizNumber] = newScore;
}
void MAC2313::updateExam(int examNumber, double newScore) {
exams[examNumber] = newScore;
}
void MAC2313::updateFinal(double newScore) {
finals = newScore;
}
//this is a generic thing that adds up the contents of an array and returns the value
double MAC2313::pointSummer(double grades[], int arraySize) {
double total = 0;
for (int i = 0; i < arraySize; i++) {
//this check makes it so only grades that have been entered are added to the total
if (grades[i] != -1) {
total += grades[i];
}
}
return total;
}
double MAC2313::examPointSummer(array<double, 20> examGrades) {
double total = 0;
for (size_t i = 0; i < examGrades.size(); i++) {
//this check makes it so only grades that have been entered are added to the total
if (examGrades[i] != -1) {
total += examGrades[i];
}
}
return total;
}
//This method condenses all the points and then sets the gpa value accordingly
void MAC2313::calcGpa() {
double percentage = 0;
double divider = 0;
if (participation != -1) {
percentage += (participation * 0.05);
divider += 5.0;
}
//count number of entered web assign grades
int webAssignCount = 0;
for (int i = 0; i < 27; i++) {
if (webAssign[i] != -1) {
webAssignCount++;
}
}
if (webAssignCount > 0) {
percentage += ((pointSummer(webAssign, 27) / webAssignCount) * 0.125);
divider += 12.5;
}
//count quizzes entered
int quizCount = 0;
for (int i = 0; i < 13; i++) {
if (quizzes[i] != -1) {
quizCount++;
}
}
if (quizCount > 0) {
percentage += ((pointSummer(quizzes, 13) / quizCount) * 0.125);
divider += 12.5;
}
//count exams
int examCount = 0;
for (int i = 0; i < 20; i++) {
if (exams[i] != -1) {
examCount++;
}
}
if (examCount > 0) {
percentage += ((examPointSummer(exams) / examCount) * 0.5);
divider += 50;
}
if (finals != -1) {
percentage += (finals * 0.2);
divider += 20;
}
if (divider != 0) {
percentage /= divider;
percentage *= 100;
}
else {
percentage = -1;
}
//these ifs serve to set the gpa according to the total percentage value
//Keeran does not do minus grades apparently, which is why this one is shorter than the others
if (percentage >= 90) {
gpa = 4.0;
}
else if (percentage >= 87 && percentage < 90) {
gpa = 3.33;
}
else if (percentage >= 80 && percentage < 87) {
gpa = 3;
}
else if (percentage >= 77 && percentage < 80) {
gpa = 2.33;
}
else if (percentage >= 70 && percentage < 77) {
gpa = 2;
}
else if (percentage >= 67 && percentage < 70) {
gpa = 1.33;
}
else if (percentage >= 60 && percentage < 67) {
gpa = 1;
}
else if (percentage >= 0 && percentage < 60) {
gpa = 0;
}
else {
gpa = -1;
}
}
//prints all of the grades for the course
void MAC2313::printAll()
{
cout << courseName << endl;
cout << "Participation Points: " << participation << endl;
cout << endl;
cout << "WebAssign: " << endl;
for (size_t i = 0; i < tempWebAssign.size(); i++) {
if (tempWebAssign[i] >= 0)
{
cout << i + 1 << ". " << tempWebAssign[i] << endl;
}
}
cout << endl;
cout << "Quizzes: " << endl;
for (size_t i = 0; i < tempQuizzes.size(); i++) {
if (tempQuizzes[i] >= 0)
{
cout << i + 1 << ". " << tempQuizzes[i] << endl;
}
}
cout << endl;
cout << "Exams: " << endl;
for (size_t i = 0; i < exams.size(); i++) {
if (exams[i] >= 0)
{
cout << i + 1 << ". " << exams[i] << endl;
}
}
cout << endl;
cout << "Finals: " << finals << endl;
cout << endl;
}