-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent.cpp
More file actions
208 lines (183 loc) · 4.56 KB
/
Student.cpp
File metadata and controls
208 lines (183 loc) · 4.56 KB
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
/*
Pham, Kidd (Team Leader)
Nguyen, Cindy
Dao, Kenneth
Rodriguez, Cele
Project: Grade Report
CS A250
Fall 2023
*/
#include "Student.h"
#include <iostream>
#include <iomanip>
using namespace std;
void Student::setStudent(const Student& paramStudent)
{
studentID = paramStudent.studentID;
firstName = paramStudent.firstName;
lastName = paramStudent.lastName;
numberOfCourses = paramStudent.numberOfCourses;
tuitionWasPaid = paramStudent.tuitionWasPaid;
coursesCompleted = paramStudent.coursesCompleted;
}
void Student::setStudentInfo(int newIDNum, const string& newFirstName,
const string& newLastName, bool newTuitionBoolean,
const multimap<Course, char>& newCoursesCompleted)
{
studentID = newIDNum;
firstName = newFirstName;
lastName = newLastName;
numberOfCourses = static_cast<int> (newCoursesCompleted.size());
tuitionWasPaid = newTuitionBoolean;
coursesCompleted = newCoursesCompleted;
}
bool Student::updatedCourse(char newGrade, const string& prefix, int num)
{
for (auto& courseMapElem : coursesCompleted)
{
if (courseMapElem.first.getCoursePrefix() == prefix
&& courseMapElem.first.getCourseNumber() == num)
{
courseMapElem.second = newGrade;
return true;
}
}
return false;
}
void Student::getName(string& fName, string& lName) const
{
fName = firstName;
lName = lastName;
}
int Student::getID() const
{
return studentID;
}
string Student::getFirstName() const
{
return firstName;
}
string Student::getLastName() const
{
return lastName;
}
int Student::getNumberOfCourses() const
{
return numberOfCourses;
}
int Student::getUnitsCompleted() const
{
int totalUnits = 0;
auto courseItr = coursesCompleted.begin();
auto coursesEnd = coursesCompleted.end();
for (courseItr; courseItr != coursesEnd; ++courseItr)
{
totalUnits += courseItr->first.getCourseUnits();
}
return totalUnits;
}
multimap<Course, char> Student::getCoursesCompleted() const
{
return coursesCompleted;
}
bool Student::isTuitionPaid() const
{
return tuitionWasPaid;
}
bool Student::isCourseCompleted(const string& coursePrefix,
int courseNumber) const
{
if (numberOfCourses == 0)
{
return false;
}
else
{
auto itr = coursesCompleted.begin();
auto end = coursesCompleted.end();
for (itr; itr != end; ++itr)
{
if (itr->first.getCoursePrefix() == coursePrefix &&
itr->first.getCourseNumber() == courseNumber)
{
return true;
}
}
return false;
}
}
double Student::calculateGPA() const
{
double totalUnits = 0;
double qualityPoints = 0;
auto courseItr = coursesCompleted.begin();
auto coursesEnd = coursesCompleted.end();
for (courseItr; courseItr != coursesEnd; ++courseItr)
{
totalUnits += courseItr->first.getCourseUnits();
if (courseItr->second == 'A')
{
qualityPoints += 4 * courseItr->first.getCourseUnits();
}
else if (courseItr->second == 'B')
{
qualityPoints += 3 * courseItr->first.getCourseUnits();
}
else if (courseItr->second == 'C')
{
qualityPoints += 2 * courseItr->first.getCourseUnits();
}
else if (courseItr->second == 'D')
{
qualityPoints += 1 * courseItr->first.getCourseUnits();
}
else
{
qualityPoints += 0;
}
}
return qualityPoints / totalUnits;
}
double Student::billingAmount(double tuitionRate) const
{
return tuitionRate * numberOfCourses;
}
void Student::printStudent() const
{
cout << studentID << " - " << lastName << ", " << firstName << endl;
}
void Student::printStudentInfo(double tuitionRate) const
{
cout << "Student Name: "
<< lastName << ", " << firstName << endl
<< "Student ID: " << studentID << endl
<< "Number of courses completed: "
<< numberOfCourses << "\n\n"
<< "CourseNo Units Grade\n";
auto course = coursesCompleted.begin();
auto coursesEnd = coursesCompleted.end();
for (course; course != coursesEnd; ++course)
{
cout << course->first.getCoursePrefix() << " "
<< course->first.getCourseNumber() << " "
<< course->first.getCourseUnits() << " "
<< course->second << endl;
}
cout << endl << "Total number of credit hours: "
<< getUnitsCompleted() << endl;
if (!isTuitionPaid())
{
cout << "*** Grades are being held for not paying the tuition. ***" << endl
<< "Amount Due: $" << billingAmount(tuitionRate) << endl << endl;
}
else
{
cout << "Current Term GPA: "
<< fixed << setprecision(2) << calculateGPA() << endl << "\n";
}
for (size_t i = 0; i < 24; ++i)
{
cout << "-*";
}
cout << "-\n" << endl;
}