-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUI.cpp
More file actions
383 lines (326 loc) · 7.45 KB
/
UI.cpp
File metadata and controls
383 lines (326 loc) · 7.45 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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#include "UI.h"
#include "iomanip"
using namespace std;
////////////////////////INPUT//////////////////////////////////////////
void UI::ReadRoversNumbers(ifstream& Input, int& P, int& E)
{
Input >> P >> E;
}
int UI::ReadRoverSpeeds(ifstream& Input)
{
int speed;
Input >> speed;
return speed;
}
void UI::Read_N_CheckupDur(ifstream& Input, int& N, int& CP, int& CE)
{
Input >> N;
Input >> CP >> CE;
}
int UI::Read_MaintDur(ifstream& Input)
{
int MainDur;
Input >> MainDur;
return MainDur;
}
int UI::Read_EventsNum(ifstream& Input)
{
int n;
Input >> n;
return n;
}
char UI::ReadEventsTyp(ifstream& Input)
{
char Typ;
Input >> Typ;
return Typ;
}
void UI::Read_Formulation(ifstream& Input, char& Rover_Typ, int& ED, int& ID, int& TLOC, int& MDUR, int& SIG)
{
Input >> Rover_Typ >> ED >> ID >> TLOC >> MDUR >> SIG;
}
//From Console
void UI::ReadUserChoice(int& choice)
{
cout << "Please select the program mode, 1 for Interactive Mode, 2 for Step-by-step Mode and 3 for Silent Mode:";
cin >> choice;
}
///////////////////////OUTPUT//////////////////////////////////////////
///1- To File:
void UI::WriteEachDay(int CD, int ID, int FD, int WD, int ED, ofstream& Output)
{
Output << left << setw(5) << CD << setw(5) << ID << setw(5) << FD << setw(5) << WD << setw(5) << ED << endl;
}
void UI::WriteHeader(ofstream& Output)
{
Output.clear();
Output << "CD" << " " << "ID" << " " << "FD" << " " << "WD" << " " << "ED" << endl;
}
void UI::WriteMissions(int E_Mission, int P_Mission, ofstream& Output) {
Output << "Missions:" << " " << E_Mission + P_Mission << " " << "[P:" << " " << P_Mission << "," << "" << "E:" << " " << E_Mission << "]" << endl;
}
void UI::WriteRovers(int E_Rover, int P_Rover, ofstream& Output) {
Output << "Rovers:" << " " << E_Rover + P_Rover << " " << "[P:" << " " << P_Rover << "," << "" << "E:" << " " << E_Rover << "]" << endl;
}
void UI::WriteStats(float Avg_Wait, float Avg_Exec, ofstream& Output)
{
Output << "Avg Wait = " << Avg_Wait << "," << " " << "Avg Exec = " << Avg_Exec << endl;
Output.close();
}
void UI::WritePRoversWarning(ofstream& Output)
{
Output << "There were no Polar Rovers, so no polar missions were formulated or executed! " <<endl;
}
void UI::WriteNoMissionsWarning(ofstream& Output)
{
Output << "There were no missions." << endl;
}
void UI::WriteCriticalWarning(ofstream& Output)
{
Output << "There were no Polar or Emergency Rovers, so simulation did not start! :D " << endl;
cout << "There were no Polar or Emergency Rovers, so simulation did not start! :D ";
}
void UI::WriteProbabilityWarning(ofstream& Output)
{
Output << "The Probability of Failure is 100, so simulation did not start!" << endl;
cout << "The Probability of Failure is 100, so simulation did not start!" << endl;
}
///2- To Console:
//Prints the data in their respective format
void UI::PrintEmergency(int* E, int count)
{
if (count == 0)
return;
cout << " " << "[";
for (int i = 0; i < count; i++)
{
if (i == count - 1)
{
cout << E[i] << "]";
}
else
{
cout << E[i] << ",";
}
}
}
void UI::PrintPolar(int* P, int count)
{
if (count == 0)
return;
cout << " " << "(";
for (int i = 0; i < count; i++)
{
if (i == count - 1)
{
cout << P[i] << ")";
}
else
{
cout << P[i] << ",";
}
}
}
//Prints in-EXECUTION M/R
void UI::PrintMissionsAndRovers(int* M, int* R, int count, int* F, int Fcount, char type)
{
if (count == 0 && Fcount == 0)
return;
cout << " ";
if (type == 'E')
cout << "[";
else cout << "(";
if (count == 0)
{
for (int i = 0; i < Fcount; i++)
{
if (i == Fcount - 1)
{
cout << 'X' << "/" << F[i];
if (type == 'E')
cout << "]";
else cout << ")";
}
else
{
cout << 'X' << "/" << F[i] << ",";
}
}
}
else if (Fcount == 0)
{
for (int i = 0; i < count; i++)
{
if (i == count - 1)
{
cout << M[i] << "/" << R[i];
if (type == 'E')
cout << "]";
else cout << ")";
}
else
{
cout << M[i] << "/" << R[i] << ",";
}
}
}
else
{
for (int i = 0; i < Fcount; i++)
{
cout << 'X' << "/" << F[i] << ",";
}
for (int i = 0; i < count; i++)
{
if (i == count - 1)
{
cout << M[i] << "/" << R[i];
if (type == 'E')
cout << "]";
else cout << ")";
}
else
{
cout << M[i] << "/" << R[i] << ",";
}
}
}
}
void UI::PrintBreakLine()
{
cout << endl;
for (int i = 0; i < 40; i++)
{
cout << "-";
}
cout << endl;
}
//Since the InExecution Missions and Rovers are each in 2 PQ's
//where each PQ contain All the types (M,P,E)
//then we have to classify them first before doing the operation
//Assume that M[] , R[] are arrays that are filled blindly with all ID's irrespective of the types
void UI::PrintInExecution(int* M, int* R, int count, int cE, int cP, char* type, int* F, int FCount, int FP, int FE, char* FType)
{
int* EM = new int[cE]; int* ER = new int[cE]; int c1 = 0;
int* PM = new int[cP]; int* PR = new int[cP]; int c3 = 0;
int* PF = new int[FP]; int* EF = new int[FE]; int c4 = 0; int c2 = 0;
for (int i = 0; i < FCount; i++)
{
if (FType[i] == 'P')
{
PF[c4] = F[i];
c4++;
}
else
{
EF[c2] = F[i];
c2++;
}
}
for (int i = 0; i < count; i++)
{
if (type[i] == 'E')
{
EM[c1] = M[i];
ER[c1] = R[i];
c1++;
}
else
{
PM[c3] = M[i];
PR[c3] = R[i];
c3++;
}
}
PrintMissionsAndRovers(EM, ER, cE, EF, FE, 'E');
PrintMissionsAndRovers(PM, PR, cP, PF, FP, 'P');
delete[] EM;
delete[] ER;
delete[] PM;
delete[] PR;
delete[] PF; //PF: Polar Failure
delete[] EF;
}
//Since we have met the case where we have both types in the same list
//then we have to classify each type first before doing the operation
//Assume that R[] is an array that is filled blindly with all ID's irrespective of the types.
void UI::PrintEmergencyAndPolar(int* R, int count, int cE, int cP, char* type)
{
int* ER = new int[cE]; int c1 = 0;
int* PR = new int[cP]; int c3 = 0;
for (int i = 0; i < count; i++)
{
if (type[i] == 'E')
{
ER[c1] = R[i];
c1++;
}
else
{
PR[c3] = R[i];
c3++;
}
}
PrintEmergency(ER, cE);
PrintPolar(PR, cP);
delete[] ER;
delete[] PR;
}
//Since making a function to print each day in the UI would require nearly 15 input
//to make the function in the master station we had to handle the statements printed to illustrate the output
//choice determines which statements should be printed
//x is the number printed in the statement(Current day, number of waiting missions, etc)
void UI::PrintStatements(int choice, int x)
{
switch (choice)
{
case 1:
cout <<endl<< "Current Day:" << x << endl;
break;
case 2:
cout << x << " " << "Waiting Missions:";
break;
case 3:
PrintBreakLine();
cout << x << " " << "In-Execution Missions/Rovers and Failed Missions' Rovers:";
cout << " ";
break;
case 4:
PrintBreakLine();
cout << x << " " << "Available Rovers:";
break;
case 5:
PrintBreakLine();
cout << x << " " << "In-Checkup Rovers:";
cout << " ";
break;
case 6:
PrintBreakLine();
cout << x << " " << "In-Maintainance Rovers:";
cout << " ";
break;
case 7:
PrintBreakLine();
cout << x << " " << "Completed Missions:";
break;
}
}
void UI::PrintFilenotFound()
{
cout << "File not found" << endl;
}
void UI::InteractiveMode()
{
system("pause");
}
void UI::StepByStepMode()
{
Sleep(1000);
}
//in silent mode you don't have to do the process at all
void UI::SilentMode()
{
cout << "Silent Mode" << endl;
cout << "Simulation Starts..." << endl;
cout << "Simulation ends, Output file created" << endl;
}