-
Notifications
You must be signed in to change notification settings - Fork 0
/
OOP - rec05.cpp
165 lines (147 loc) · 4.5 KB
/
OOP - rec05.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
FileName: rec05
Programmer: Yohann Abittan
The aim of this program is to simulate the grading system used at poly
*/
#include <vector>
#include <string>
#include <iostream>
using namespace std;
class Student {
private:
const string name;
vector<int> grades;
public:
Student(const string studentName) : name(studentName), grades(13,-1) {}
void getNumberOfGrades() {
int gradesSize;
for (int grade : grades) {
gradesSize = 0;
gradesSize++;
}
}
void displayStudent()const {
cout << "Student: " << name << "; Grades: ";
for (int grade : grades) {
cout << grade;
}
}
string getName() const { return name; }
void setGrade(const int& week, const int& grade) { grades[week] = grade; }
};
class TimeSlot {
private:
string day;
const unsigned hour;
public:
TimeSlot(string dayOfTheWeek, const unsigned hourOfTheDay) : day(dayOfTheWeek), hour(hourOfTheDay) {}
void displayTimeSlot()const;
};
class Section {
private:
const TimeSlot slot;
const string& name;
vector<Student*> students;
public:
Section(const string& dayOfTheWeek, const string& sectionName,const unsigned hourOfTheDay) : name(sectionName), slot(dayOfTheWeek,hourOfTheDay) {}
void reset() {
for (size_t i = 0; i < students.size(); i++) {
delete students[i];
}
students.clear();
}
void addStudent(const string& studentName){
Student* studentPtr = new Student(studentName);
students.push_back(studentPtr);
}
void display()const {
cout << "Section:" << name << "; ";
slot.displayTimeSlot();
for (size_t i = 0; i < students.size(); i++) {
students[i]->displayStudent();
}
}
void addGrade(const string& studentName, const int& week, const int& grade) {
for (size_t i = 0; i < students.size(); ++i) {
if (students[i]->getName() == studentName) {
students[i]->setGrade(week, grade);
}
}
}
};
class LabWorker {
private:
const string name;
const Section* labSection;
public:
LabWorker(const string& workerName) : name(workerName) {}
void addGrade(const string& studentName, const int& grade, const int& week) {
labSection->addGrade(studentName, grade, week);
}
void addSection(Section& newSection) {
labSection = &newSection;
}
void displayGrades()const {
labSection->display();
}
};
void TimeSlot::displayTimeSlot()const {
cout << " " << day << " " << hour << endl;
}
int main() {
// lab workers
LabWorker moe("Moe");
LabWorker jane("Jane");
// sections and setup and testing
Section secA2("A2", "Tuesday", 16);
//secA2.loadStudentsFromFile( "A2.txt" );
secA2.addStudent("John");
secA2.addStudent("George");
secA2.addStudent("Paul");
secA2.addStudent("Ringo");
cout << "\ntest A2\n"; // here the modeler-programmer checks that load worked
secA2.display(); // YOU'll DO THIS LATER AS: cout << secA2 << endl;
moe.addSection(secA2);
moe.displayGrades(); // here the modeler-programmer checks that adding the Section worked
Section secB3("B3", "Thursday", 11);
//secB3.loadStudentsFromFile( "B3.txt" );
secB3.addStudent("Thorin");
secB3.addStudent("Dwalin");
secB3.addStudent("Balin");
secB3.addStudent("Kili");
secB3.addStudent("Fili");
secB3.addStudent("Dori");
secB3.addStudent("Nori");
secB3.addStudent("Ori");
secB3.addStudent("Oin");
secB3.addStudent("Gloin");
secB3.addStudent("Bifur");
secB3.addStudent("Bofur");
secB3.addStudent("Bombur");
cout << "\ntest B3\n"; // here the modeler-programmer checks that load worked
secB3.display(); // YOU'll DO THIS LATER AS: cout << secB3 << endl;
jane.addSection(secB3);
jane.displayGrades(); // here the modeler-programmer checks that adding Instructor worked
// setup is complete, now a real world scenario can be written in the code
// [NOTE: the modeler-programmer is only modeling joe's actions for the rest of the program]
// week one activities
cout << "\nModeling week: 1\n";
moe.addGrade("John", 7, 1);
moe.addGrade("Paul", 9, 1);
moe.addGrade("George", 7, 1);
moe.addGrade("Ringo", 7, 1);
cout << "End of week one\n";
moe.displayGrades();
// week two activities
cout << "\nModeling week: 2\n";
moe.addGrade("John", 5, 2);
moe.addGrade("Paul", 10, 2);
moe.addGrade("Ringo", 0, 2);
cout << "End of week two\n";
moe.displayGrades();
//test that reset works // NOTE: can we check that the heap data was dealt with?
cout << "\ntesting reset()\n";
secA2.reset();
secA2.display();
moe.displayGrades();
} // main