-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
127 lines (92 loc) Β· 2.69 KB
/
main.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
///////////////////////////////
// Main function to test School
///////////////////////////////
// Include header file
#include "School.h"
int main(int argc, char* argv[]) {
// Get parameters
int Cclass = atoi(argv[1]);
int Lj = atoi(argv[2]);
int Ls = atoi(argv[3]);
int Lt = atoi(argv[4]);
int N = atoi(argv[5]);
// Create School
School school(Lj, Ls, Lt, Cclass);
// Create Students and Teachers
int size_stud = Cclass * 3 * 6;
Student** students = new Student*[size_stud];
int nf=0;
for (int i=0 ; i<size_stud ; i++) {
if (i % 6 == 0 && i != 0) nf++;
// Converting int to string
// Could use to_string, but not available in c++98
ostringstream str1;
str1 << i;
string temp = str1.str();
if (i%6 < 3) students[i] = new Junior("Junior_name" + temp, nf%3, i%6);
else students[i] = new Senior("Senior_name" + temp, nf%3, i%6);
}
int size_teacher = 3 * 6;
Teacher** teachers = new Teacher*[size_teacher];
nf = 0;
for (int i=0 ; i<size_teacher ; i++) {
if (i % 6 == 0 && i != 0) nf++;
// Converting int to string
// Could use to_string, but not available in c++98
ostringstream str1;
str1 << i;
string temp = str1.str();
teachers[i] = new Teacher("Teacher_name" + temp, nf, i%6);
}
// Get students and teacher in the school
// with random order
srand(time(NULL));
int i=0, j=0;
bool stud; // True if we stopped in student
// While all students or all teachers enter school,
// pick one random to get in
while (true) {
if (rand() % 2 == 0) {
if (i >= size_stud) {
stud = false;
break;
}
school.enter(students[i]);
i++;
}
else {
if (j >= size_teacher) {
stud = true;
break;
}
school.place(teachers[j]);
j++;
}
}
// If there are students to enter school
if (stud) {
for (int k=i ; k<size_stud ; k++) {
school.enter(students[k]);
}
}
// If there are teachers to place in school
else {
for (int k=j ; k<size_teacher ; k++) {
school.place(teachers[k]);
}
}
// School should operate for N hours
school.operate(N);
// Print out school
school.print();
// Delete Students and Teachers
for (int i=0 ; i<size_stud ; i++) {
delete students[i];
}
delete[] students;
for (int i=0 ; i<size_teacher ; i++) {
delete teachers[i];
}
delete[] teachers;
return 0;
}