-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOP3503.cpp
155 lines (144 loc) · 3.63 KB
/
COP3503.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
#include "COP3503.h"
//constructor initializes everything to -1
COP3503::COP3503() {
groupProject = -1;
for (int i = 0; i < 20; i++) {
if (i < 3) {
assignments[i] = -1;
tempAssignments[i] = -1;
}
exams[i] = -1;
}
}
//these methods take in a new grade value and change or set the existing value
void COP3503::updateAssignments(int assignmentNumber, double newScore) {
assignments[assignmentNumber] = newScore;
tempAssignments[assignmentNumber] = newScore;
}
void COP3503::updateGroupProject(double newScore) {
groupProject = newScore;
}
void COP3503::updateExams(int examNumber, double newScore) {
exams[examNumber] = newScore;
}
//this is a generic thing that adds up the contents of an array and returns the value
double COP3503::pointSummer(double grades[], int arraySize) {
double total = 0;
for (int i = 0; i < arraySize; i++) {
total += grades[i];
}
return total;
}
double COP3503::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 as percentages and then sets the gpa value accordingly
//calcs gpa based on syllabus
//does not add in grades that are -1 which means that they have not been set
void COP3503::calcGpa() {
double percentage = 0;
double divisor = 0;
//count assignment grades
int assignmentCount = 0;
for (int i = 0; i < 3; i++) {
if (assignments[i] != -1) {
assignmentCount++;
}
}
if (assignmentCount != -1) {
percentage += ((pointSummer(assignments, 3) / assignmentCount) * 0.3);
divisor += 30;
}
//count exam grades
int examCount = 0;
for (int i = 0; i < 2; i++) {
if (exams[i] != -1) {
examCount++;
}
}
if (examCount != -1) {
percentage += ((examPointSummer(exams) / examCount) * 0.4);
divisor += 40;
}
if (groupProject != -1) {
percentage += (groupProject * 0.3);
divisor += 30;
}
if (divisor != 0) {
percentage /= divisor;
percentage *= 100;
}
else {
percentage = -1;
}
//these ifs serve to set the gpa according to the total percentage value
if (percentage >= 93) {
gpa = 4.0;
}
else if (percentage >= 90 && percentage < 93) {
gpa = 3.67;
}
else if (percentage >= 87 && percentage < 90) {
gpa = 3.33;
}
else if (percentage >= 83 && percentage < 87) {
gpa = 3;
}
else if (percentage >= 80 && percentage < 83) {
gpa = 2.67;
}
else if (percentage >= 77 && percentage < 80) {
gpa = 2.33;
}
else if (percentage >= 73 && percentage < 77) {
gpa = 2;
}
else if (percentage >= 70 && percentage < 73) {
gpa = 1.67;
}
else if (percentage >= 67 && percentage < 70) {
gpa = 1.33;
}
else if (percentage >= 63 && percentage < 67) {
gpa = 1;
}
else if (percentage >= 60 && percentage < 63) {
gpa = 0.67;
}
else if (percentage >= 0 && percentage < 60) {
gpa = 0;
}
else {
gpa = -1;
}
}
//prints all of the grade values for the class
void COP3503::printAll()
{
cout << "COP3503" << endl;
cout << "Group Project : " << groupProject << endl;
cout << endl;
cout << "Programming Assignments : " << endl;
for (size_t i = 0; i < tempAssignments.size(); i++) {
if (tempAssignments[i] >= 0)
{
cout << i + 1 << ". " << tempAssignments[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;
}