-
Notifications
You must be signed in to change notification settings - Fork 0
/
MAC2311.cpp
331 lines (315 loc) · 9.78 KB
/
MAC2311.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
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#include "MAC2311.h"
#include <iostream>
//constructor initializes everything to -1
MAC2311::MAC2311() {
hittPoints = -1;
finals = -1;
for (int i = 0; i < 20; i++) {
if (i < 13) {
webAssign[i] = -1;
webAssignPrint[i] = -1;
}
if (i < 10) {
quizzes[i] = -1;
quizzesPrint[i] = -1;
}
if (i < 5) {
writtenHomework[i] = -1;
writtenHomeworkPrint[i] = -1;
}
if (i < 20) {
examsPrint[i] = -1;
}
exams[i] = -1;
}
}
//these methods take in a new grade value and change or set the existing value
void MAC2311::updateHittPoints(double newScore) {
hittPoints = newScore;
}
void MAC2311::updateWebAssign(int assignmentNumber, double newScore) {
webAssign[assignmentNumber] = newScore;
webAssignPrint[assignmentNumber] = newScore;
}
void MAC2311::updateQuiz(int quizNumber, double newScore) {
quizzes[quizNumber] = newScore;
quizzesPrint[quizNumber] = newScore;
}
void MAC2311::updateWrittenHomework(int assignmentNumber, double newScore) {
writtenHomework[assignmentNumber] = newScore;
writtenHomeworkPrint[assignmentNumber] = newScore;
}
void MAC2311::updateExam(int examNumber, double newScore) {
exams[examNumber] = newScore;
examsPrint[examNumber] = newScore;
}
void MAC2311::updateFinal(double newScore) {
finals = newScore;
}
//this method replaces the lowest exam grade with final exam grade if final is higher
void MAC2311::examReplace(array<double, 20> examGrades, double finals) {
int lowestIndex = 0;
//this part finds the index of the lowest exam grade
for (int i = 1; i < 3; i++) {
if (examGrades[i] < examGrades[lowestIndex]) {
lowestIndex = i;
}
}
//this part compares final exam grade to the lowest exam grade
//if final is higher it replaces the lowest exam grade
if (finals > examGrades[lowestIndex]) {
examGrades[lowestIndex] = finals;
}
}
//this is a generic thing that adds up the contents of an array and returns the value
//it is used in pretty much every course gpa calculation
double MAC2311::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;
}
//this is exactly like pointSummer except that it takes in an array<T, V> type
double MAC2311::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 sorts through the quiz array and finds the index of the two lowest quiz grades
//these two grades are dropped
//and then the rest of the grades are summed and returned as a double
double MAC2311::bestOfQuizzes(double quizzes[]) {
double bestSum = 0;
int lowestIndex = 0;
//finding lowest index
for (int i = 1; i < 10; i++) {
if (quizzes[i] < quizzes[lowestIndex]) {
lowestIndex = i;
}
}
int nextLowest;
if (lowestIndex == 0) {
nextLowest = 1;
}
else {
nextLowest = 0;
}
//finds 2nd lowest by redoing the check and ignoring the lowest one
for (int i = 1; i < 10; i++) {
if (quizzes[i] < quizzes[nextLowest] && i != lowestIndex) {
nextLowest = i;
}
}
bestSum = pointSummer(quizzes, 10) - quizzes[lowestIndex] - quizzes[nextLowest];
return bestSum;
}
//this method acts the same way as the one above, but it only finds the lowest homework grade
//and drops it before returning the sum of the rest of them
double MAC2311::bestOfWrittenHomework(double writtenHomework[]) {
double bestSum = 0;
int lowestIndex = 0;
for (int i = 1; i < 5; i++) {
if (writtenHomework[i] < writtenHomework[lowestIndex]) {
lowestIndex = i;
}
}
if (writtenHomework[lowestIndex] == -1) {
bestSum = pointSummer(writtenHomework, 5);
}
else {
bestSum = pointSummer(writtenHomework, 5) - writtenHomework[lowestIndex];
}
return bestSum;
}
//this method was made to deal with webassign because it's weird
//since we don't know the point values for the individual assignments
//so these grades are taken as percentages, averaged, and that average is projected onto the total possible point value later on
double MAC2311::webAssignCalculator(double webAssign[]) {
//find number of grades that have been entered
double points;
int count = 0;
for (int i = 0; i < 13; i++) {
if (webAssign[i] != -1) {
count++;
}
}
//makes sure it never divides by zero
//if there are no webassign grades it returns -1
if (count != 0) {
points = ((pointSummer(webAssign, 13) / count) / 100) * 50;
}
else {
points = -1;
}
return points;
}
//This method condenses all the points and then sets the gpa value accordingly
void MAC2311::calcGpa() {
double totalPoints = 0; //this tracks number of points earned
double pointDivision = 0; //this will track number of available points based on what has been graded
//webAssign points max out at 50
//for webassign, take in each grade as percentage, then use average percentage to calculate total points out of 50
//the if statements determine how the various grades affect the total, depending on which ones have been graded
if (webAssignCalculator(webAssign) != -1) {
totalPoints += webAssignCalculator(webAssign);
pointDivision += 50;
}
if (hittPoints != -1) {
totalPoints += (hittPoints * 0.4);
pointDivision += 40;
}
//now figure out how many quiz grades have been entered
int quizCount = 0;
for (int i = 0; i < 10; i++) {
if (quizzes[i] != -1) {
quizCount++;
}
}
//the if determinse how the quizzes affect the grade
//because there were a few different cases
if (quizCount > 8) {
pointDivision += 48;
totalPoints += (bestOfQuizzes(quizzes) / 8 * 0.48);
}
else if (quizCount > 0 && quizCount < 8) {
pointDivision += (6 * quizCount);
totalPoints += (pointSummer(quizzes, 10) / quizCount * 0.48);
}
//same but for written homework
int writtenHomeworkCount = 0;
for (int i = 0; i < 5; i++) {
if (writtenHomework[i] != -1) {
writtenHomeworkCount++;
}
}
if (writtenHomeworkCount == 5) {
pointDivision += 12;
totalPoints += (bestOfWrittenHomework(writtenHomework) / 4 * 0.12);
}
else if (writtenHomeworkCount > 0 && writtenHomeworkCount < 5) {
pointDivision += (3 * writtenHomeworkCount);
totalPoints += (pointSummer(writtenHomework, 5) / writtenHomeworkCount * 0.12);
}
//count entered exam grades
int examCount = 0;
for (int i = 0; i < 3; i++) {
if (exams[i] != -1) {
examCount++;
}
}
//if there is a final exam grade and at least one regular exam grade we can do this
if (finals != -1 && examCount != 0) {
examReplace(exams, finals);
}
if (examCount > 0) {
pointDivision += (75 * examCount);
(totalPoints += examPointSummer(exams) * 0.75);
}
if (finals != -1) {
pointDivision += 75;
totalPoints += (finals * 0.75);
}
//makes sure no division by zer0 when finding percentage
double percentage;
if (pointDivision != 0) {
percentage = (totalPoints / pointDivision);
}
else {
//if no grades are in, gpa returns -1, which is what a percentage of -1 will lead to
percentage = -1;
}
//these ifs serve to set the gpa according to the total point value converted to a percentage
if (percentage >= (405.0 / 450.0)) {
//I changed these to use the setGPA function when I was debugging
//not sure if it is needed but it works like this so it shall remain
setGpa(4);
}
else if (percentage >= (390.0 / 450.0) && percentage < (405.0 / 450.0)) {
setGpa(3.67);
}
else if (percentage >= (375.0 / 450.0) && percentage < (390.0 / 450.0)) {
setGpa(3.33);
}
else if (percentage >= (360.0 / 450.0) && percentage < (375.0 / 450.0)) {
setGpa(3);
}
else if (percentage >= (345.0 / 450.0) && percentage < (360.0 / 450.0)) {
setGpa(2.67);
}
else if (percentage >= (325.0 / 450.0) && percentage < (345.0 / 450.0)) {
setGpa(2.33);
}
else if (percentage >= (305.0 / 450.0) && percentage < (325.0 / 450.0)) {
setGpa(2);
}
else if (percentage >= (290.0 / 450.0) && percentage < (305.0 / 450.0)) {
setGpa(1.67);
}
else if (percentage >= (275.0 / 450.0) && percentage < (290.0 / 450.0)) {
setGpa(1.33);
}
else if (percentage >= (260.0 / 450.0) && percentage < (275.0 / 450.0)) {
setGpa(1);
}
else if (percentage >= (245.0 / 450.0) && percentage < (260.0 / 450.0)) {
setGpa(0.67);
}
else if (percentage >= 0 && percentage < (245.0 / 450.0)) {
setGpa(0);
}
else {
setGpa(-1);
}
}
//prints all the grades for the course
void MAC2311::printAll()
{
cout << courseName << endl;
cout << "Hittpoints: " << hittPoints << endl;
cout << endl;
cout << "WebAssign: " << endl;
for (size_t i = 0; i < webAssignPrint.size(); i++) {
if (webAssignPrint[i] >= 0) {
cout << i + 1 << ". " << webAssignPrint[i] << endl;
}
}
cout << endl;
cout << "Quizzes: " << endl;
for (size_t i = 0; i < quizzesPrint.size(); i++) {
if (quizzesPrint[i] >= 0) {
cout << i + 1 << ". " << quizzesPrint[i] << endl;
}
}
cout << endl;
cout << "Written Homework: " << endl;
for (size_t i = 0; i < writtenHomeworkPrint.size(); i++) {
if (writtenHomeworkPrint[i] >= 0) {
cout << i + 1 << ". " << writtenHomeworkPrint[i] << endl;
}
}
cout << "Exams: " << endl;
for (size_t i = 0; i < examsPrint.size(); i++) {
if (examsPrint[i] >= 0) {
cout << i + 1 << ". " << examsPrint[i] << endl;
}
}
cout << endl;
cout << "Exams: " << endl;
for (size_t i = 0; i < examsPrint.size(); i++) {
if (examsPrint[i] >= 0) {
cout << i + 1 << ". " << examsPrint[i] << endl;
}
}
cout << endl;
cout << "Finals: " << finals << endl;
cout << endl;
}