forked from dafern7/ece160-hw06
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student.cpp
69 lines (63 loc) · 1.35 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 <iostream>
#include "Student.h"
#include <iomanip>
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() {
unsigned int i = 0;
float gpasum = 0;
while(i < _grades.size())
{
gpasum = gpasum + _grades.at(i);
i++;
}
float gpa = gpasum / _grades.size();
return gpa;
return 0.0;
}
void Student::addGrade(float grade) {
_grades.push_back(grade);
}
const std::string& Student::getLastName() {
// TODO Fill in real implementation
return _last_name;
}
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;
}
return "Error";
}
/*
* Should print:
* _last_name, first_name
* _major _grad_year
* GPA: x.xx
*/
void Student::printInfo() {
std::cout << _last_name <<", " << _first_name<< std::endl;
std::cout << majorString(_major) << " "<< _grad_year<< std::endl;
std::cout << "GPA: " << std::setprecision(2)<< std::fixed <<getGpa() << std::endl;
}