forked from jordanklahr/ece160-hw05
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.cpp
53 lines (50 loc) · 1.17 KB
/
Student.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
#include "Student.h"
Student::Student(std::string fn, std::string ln, int y, Major m){
_first_name = fn;
_last_name = ln;
_grad_year = y;
_major = m;
}
Student::~Student() {}
float Student::getGpa(){
float gpa = 0;
for (int i = 0; i < _grades.size(); i++){
gpa = gpa + _grades[i];
}
if (gpa != 0) {
gpa = gpa/_grades.size();
}
return gpa;
}
void Student::addGrade(float grade) {
_grades.push_back(grade);
}
void Student::printInfo() {
std::string major;
switch(_major) {
case Major::EE:
major = "EE";
break;
case Major::ME:
major = "ME";
break;
case Major::CE:
major = "CE";
break;
case Major::CHE:
major = "CHE";
break;
case Major::BSE:
major = "BSE";
break;
case Major::ART:
major = "ART";
break;
case Major::ARCH:
major = "ARCH";
break;
}
printf("%s, %s\n", _last_name.c_str(), _first_name.c_str());
printf("%s, %d\n", major.c_str(), _grad_year);
printf("GPA: %.2f\n", getGpa());
}