-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOffice.cpp
More file actions
195 lines (164 loc) · 4.93 KB
/
Office.cpp
File metadata and controls
195 lines (164 loc) · 4.93 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
#include "Office.h"
Office::Office(char name, int numWindows) {
deleteThisToo = 0;
queue = new Queue<Customer*>();
windows = new Window*[numWindows];
// create new windows for length of windows
for (int i = 0; i < numWindows; ++i) {
Window *w = new Window();
windows[i] = w;
}
officeName = name;
this->numWindows = numWindows;
// set all aux variables to 0
totalWaitTime = 0;
totalVisitors = 0;
longestWaitTime = 0;
visitsOver10 = 0;
timeCounter = 0;
}
Office::Office(){}
Office::~Office() {
delete queue;
for(int i = 0; i < numWindows; ++i){
delete windows[i];
}
delete[] windows;
}
void Office::timeIncrement() {
++timeCounter;
// check if any windows are open
int openWindow = firstEmptyWindow();
while ((openWindow != -1) && (!(queue->isEmpty()))) {
// send the student to an open window
sendStudentToWindow(openWindow);
// set to next variable
openWindow = firstEmptyWindow();
}
for(int i = 0; i < numWindows; ++i){
// increments window time
windows[i]->timeIncrement();
}
addToWaitTime();
}
void Office::addStudentToQueue(Customer* s) {
if(s->notDone()){
// updates student office
s->setCurrentOffice(officeName);
s->enterQueue(timeCounter);
queue->insert(s);
totalVisitors++;
}
}
int Office::getNumWindows() {
return numWindows;
}
int Office::getTotalWaitTime() {
return totalWaitTime;
}
int Office::getTotalVisitors() {
return totalVisitors;
}
double Office::getMeanWaitTime() {
// gets mean wait time by dividing total by visitors
if(totalVisitors == 0){
return 0;
}
return ((double) totalWaitTime / (double) totalVisitors);
}
int Office::getLongestWaitTime() {
return longestWaitTime;
}
int Office::getVisitsOver10() {
return visitsOver10;
}
double Office::getMeanIdleTime() { // gets the mean idle time from all windows' total idle times
int totalIdleTime = 0;
for (int i = 0; i < numWindows; ++i) {
// add idle time of window to total
totalIdleTime += windows[i]->getTotalIdleTime();
}
return ((double) totalIdleTime / (double) numWindows);
}
int Office::getLongestIdleTime() { // gets the longest idle time amongst all windows
int maxIdleTime = 0;
for (int i = 0; i < numWindows; ++i) {
// if the max idle time is greater, replace the old one
int currIdleTime = windows[i]->getTotalIdleTime();
if (currIdleTime > maxIdleTime) maxIdleTime = currIdleTime;
}
return maxIdleTime;
}
int Office::getTotalIdleOver5() { // returns the total number of windows with idles over 5
int counter = 0;
for (int i = 0; i < numWindows; ++i) {
// add idle time of window to total
counter += windows[i]->getNumIdlesOver5();
}
return counter;
}
int Office::firstEmptyWindow() {
/* iterate through all windows return
- Return index of the first empty window
- Else return -1
*/
for (int i = 0; i < numWindows; ++i) {
if (windows[i]->isEmpty()){
return i;
}
}
return -1;
}
void Office::sendStudentToWindow(int windowNum) {
// removes a student from the queue and sends them to the first available window
if(queue->peek()->exitQueue(timeCounter) > longestWaitTime){
longestWaitTime = queue->peek()->exitQueue(timeCounter) - 1;
}
windows[windowNum]->approachWindow(queue->remove());
}
void Office::addToWaitTime() {
// get number of students in the array
// ex: if there are 3 students in line and 1 time has passed, then a total of 3 wait time has happened
totalWaitTime += queue->getSize();
}
void Office::prepStudentForQueue(Customer *c){ //adds student to the array and increases index
queuePrep[queuePrepIndex] = c;
++queuePrepIndex;
}
void Office::makeQueuePrepArray(int sn){ //makes an array based on number of students
queuePrep = new Customer*[sn];
queuePrepIndex = 0;
}
void Office::addQueueFromOtherOffice(){ //This method is for when a student finishes and needs to be added to another queue when
for(int i = 0; i < queuePrepIndex; ++i){
if(queuePrep[i] == NULL){
break;
}
if(queuePrep[i]->getPrevOffice() == 'C'){
addStudentToQueue(queuePrep[i]);
}
}
for(int i = 0; i < queuePrepIndex; ++i){
if(queuePrep[i] == NULL){
break;
}
if(queuePrep[i]->getPrevOffice() == 'F'){
addStudentToQueue(queuePrep[i]);
}
}
for(int i = 0; i < queuePrepIndex; ++i){
if(queuePrep[i] == NULL){
break;
}
if(queuePrep[i]->getPrevOffice() == 'R'){
addStudentToQueue(queuePrep[i]);
}
}
for(int i = 0; i < queuePrepIndex; ++i){
if(queuePrep[i] == NULL){
break;
}
queuePrep[i] == NULL;
}
queuePrepIndex = 0;
}