-
Notifications
You must be signed in to change notification settings - Fork 0
/
student.cpp
50 lines (42 loc) · 1.13 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
#include "student.h"
Student::Student(std::string name, std::vector<float> grades, bool oncontract) {
_name = name;
_onContract = oncontract;
_grades = grades;
_average = 0;
}
Student::Student(Student &another){
this-> _name = another.getName();
this-> _onContract = another.isOnContract();
for(int i = 0; i < another._grades.size(); i++){
this->_grades[i] = another._grades[i];
}
this->_average = another.getAvarage();
}
std::string Student::getName(){
return _name;
}
bool Student::isOnContract(){
return _onContract;
}
float Student::getAvarage(){
if (!_onContract && !_average){
countAverageGrade();
}
return _average;
}
void Student::countAverageGrade(){
for(int i = 0; i < _grades.size(); i++){
_average += _grades[i];
}
_average /= _grades.size();
}
float Student::getNthGrade(int n){
if( n < _grades.size()){
return _grades[n];
}
else {
std::string msg = "Cannot get " + std::to_string(n) + "th grade, as the grade count is " + std::to_string(_grades.size());
throw std::out_of_range("msg");
}
}