-
Notifications
You must be signed in to change notification settings - Fork 15
/
Student.cpp
69 lines (60 loc) · 1.21 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "Student.h"
#include <sstream>
#include <iostream>
#include <stdio.h>
Student::Student(std::string fn, std::string ln, int gy, Major m) {
_grad_year = gy;
_first_name = fn;
_last_name = ln;
_major = m;
}
Student::~Student() {}
float Student::getGpa() {
int i = 0;
float gpasum = 0;
while(i < _grades.size())
{
gpasum = gpasum + _grades.at(i);
i++;
}
float gpa = gpasum / _grades.size();
return gpa;
}
void Student::addGrade(float grade) {
_grades.push_back(grade);
}
std::string Student::majorString(Major m) {
std::string maj;
switch(m){
case Major::EE:
maj = "EE";
return maj;
case Major::ME:
maj = "ME";
return maj;
case Major::CE:
maj = "CE";
return maj;
case Major::CHE:
maj = "CHE";
return maj;
case Major::BSE:
maj= "BSE";
return maj;
case Major::ART:
maj = "ART";
return maj;
case Major::ARCH:
maj = "ARCH";
return maj;
}
}
void Student::printInfo() {
std::stringstream ss;
ss << _last_name << ", " << _first_name;
std::cout << ss.str() << std::endl;
std::stringstream ss1;
ss1 << majorString(_major) << " " << std::to_string(_grad_year);
std::cout << ss1.str() << std::endl;
printf("GPA: %.2f\n", getGpa());
}