-
Notifications
You must be signed in to change notification settings - Fork 0
/
Project_Method.cpp
465 lines (409 loc) · 10.5 KB
/
Project_Method.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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
#include "Project.h"
void HospitalHandler::ShowMenu()
{
cout << "Menu------" << endl;
cout << "1. 환자" << endl;
cout << "2. 병원" << endl;
cout << "3. 관리자" << endl;
cout << "4. 종료" << endl;
}
void HospitalHandler::ShowPatientMenu()
{
cout << "환자------" << endl;
cout << "1. 환자등록" << endl;
cout << "2. 진료예약" << endl;
cout << "3. 환자검색" << endl;
cout << "4. 진료완료" << endl;
cout << "5. 뒤로가기" << endl;
}
void HospitalHandler::ShowHospitalMenu()
{
cout << "병원------" << endl;
cout << "1. 병원등록" << endl;
cout << "2. 병원검색" << endl;
cout << "3. 뒤로가기" << endl;
}
void HospitalHandler::ShowManagerMenu()
{
cout << "관리자------" << endl;
cout << "1. 전체 환자 출력" << endl;
cout << "2. 전체 병원 출력" << endl;
cout << "3. 통계 확인" << endl;
cout << "4. 뒤로가기" << endl;
}
void HospitalHandler::RegisterPatient()
{
char name[20], phone[20], abroad[20];
int prereser, hos_index, preabroad, Patdata;
string tmp;//
cout << "\n성명을 입력해 주세요(end : 입력 종료) : ";
cin >> name;
if (strcmp(name, "end") == 0) {
return;
}
cout << "전화번호(숫자만 입력해주세요) : ";
//cin >> phone;
cin >> tmp;
for (int i = 0; i < tmp.length(); i++) {
char c = tmp.at(i);
if (c < 48 || c> 57) {//숫자가 아닌 경우
cout << "잘못된 번호 형식입니다. 다시 입력해주세요" << endl;
cout << "메뉴로 돌아갑니다" << endl;
return;
}
}
if (tmp.size() != 11) {
cout << "잘못된 번호 형식입니다. 다시 입력해주세요" << endl;
cout << "메뉴로 돌아갑니다" << endl;
return;
}
tmp.insert(3, "-");
tmp.insert(8, "-");
strcpy(phone, tmp.c_str());
for (int i = 0; i < patNum; i++) {
if (strcmp(name, (*(patList[i])).getNames()) == 0) {
if (strcmp(phone, (*(patList[i])).getPhones()) == 0) {
cout << "";
cout << "======================================== \n";
cout << "이미 등록하신 환자입니다.\n";
cout << "======================================== \n";
cout << "";
return;
}
}
}
cout << "\n해외 입국자 이신가요? \n";
cout << "맞으면 0, 아니면 1을 입력해 주세요 : ";
cin >> preabroad;
if (preabroad == 0)
{
cout << "\n방문한 나라를 적어주세요: ";
cin >> abroad;
cout << "======================================== \n";
cout << "해외 환자로 등록이 완료되었습니다. \n";
cout << "추후 병원예약을 원할 시 환자 목록에서 [2.진료예약]으로 가주십시오.\n";
cout << "목록으로 돌아갑니다. \n";
cout << "======================================== \n";
cout << "\n";
expatListFile[expatNumFile] = patNum; //파일입출력 위한 배열에 추가
expatNumFile++;
patList[patNum] = new ExternalPatient(name, phone, abroad);
}
else
{
cout << "======================================== \n";
cout << "국내 환자로 등록이 완료되었습니다. \n";
cout << "추후 병원예약을 원할 시 환자 목록에서 [2.진료예약]으로 가주십시오.\n";
cout << "목록으로 돌아갑니다. \n";
cout << "======================================== \n";
cout << "\n";
inpatListFile[inpatNumFile] = patNum;
inpatNumFile++;
patList[patNum] = new InternalPatient(name, phone);
}
patNum++;
}
void HospitalHandler::FindPatient()
{
char name[20];
int sameName[5];
int num = 0;
int patTmp;
char yesnoTmp;
cout << "이름을 입력하시오 : ";
cin >> name;
for (int i = 0; i < patNum; i++) {
if (strcmp(name, (*(patList[i])).getNames()) == 0) {
sameName[num] = i;
num++;
}
}
if (num == 0) {
cout << name << ", Not found!!!" << endl;
}
else {
for (int i = 0; i < num; i++) {
(*(patList[sameName[i]])).showInfo();
}
}
}
void HospitalHandler::Reservation()
{
char name[20];
int num = 0; //해당 이름이 몇명인지 확인
int patTmp;
char yesnoTmp;
int sameName[5]; //동명이인 체크
cout << "이름을 입력하시오 : ";
cin >> name;
cout << endl;
for (int i = 0; i < patNum; i++) {
if (strcmp(name, (*(patList[i])).getNames()) == 0) {
sameName[num] = i;
num++;
}
}
if (num == 0) {
cout << name << ", Not found!!!" << endl;
}
else if (num == 1) {
(*(patList[sameName[0]])).showInfoRestrict();
cout << "본인이 맞으신가요? (y/n) ";
cin >> yesnoTmp;
if (yesnoTmp == 'y') {
ReservationHosSelect(0, sameName);
}
else {
cout << "다시 입력해주세요" << endl;
}
}
else {
cout << "같은 이름이 여러명 있습니다" << endl;
for (int i = 0; i < num; i++) {
cout << i << "번 : ";
(*(patList[sameName[i]])).showInfoRestrict();
}
cout << "본인에 해당하는 번호를 골라주세요 : ";
cin >> patTmp;
ReservationHosSelect(patTmp, sameName);
}
}
void HospitalHandler::ReservationHosSelect(int _patTmp, int* sameName)
{
int hosTmp;
int validTmp = 1; //유효한 병원번호인지 확인
if ((*(patList[sameName[_patTmp]])).getReser() == true) { //이미 예약한 사람인지 체크
cout << "이미 예약하셨습니다." << endl;
cout << "목록으로 돌아갑니다." << endl;
return;
}
for (int i = 0; i < hosNum; i++) {
cout << i << "번 - ";
(*(hosList[i])).showInfo();
}
while (validTmp) {
cout << "예약하실 병원번호를 골라주세요 : ";
cin >> hosTmp;
if (hosTmp >= 0 && hosTmp < hosNum) { //병원번호 오류처리
cout << (*(patList[sameName[_patTmp]])).getNames() << " - " << (*(hosList[hosTmp])).getName() << " : 예약되었습니다" << endl;
(*(patList[sameName[_patTmp]])).setReser(true);
(*(patList[sameName[_patTmp]])).setHosIndex(hosTmp);
(*(hosList[hosTmp])).plusPatNum();
validTmp = 0; //반복문 나감
}
else {
cout << "유효한 병원번호를 입력해주세요" << endl;
}
}
}
void HospitalHandler::BeTreated()
{
char name[20];
int num = 0;
int patTmp;
char yesnoTmp;
int sameName[5]; //동명이인 체크
bool reserTmp; //예약여부 확인
cout << "이름을 입력하시오 : ";
cin >> name;
for (int i = 0; i < patNum; i++) {
if (strcmp(name, (*(patList[i])).getNames()) == 0) {
sameName[num] = i;
num++;
}
}
if (num == 0) {
cout << name << ", Not found!!!" << endl;
}
else if (num == 1) {
(*(patList[sameName[0]])).showInfo();
cout << "본인이 맞으신가요? (y/n) ";
cin >> yesnoTmp;
if (yesnoTmp == 'y') {
reserTmp = BeTreatedNotReser(0, sameName); //예약했는지 확인
if (reserTmp == false) {
return;
}
BeTreatedResult(0, sameName);
}
else {
cout << "다시 입력해주세요" << endl;
}
}
else {
for (int i = 0; i < num; i++) {
cout << i << "번 : ";
(*(patList[sameName[i]])).showInfo();
}
cout << "본인에 해당하는 번호를 골라주세요 : ";
cin >> patTmp;
reserTmp = BeTreatedNotReser(patTmp, sameName);
if (reserTmp == false) {
return;
}
BeTreatedResult(patTmp, sameName);
}
}
bool HospitalHandler::BeTreatedNotReser(int _patTmp, int* sameName)
{
if ((*(patList[sameName[_patTmp]])).getReser() == false)
{
cout << "========================================" << endl;
cout << "예약을 하신분만 진료를 받을 수 있습니다." << endl;
cout << "========================================" << endl;
return false;
}
else
return true;
}
void HospitalHandler::BeTreatedResult(int _patTmp, int* sameName)
{
int cost;
int hosTmp;
hosTmp = (*(patList[sameName[_patTmp]])).getHosIndex();
cout << "결과를 확인중입니다." << endl;
random_device rd;
mt19937 gen(rd());
uniform_int_distribution<int> dist(0, 1);
int positive = dist(gen);
if (positive == 0) {
cout << "음성입니다." << endl;
cost = 10000 * ((*(patList[sameName[_patTmp]])).getDisRate());
cout << "진료비는 " << cost << "원 입니다" << endl;
}
else {
cout << "양성입니다." << endl;
(*(hosList[hosTmp])).plusInfectThisHos();
infectNum++;
cost = 30000 * ((*(patList[sameName[_patTmp]])).getDisRate());
cout << "진료비는 " << cost << "원 입니다" << endl;
}
(*(hosList[hosTmp])).minusPcrNum();
(*(hosList[hosTmp])).minusPatNum();
(*(patList[sameName[_patTmp]])).setCost(cost);
(*(patList[sameName[_patTmp]])).setReser(false);
}
void HospitalHandler::Infected()
{
infectNum++;
}
void HospitalHandler::RegisterHospital() //1.병원등록
{
char name[20];
int pcrNum;
cout << "등록 하실 병원명을 입력하세요" << endl;
cin >> name;
if (strcmp(name, "뒤로가기") == 0)
{
//return ;
}
cout << "초기 보유 신속 항원 검사 키트 개수" << endl;
cin >> pcrNum;
hosList[hosNum] = new Hospital(name, pcrNum);
hosNum++;
}
void HospitalHandler::FindHospital()
{
int i, found;
char name[20];
int num = 0;
while (1)
{
cout << "\n신속 항원 검사 가능 병원 조회 (검색종료:end) ";
cin >> name;
if (strcmp(name, "end") == 0)
break;
found = 1;
for (i = 0; i < hosNum; i++)
{
if (strcmp(name, (*(hosList[i])).getName()) == 0)
{
found = 0;
(*(hosList[i])).showInfo();
}
}
if (found)
cout << name << ", Not found !!! " << endl;
}//while (1) end예외 발생(0x00ECC3F0, Team_project1.exe): 0xC0000005: 0x00E0B1B8 위치를 읽는 동안 액세스 위반이 발생했습니다..
}
void HospitalHandler::ShowAllPatient()
{
for (int i = 0; i < patNum; i++)
{
(*(patList[i])).showInfo();
}
}
void HospitalHandler::ShowAllHospital()
{
for (int i = 0; i < hosNum; i++)
{
(*(hosList[i])).showInfo();
}
}
void HospitalHandler::Stats()
{
cout << "등록된 총 환자 수 : " << patNum << endl;
cout << "등록된 총 병원 수 : " << hosNum << endl;
cout << "총 누적 확진자 수 : " << infectNum << endl;
cout << "병원 별 확진자 수" << endl;
for (int i = 0; i < hosNum; i++) {
cout << (*(hosList[i])).getName() << " : " << (*(hosList[i])).getInfectThisHos() << "명" << endl;
}
}
void HospitalHandler::SaveData()
{
const char* file = "emps.dat";
ofstream fout;
fout.open(file, ios::out | ios::binary); // 읽기모드
if (!fout)
{
cout << "SaveData() 파일 열기 오류" << endl;
return;
}
fout.write((char*)&patNum, sizeof(patNum));
fout.write((char*)&hosNum, sizeof(hosNum));
fout.write((char*)&infectNum, sizeof(infectNum));
for (int i = 0; i < patNum; i++) {
(*(patList[i])).save(fout, patList, i);
}
for (int i = 0; i < hosNum; i++) {
fout.write((char*)(hosList[i]), sizeof(Hospital));
}
fout.close();
printf("ems.dat Save !!! \n");
}
void HospitalHandler::LoadData()
{
const char* file = "emps.dat";
Patient* ptr;
ifstream fin;
fin.open(file, ios::in | ios::binary); // 읽기모드
if (!fin)
{
cout << "LoadData() 파일 없음" << endl;
return;
}
fin.read((char*)&patNum, sizeof(patNum));
fin.read((char*)&hosNum, sizeof(hosNum));
fin.read((char*)&infectNum, sizeof(infectNum));
int size = 0;
for (int i = 0; i < patNum; i++)
{
fin.read((char*)&size, sizeof(int));
if (size == sizeof(InternalPatient)) {
patList[i] = new InternalPatient;
fin.read((char*)(patList[i]), sizeof(InternalPatient));
}
else if (size == sizeof(ExternalPatient)) {
patList[i] = new ExternalPatient;
fin.read((char*)(patList[i]), sizeof(ExternalPatient));
}
}
for (int i = 0; i < hosNum; i++)
{
hosList[i] = new Hospital;
fin.read((char*)(hosList[i]), sizeof(Hospital));
}
fin.close();
printf("ems.dat Load!!! \n");
}