-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApplication.cpp
418 lines (368 loc) · 7.95 KB
/
Application.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
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
#pragma once
#include "Application.h"
Application::Application()
{
m_Command = 0;
OpenTime = 0;
CloseTime = 0;
Day = 0;
isOpen = false;
}
void Application::run()
{
int temp;
intro.title();
cout << "\t계속하시려면 아무것이나 입력해주세요 -";
while (true)
{
if (getKey()) break;
}
system("cls");
while (true) {
if (isOpen)
{
Day++;
open();
}
else
{
close();
}
}
}
void Application::open()
{
m_Command = 0;
int tick = 0, num = 1;
cout << "\n\t한 번에 추가할 유저 수를 입력해주세요 : ";
while (true)
{
cin >> num;
if (num <= 0)
{
cout << "\n\t한 번에 추가할 유저 수를 입력해주세요 : ";
continue;
}
if (num >= 1) break;
}
admin.setMaxUser(num * 100);
admin.setRun();
while (true) {
if (m_Command == -1) break;
tick++;
switch (m_Command)
{
case 1:
searchRide();
break;
case 2:
searchAllUser();
break;
default:
printLive(tick);
break;
}
for(int i = 0; i < num; i++) admin.newUser();
admin.run(tick);
Sleep(900);
m_Command = getKey();
}
isOpen = false;
admin.runDelete();
if(m_Command==-1)
system("CLS");
return;
}
int Application::getKey()
{
if (_kbhit()) {
int nKey = _getch();
switch (nKey)
{
case 'p':
return -1;
case 's':
return 1;
case 'u':
return 2;
default:
return 100;
}
}
return 0;
}
void Application::printLive(int tick)
{
// ID, 대기인원, 대기시간? 이거만 있음될듯
// 이 함수랑
system("CLS");
cout << "\n\t --------" << Day << "th Day Opened--------"<<endl;
DoublyIterator<Ride> itor( *(admin.rideListPointer()) );
cout << "\t현재 시간 - " << clock(tick) << "\n\t놀이기구 갯수 - " << admin.getRideLength()
<<"\n\t입장인원 수 - " << admin.getNumOfEnterUser();
itor.Next();
cout << "\n\n" << setw(25) << "놀이기구 목록" << setw(10) << "대기인원";
while (itor.NextNotNull())
{
liveInfo live = itor.GetCurrentNodePointer()->data.getLiveInfo();
cout << "\n" << setw(25) << live.info;
cout << setw(10) << live.numWatingUser;
cout << '\t';
for (int j = 0; j < live.watingtime; j++) {
cout << "■";
if (j > 25) {
cout << "...";
break;
}
}
itor.Next();
}
cout << '\n';
cout << "\n\n\t" << "- 중단하기(p)" << "\n\t" << "- 놀이기구 상세 정보 검색(s)" << "\n\t" << "- 유저 상세 정보 검색(u)" "\n\t-->";
}
string Application::clock(int tick)
{
string temp = "";
int hour = tick / 60;
int min = tick % 60;
if (hour == 0) temp += "00:";
else if (hour < 10) temp += "0" + to_string(hour) + ":";
else temp += to_string(hour) + ":";
if (min < 10) temp += "0" + to_string(min);
else temp += to_string(min);
return temp;
}
void Application::close()
{
while (true) {
getCloseCommand();
switch (m_Command)
{
case 1:
printTodayInfo();
break;
case 2:
printAllRideInfo();
break;
case 3:
searchRide();
break;
case 4:
addRide();
break;
case 5:
updateRide();
break;
case 6:
deleteRide();
break;
case 7:
writeRideListToFile();
break;
case 8:
ReadRideListFromFile();
break;
case 9:
isOpen = true;
return;
case 0:
exit(100);
default:
cout << "\n\t입력 오류입니다. 다시 입력해주세요.";
break;
}
}
}
bool Application::getCloseCommand()
{
cout << "\n\t --------" << Day << "th Day Closed --------";
cout << "\n\t폐장 상태";
cout << "\n\t1. 놀이공원 통계 보기";
cout << "\n\t2. 전체 놀이기구 정보 보기";
cout << "\n\t3. 상세 놀이기구 정보 보기";
cout << "\n\t4. 놀이기구 추가 하기";
cout << "\n\t5. 놀이기구 수정 하기";
cout << "\n\t6. 놀이기구 삭제 하기";
cout << "\n\t7. 놀이기구 파일 쓰기";
cout << "\n\t8. 놀이기구 파일 읽기";
cout << "\n\t9. 개장하기";
cout << "\n\t0. 프로그램 종료";
cout << "\n\t->";
cin.clear();
cin >> m_Command;
return true;
}
bool Application::getOpenCommand()
{
cout << "\n\t안녕";
return true;
}
bool Application::isItOpen() const
{
return isOpen;
}
bool Application::searchAllUser()
{
int num = admin.getNumOfEnterUser();
int id;
if (num == 0)
{
cout << "\n\t유저가 존재하지 않습니다. 자동으로 돌아갑니다.";
Sleep(500);
return false;
}
while (true) {
cout << "\n\t현재 유저는 0~" << num- 1<< "까지 입니다.";
cout << "\n\t검색하고 싶은 유저 번호를 입력하세요(input -7 to exit)-->";
cin >> id;
if ( (id >= 0 && id < num) || id == -7) { break; }
cout << "\n\t잘못된 입력입니다.";
}
if ((id >= 0 && id < num))
{
User searchedUser = admin.searchUser(id);
searchedUser.printInfo();
cout << "\n\t나가시려면 p를 눌러주세요";
while (true)
{
if (getKey() == -1) break;
Sleep(500);
}
}
m_Command = 0;
return true;
}
void Application::printAllRideInfo()
{
admin.PrintRideAll();
}
bool Application::searchRide()
{
int num = admin.getRideLength();
int id;
if (num == 0)
{
cout << "\n\t놀이기구가 존재하지 않습니다. 자동으로 돌아갑니다.";
Sleep(500);
return false;
}
while (true) {
cout << "\n\t현재 놀이기구는 0~" << num-1 << "까지 입니다.";
cout << "\n\t검색하고 싶은 놀이기구 번호를 입력하세요(input -7 to exit)-->";
cin >> id;
if ((id >= 0 && id < num) || id == -7) { break; }
cout << "\n\t잘못된 입력입니다.";
}
if ((id >= 0 && id < num))
{
Ride searchedRide = admin.searchRide(id);
searchedRide.printInfo();
cout << "\n\t나가시려면 p를 눌러주세요";
while (true)
{
if (getKey() == -1) break;
Sleep(500);
}
}
m_Command = 0;
return true;
}
bool Application::addRide()
{
Ride* addingRide=new Ride;
addingRide->setAllFromKB();
admin.insertRide(*addingRide);
return true;
}
bool Application::deleteRide()
{
int id;
int num = admin.getRideLength();
if (num == 0)
{
cout << "\n\t놀이기구가 존재하지 않습니다. 자동으로 돌아갑니다.";
Sleep(500);
return false;
}
while (true) {
cout << "\n\t현재 놀이기구는 0~" << num -1<< "까지 입니다.";
cout << "\n\t삭제하고 싶은 놀이기구 번호를 입력하세요-->";
cin >> id;
if (id >= 0 && id < num) { break; }
cout << "\n\t잘못된 입력입니다.";
}
if (id >= 0 && id < num)
{
if (admin.removeRide(id))
{
cout << "\n\t삭제에 성공했습니다.";
return true;
}
cout << "\n\t삭제에 실패했습니다.";
}
return false;
}
bool Application::updateRide()
{
int id;
int num = admin.getRideLength();
if (num == 0)
{
cout << "\n\t놀이기구가 존재하지 않습니다. 자동으로 돌아갑니다.";
Sleep(500);
return false;
}
while (true) {
cout << "\n\t현재 놀이기구는 0~" << num - 1 << "까지 입니다.";
cout << "\n\t수정하고 싶은 놀이기구 번호를 입력하세요-->";
cin >> id;
if (id >= 0 && id < num) { break; }
cout << "\n\t잘못된 입력입니다.";
}
if (id >= 0 && id < num)
{
Ride* addingRide = new Ride;
addingRide->setAllFromKB();
addingRide->setId(id);
addingRide->setRideListPointer(admin.rideListPointer());
admin.rideListPointer()->Replace(*addingRide);
cout << "\n\t수정에 성공했습니다.";
return true;
cout << "\n\t수정에 실패했습니다.";
}
return false;
}
void Application::printTodayInfo() {
DoublySortedLinkedList<Ride>* rideList = admin.rideListPointer();
Ride cur;
liveInfo print;
int mostRide = 0;
int worstRide = 0;
int mostScore = 0;
double worstScore = 0;
cout << "\n\t --------" << Day << "th Day Summary --------";
for (int i = 0; i < rideList->GetLength(); i++) {
cur.setId(i);
rideList->Get(cur);
print = cur.printStat();
cout << "\n\tid : " << print.info;
cout << "\n\ttotal User : " << print.totalUser;
cout << "\n\tMax waitingtime : " << print.watingtime;
cout << "\n\tMax waitingUser number : " << print.numWatingUser << '\n';
//plus
if (Day >= 1) {
int score1 = print.numWatingUser + print.totalUser*2;
mostRide = (score1 > mostScore ? cur.getId() : mostRide);
mostScore = (score1 > mostScore ? score1 : mostScore);
if (print.totalUser != 0) {
double score2 = (double)print.watingtime / (double)print.totalUser;
worstRide = (score2 > worstScore ? cur.getId() : worstRide);
worstScore = (score2 > worstScore ? score2 : worstScore);
}
}
}
if (Day >= 1) {
cout << "\n\t- most Popular Ride( totalUser*2 + watingUser ) is Id " << mostRide;
cout << "\n\t- worst Ride( waitingtime / totalUser ) is Id " << worstRide << endl;
}
}