-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstudent.cpp
111 lines (97 loc) · 3.23 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
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
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include "student.hpp"
Student::Student() {
// Initialize RNG with current time as seed
// srand(time(nullptr));
// id_ = rand() % 10000 + 1;
givenName_ = "";
surname_ = "";
coursesTaken_ = {};
}
Student::Student(std::string givenName, std::string surname) : givenName_(givenName), surname_(surname) {
// Initialize RNG with current time as seed
// srand(time(nullptr));
// id_ = rand() % 10000 + 1;
}
// int Student::getId() {
// return id_;
// }
std::string Student::getGivenName() {
return givenName_;
}
std::string Student::getSurname() {
return surname_;
}
std::vector<std::string> Student::getCoursesTaken() {
return coursesTaken_;
}
int Student::amountOfCoursesTaken() {
return coursesTaken_.size();
}
std::string Student::getCourse(int index) {
if(index >= 0 && index < coursesTaken_.size())
return coursesTaken_[index];
return "";
}
bool Student::hasTaken(std::string courseId) {
return std::find(coursesTaken_.begin(), coursesTaken_.end(), courseId) != coursesTaken_.end();
}
void Student::addCourse(std::string courseId) {
coursesTaken_.push_back(courseId);
}
void Student::removeCourse() {
coursesTaken_.pop_back();
}
bool Student::removeCourse(std::string courseId) {
if(std::find(coursesTaken_.begin(), coursesTaken_.end(), courseId) != coursesTaken_.end()) {
coursesTaken_.erase(std::find(coursesTaken_.begin(), coursesTaken_.end(), courseId));
return true;
}
return false;
}
void Student::removeCourse(int index) {
coursesTaken_.erase(std::find(coursesTaken_.begin(), coursesTaken_.end(), coursesTaken_[index]));
}
std::string Student::toString(bool full = false) {
if(full) {
std::string output = surname_ + ", " + givenName_ + "\n";
output += "{ ";
for(int i = 0; i < coursesTaken_.size(); i++) {
if(i != coursesTaken_.size() - 1)
output += coursesTaken_[i] + ", ";
else
output += coursesTaken_[i];
}
return output + " }";
}
return "[" + surname_ + ", " + givenName_ + "]";
}
bool Student::operator<(const Student& other) const {
if(surname_ == other.surname_)
return givenName_.compare(other.givenName_) < 0;
return surname_.compare(other.surname_) < 0;
}
bool Student::operator>(const Student& other) const {
if(surname_ == other.surname_)
return givenName_.compare(other.givenName_) > 0;
return surname_.compare(other.surname_) > 0;
}
bool Student::operator==(const Student& other) const {
if(surname_ == other.surname_)
return givenName_ == other.givenName_;
return surname_ == other.surname_;
}
bool Student::operator<=(const Student& other) const{
if(surname_ == other.surname_)
return givenName_.compare(other.givenName_) <= 0;
return surname_.compare(other.surname_) <= 0;
}
bool Student::operator>=(const Student& other) const {
if(surname_ == other.surname_)
return givenName_.compare(other.givenName_) >= 0;
return surname_.compare(other.surname_) >= 0;
}