-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSchool.h
361 lines (254 loc) Β· 7.07 KB
/
School.h
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/////////////////////////
// Header file for School
/////////////////////////
// Include libraries
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
// Include only for convert int to string
#include <sstream>
using namespace std;
//////////
// Classes
// Person
class Person {
string name; // Person's name
int no_flo; // Floor's number
int no_cls; // Class's number
protected:
bool in_cls; // True if in class
int tired; // Counter for tiredness
public:
// Constructor
Person(string name, int nf, int nc): name(name), no_flo(nf), no_cls(nc), in_cls(false), tired(0) {
cout << "A New Person has been created!" << endl;
}
// Destructor
virtual ~Person();
// Print function
virtual void print(void) const = 0;
// Get name
string get_name(void) const { return this->name; }
// Get no_flo
int get_flo(void) const { return this->no_flo; }
// Get no_cls
int get_cls(void) const { return this->no_cls; }
// Get in_cls
bool get_in(void) const { return this->in_cls; }
// Get tired
int get_tired(void) const { return this->tired; }
// Set in_cls
void set_cls(void) { this->in_cls = true; }
};
// Teacher
class Teacher: public Person {
public:
// Constructor
Teacher(string name, int nf, int nc): Person(name, nf, nc) {
cout << "A New Teacher has been created!" << endl;
}
// Destructor
~Teacher();
// Copy Constructor
Teacher(const Teacher& t): Person(t.get_name(), t.get_flo(), t.get_cls()) {
cout << "A New Teacher copied!" << endl;
}
// Teach teacher
void teach(int N, int Lt);
// Print Teacher
void print(void) const;
};
// Student
class Student: public Person {
public:
// Constructor
Student(string name, int nf, int nc): Person(name, nf, nc) {
cout << "A New Student has been created!" << endl;
}
// Destructor
virtual ~Student();
// Attend student
virtual void attend(int N, int L) = 0;
// Print Student
virtual void print(void) const = 0;
};
// Junior
class Junior: public Student {
public:
// Constructor
Junior(string name, int nf, int nc): Student(name, nf, nc) {
cout << "A New Junior has been created!" << endl;
}
// Destructor
~Junior();
// Copy Constructor
Junior(const Junior& j): Student(j.get_name(), j.get_flo(), j.get_cls()) {
cout << "A Junior has been copied!" << endl;
}
// Attend Junior
void attend(int N, int L);
// Print Junior
void print(void) const { Person::print(); }
};
// Senior
class Senior: public Student {
public:
// Constructor
Senior(string name, int nf, int nc): Student(name, nf, nc) {
cout << "A New Senior has been created!" << endl;
}
// Destructor
~Senior();
// Copy Constructor
Senior(const Senior& s): Student(s.get_name(), s.get_flo(), s.get_cls()) {
cout << "A New Senior has been copied!" << endl;
}
// Attend Senior
void attend(int N, int L);
// Print Senior
void print(void) const { Person::print(); }
};
// Room
class Room {
protected:
Student* student; // Keep student when enters Room
public:
// Constructor
Room() {
cout << "A New Room has been created!" << endl;
}
// Destructor
virtual ~Room();
// Enter student in room
virtual void enter(Student* s) = 0;
// Exit student from room
virtual Student* exit(void) = 0;
};
// Yard
class Yard: public Room {
public:
// Constructor
Yard(): Room() {
cout << "A New Yard has been created!" << endl;
}
// Destructor
~Yard();
// Enter student in yard
void enter(Student* s);
// Exit student from yard
Student* exit(void);
};
// Stairs
class Stairs: public Room {
public:
// Constructor
Stairs(): Room() {
cout << "A New Stairs has been created!" << endl;
}
// Destructor
~Stairs();
// Enter student in stairs
void enter(Student* s);
// Exit student from stairs
Student* exit(void);
};
// Corridor
class Corridor: public Room {
public:
// Constructor
Corridor(): Room() {
cout << "A New Corridor has been created!" << endl;
}
// Destructor
~Corridor();
// Enter student in corridor
void enter(Student* s);
// Exit student from corridor
Student* exit(void);
};
// Classroom
class Classroom {
int no; // Number of Class
Teacher* teacher; // Teacher of Class
Student** students; // Students of Class
int size; // How many students there are
int Cclass; // Capacity of Class
public:
// Constructor
Classroom(int no, int Cclass): no(no), size(0), Cclass(Cclass) {
cout << "A New Classroom has been created!" << endl;
students = new Student*[Cclass];
teacher = NULL;
}
// Destructor
~Classroom();
// Enter student in classroom
void enter(Student* s);
// Place teacher in classroom
void place(Teacher* t);
// Operate classroom
void operate(int N, int Lj, int Ls, int Lt) const;
// Get Cclass
int get_ccls(void) const { return this->Cclass; }
// Print
void print(void) const;
};
// Floor
class Floor {
int no; // Number of Floor
Classroom* classes[6]; // Classes
Corridor* corridor; // Corridor
public:
// Constructor
Floor(int no, int Cclass): no(no) {
cout << "A New Floor has been created!" << endl;
for (int i=0 ; i<6 ; i++) classes[i] = new Classroom(i, Cclass);
corridor = new Corridor();
}
// Destructor
~Floor();
// Enter student in floor
void enter(Student* s);
// Place teacher in floor
void place(Teacher* t);
// Operate floor
void operate(int N, int Lj, int Ls, int Lt) const;
// Get Cclass
int get_ccls(void) const { return this->classes[0]->get_ccls(); }
// Print
void print(void) const;
};
// School
class School {
Floor* floors[3]; // Floors
Yard* yard; // Yard
Stairs* stairs; // Stairs
int Lj; // Units for Junior
int Ls; // Units for Senior
int Lt; // Units for Teacher
public:
// Constructor
School(int Lj, int Ls, int Lt, int Cclass): Lj(Lj), Ls(Ls), Lt(Lt) {
cout << "A New School has been created!" << endl;
yard = new Yard();
stairs = new Stairs();
for (int i=0 ; i<3 ; i++) floors[i] = new Floor(i, Cclass);
}
// Destructor
~School();
// Copy constructor
School(School& s): Lj(s.Lj), Ls(s.Ls), Lt(s.Lt) {
yard = new Yard();
stairs = new Stairs();
for (int i=0 ; i<3 ; i++) floors[i] = new Floor(i, s.floors[0]->get_ccls());
}
// Enter student in school
void enter(Student* s);
// Place teacher in school
void place(Teacher* t);
// Operate school
void operate(int N) const;
// Print
void print(void) const;
};