-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSchool.cpp
More file actions
273 lines (183 loc) Β· 5.1 KB
/
School.cpp
File metadata and controls
273 lines (183 loc) Β· 5.1 KB
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
///////////////////////////
// Implementation of School
///////////////////////////
// Include header file
#include "School.h"
// Person Functions
Person::~Person() {
cout << "A Person to be destroyed!" << endl;
}
void Person::print(void) const {
cout << this->name << " " << this->tired << endl;
}
// Teacher Functions
Teacher::~Teacher() {
cout << "A Teacher to be destroyed!" << endl;
}
void Teacher::teach(int N, int Lt) {
// Add hours * Lt
this->tired += (N * Lt);
}
void Teacher::print(void) const {
cout << "The teacher is: ";
Person::print();
}
// Student Functions
Student::~Student() {
cout << "A Student to be destroyed!" << endl;
}
// Junior Functions
Junior::~Junior() {
cout << "A Junior to be destroyed!" << endl;
}
void Junior::attend(int N, int L) {
// Add hours * Lj
this->tired += (N * L);
}
// Senior Functions
Senior::~Senior() {
cout << "A Senior to be destroyed!" << endl;
}
void Senior::attend(int N, int L) {
// Add hours * Ls
this->tired += (N * L);
}
// Room Functions
Room::~Room() {
cout << "A Room to be destroyed!" << endl;
}
// School Functions
School::~School() {
// Delete memore allocated
delete yard;
delete stairs;
for (int i=0 ; i<3 ; i++) delete floors[i];
cout << "A School to be destroyed!" << endl;
}
void School::enter(Student* s) {
cout << s->get_name() << " enters school!" << endl;
// When Student enters school,
// he goes all the way to his Class
yard->enter(s);
s = yard->exit();
stairs->enter(s);
s = stairs->exit();
floors[s->get_flo()]->enter(s);
}
void School::place(Teacher* t) {
// Teacher is just placed in his Class
this->floors[t->get_flo()]->place(t);
}
void School::operate(int N) const {
// Calling operate for each floor
for (int i=0 ; i<3 ; i++) floors[i]->operate(N, Lj, Ls, Lt);
}
void School::print(void) const {
cout << "School life consists of:" << endl;
for (int i=0 ; i<3 ; i++) floors[i]->print();
}
// Yard Functions
Yard::~Yard() {
cout << "A Schoolyard to be destroyed!" << endl;
}
void Yard::enter(Student* s) {
// Temporary save Student
this->student = s;
cout << s->get_name() << " enters schoolyard!" << endl;
}
Student* Yard::exit(void) {
// Return Student
cout << this->student->get_name() << " exits schoolyard!" << endl;
return student;
}
// Stairs Functions
Stairs::~Stairs() {
cout << "A Stairs to be destroyed!" << endl;
}
void Stairs::enter(Student* s) {
// Temporary save Student
this->student = s;
cout << s->get_name() << " enters stairs!" << endl;
}
Student* Stairs::exit(void) {
// Return Student
cout << this->student->get_name() << " exits stairs!" << endl;
return student;
}
// Floor Functions
Floor::~Floor() {
for (int i=0 ; i<6 ; i++) delete classes[i];
delete corridor;
cout << "A Floor to be destroyed!" << endl;
}
void Floor::enter(Student* s) {
cout << s->get_name() << " enters floor!" << endl;
// Continue the way of Student to Class
corridor->enter(s);
s = corridor->exit();
classes[s->get_cls()]->enter(s);
}
void Floor::place(Teacher* t) {
// Teacher is placed
this->classes[t->get_cls()]->place(t);
}
void Floor::operate(int N, int Lj, int Ls, int Lt) const {
// Calling operate for each Class
for (int i=0 ; i<6 ; i++) {
classes[i]->operate(N, Lj, Ls, Lt);
}
}
void Floor::print(void) const {
cout << "Floor number " << no << " contains:" << endl;
for (int i=0; i<6 ; i++) classes[i]->print();
}
// Corridor Functions
Corridor::~Corridor() {
cout << "A Corridor to be destroyed!" << endl;
}
void Corridor::enter(Student* s) {
// Temporary save Student
this->student = s;
cout << s->get_name() << " enters corridor!" << endl;
}
Student* Corridor::exit(void) {
// Return Student
cout << this->student->get_name() << " exits corridor!" << endl;
return student;
}
// Classroom Functions
Classroom::~Classroom() {
cout << "A Class to be destroyed!" << endl;
delete[] this->students;
}
void Classroom::enter(Student* s) {
// If classroom is full
if (size >= Cclass) return;
// Add Student to students
// and set him in Classroom
s->set_cls();
this->students[size++] = s;
cout << s->get_name() << " enters classroom!" << endl;
}
void Classroom::place(Teacher* t) {
this->teacher = t;
// Change teacher's inside bool
t->get_in();
cout << t->get_name() << " places in classroom!" << endl;
}
void Classroom::operate(int N, int Lj, int Ls, int Lt) const {
if (teacher != NULL) this->teacher->teach(N, Lt);
for (int i=0 ; i<size ; i++) {
// If Student is Junior
if (students[i]->get_cls() < 3) students[i]->attend(N, Lj);
// If Student is Senior
else students[i]->attend(N, Ls);
}
}
void Classroom::print(void) const {
cout << "People in class " << no << " are:" << endl;
// For all students in Classroom
for (int i=0 ; i<size ; i++) students[i]->print();
// If teacher is in Classroom
if (teacher != NULL) teacher->print();
}