-
Notifications
You must be signed in to change notification settings - Fork 2
/
Main.cpp
656 lines (602 loc) · 15.7 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
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
#include <iostream>
#include <string>
#include <Windows.h>
#include <fstream>
#include <string.h>
using namespace std;
/*
implementasi array -> done
implementasi struct -> done
implementasi pointer -> done
implementasi search -> done
implementasi sorting -> done
implementasi queue -> done
*/
#define MAX 10 // jumlah maksimal untuk antrian (bisa ditambah)
struct guest {
string nama;
char nik[17]{};
string address;
int umur{};
} person[100];// Implementasi array of struct
struct queue {
string data[MAX]{};
int head{}, tail{};
} antrian;
int jumlah = -1; // public varibel penampung posisi terakhir data pasien
//List fungsi
bool login();
bool auth(string username, string password); //Implementasi array 2D
void loading();
void mainMenu(); //Menu utama
bool regist();
void quisioner();//Implemetasi array
void rapid(); //Implementasi queue
int cari(char nik[]); //Implementasi squential search
void sorting(int sortMode); //Implementasi sorting
void cetakHasil(string *data); //Implementasi pointer
string saveToTxt(string *data); //Implementasi pointer
void exitConfirm();
void init(); //fungsi queue
int IsEmpty(); //fungsi queue
int IsFull(); //fungsi queue
void push(string data); //fungsi queue
string pop(); //fungsi queue
void Clear(); //fungsi queue
void Tampil(); //fungsi queue
int main() {
SetConsoleTitle(TEXT("Hospital Helper"));
bool isLogin;
init();
do
{
system("cls");
isLogin = login();
if (isLogin)
{
cout << "\n\t\t\t\t\t\t Login berhasil!";
Sleep(1200);
loading();
mainMenu();
}
} while (!isLogin);
return 0;
}
bool login() {
string username, password;
cout << "\n\t\t\t\n\t\t\t\t\t\t\tLOGIN" << endl;
cout << "\n\t\t\t\tUsername : "; cin >> username;
cout << "\n\t\t\t\tPasssword : "; cin >> password;
if (auth(username, password))
return true;
else
return false;
}
bool auth(string username, string password) { //Implementasi array 2D
string db[5][3] = {
{"anhalim", "admin", "ahmad nur halim"},
{"indra", "admin", "ade indra yudha pratama"},
{"Wibisono", "wibiganteng", "satrio wibisono"},
{"betha", "admin", "betharia pranesti nur pafitri"},
{"okta", "admin", "okta eka pratama"}
};
int i = 0;
do
{
if (username == db[i][0] && password == db[i][1]) {
return true;
}
i++;
} while (i < 5);
cout << "\n\n\t\t\t\t\t Password atau username salah!" << endl;
Sleep(1000);
return false;
}
void loading() {
string s = " ";
for (int i = 0; i < 100; i++) {
system("cls");
cout << "\n\n\n\n\n\t\t\t\t\t\t Loading " << i << "% " << "\n\t\t\t Jangan keluarkan program ataupun tekan apapun saat proses sedang berjalan\n";
s += "=";
cout << endl;
cout << "\t" << s;
cout << "\n\n\n\n\n\t\t\t\t\t\t Hospital Helper @2021";
}
}
void mainMenu() {
string uname, pass;
char nik[17];
int pilihan, hasil;
char pilih;
bool isRegistered;
awal:
SetConsoleTitle(TEXT("Hospital Helper"));
system("cls");
cout << "\n\tSelamat datang di Hospital Helper" << endl;
cout << "\n\t-------------------------------" << endl;
cout << "\t\t Menu";
cout << "\n\t-------------------------------" << endl;
cout << "\n\t1. Registrasi pasien" << endl;
cout << "\n\t2. Screening Covid-19" << endl;
cout << "\n\t3. Rapid test" << endl;// implementasi queue
cout << "\n\t4. Cari data pasien" << endl; // implementasi searching
cout << "\n\t5. Tampilkan data pasien" << endl; // implementasi sorting
cout << "\n\t6. keluar" << endl;
cout << "\n\t-------------------------------" << endl;
cout << "\n\n>\tMasukan pilihan kamu => ";
cin >> pilihan;
switch (pilihan)
{
case 1:
isRegistered = regist();
if (isRegistered)
{
system("cls");
cout << ">\tRegistrasi berhasil!" << endl;
}
break;
case 2:
cout << "\n>\tApakah pasien sebelumnya sudah terdaftar? [Y/n] -> ";
cin >> pilih;
if (pilih == 'Y' || pilih == 'y')
{
cout << ">\tSilahkan masukan NIK anda : ";
cin >> nik;
hasil = cari(nik);
if (hasil != -1)
{
quisioner();
}
}
else
{
isRegistered = regist();
if (isRegistered)
{
system("cls");
cout << ">\tRegistrasi berhasil!" << endl;
}
}
break;
case 3:
system("cls");
rapid();
break;
case 4:
system("cls");
cout << ">\tMasukan NIK pasien: ";
cin >> nik;
hasil = cari(nik);
if (hasil != -1)
{
cout << "\n\t---------------------------------" << endl;
cout << "\t Hasil Pencarian NIK " << endl;
cout << "\t---------------------------------" << endl;
cout << "\n>\tNama: " << person[hasil].nama << endl;
cout << ">\tUmur: " << person[hasil].umur << endl;
cout << ">\tNIK: " << person[hasil].nik << endl;
cout << ">\tAlamat: " << person[hasil].address << endl;
}
break;
case 5:
system("cls");
cout << "\n\t---------------------------------" << endl;
cout << "\t Pilih tipe pengurutan data " << endl;
cout << "\t---------------------------------" << endl;
cout << "\t1. ascending(menaik)" << endl;
cout << "\t2. descending(menurun)" << endl;
cout << "\n>\tMasukan pilihan -> ";
int k;
cin >> k;
sorting(k);
break;
case 6:
exitConfirm();
break;
default:
cout << ">\tPilihan menu tidak tersedia!" << endl;
break;
}
cout << "\n\n>\tKembali ke menu utama? [Y/n] -> ";
cin >> pilih;
if (pilih == 'Y' || pilih =='y')
goto awal;
else
exitConfirm();
}
bool regist() {
char pilihan;
SetConsoleTitle(TEXT("Registrasi pasien"));
system("cls");
cout << "\n>\tSebelum melanjutkan apakah data diri pasien bersedia tersimpan dalam database? [Y/n] -> ";
cin >> pilihan;
if (pilihan == 'y' || pilihan == 'Y') {
jumlah++;
cout << "\n\tData diri pasien" << endl;
cout << "\t--------------------" << endl;
cout << ">\tNama : ";
cin.ignore();
getline(cin, person[jumlah].nama);
cout << "\n>\tUmur : ";
cin >> person[jumlah].umur;
cout << "\n>\tNIK : ";
cin >> person[jumlah].nik;
cout << "\n>\tAlamat : ";
cin.ignore();
getline(cin, person[jumlah].address);
return true;
}
else
{
cout << ">\tRegistrasi gagal!" << endl;
Sleep(1000);
return false;
}
}
void quisioner() { //Implementasi array
system("cls");
string pilihan, hasil;
int yes = 0;
string question[5] = {
"\n\tApakah pasien demam?",
"\n\tApakah pasien batuk/pilek?",
"\n\tApakah Anda pernah kontak dengan pasien positif COVID-19 atau berada satu ruangan yang sama atau kontak dalam \n\t1 meter pada 14 hari terakhir ?",
"\n\tApakah Anda pernah berkunjung atau tinggal ke negara atau daerah endemis COVID-19 dalam 14 hari Terakhir?",
"\n\tApakah Anda mengalami Diare pada 14 hari terakhir ?"
};
string answer[3] = {
"Lakukan perawatan mandiri di rumah dengan beristirahat jika seminggu tidak ada perubahan segera datang ke klinik terdekta",
"Kondisi anda kurang fit, segera periksa dokter terdekat!",
"Segera lakukan rapid test di Fasilitas Kesehatan terdekat atau Hubungi segera layanan 119 Ext 9."
};
cout << "\n\tSilahkan isi quisioner berikut\n" << endl;
for (int i = 0; i < 5; i++)
{
cout << question[i] << endl;
cout << "\n>\tya/tidak?\n\t->";
cin >> pilihan;
if (pilihan == "ya" || pilihan == "Ya" || pilihan == "YA" || pilihan == "Y" || pilihan == "y")
yes++;
cout << "\t---------------------------------------------\n";
}
if (yes <= 2) {
hasil = answer[0];
cetakHasil(&hasil);
}
else if (yes == 3) {
hasil = answer[1];
cetakHasil(&hasil);
}
else {
hasil = answer[2];
cetakHasil(&hasil);
}
cout << "\n>\tSimpan hasil tes kedalam file? [Y/n] -> ";
cin >> pilihan;
if (pilihan == "ya" || pilihan == "YA" || pilihan == "y" || pilihan == "Y") {
string save = saveToTxt(&hasil);
cout << save << endl;
}
cout << "\n>\tApakah anda ingin melakukan rapid test? [Y/n] -> ";
cin >> pilihan;
if (pilihan == "ya" || pilihan == "YA" || pilihan == "y" || pilihan == "Y")
rapid();
else
mainMenu();
}
void rapid() {//implementasi queue
SetConsoleTitle(TEXT("RAPID TEST"));
char pilih;
int pilihan;
char nik[17];
int hasil, i = 0;
cout << "\n>\tApakah pasien sebelumnya sudah terdaftar? [Y/n] -> ";
cin >> pilih;
if (pilih == 'Y' || pilih == 'y')
{
do
{
system("cls");
Tampil();
cout << "\n\t-------------------------------" << endl;
cout << "\t\t Menu";
cout << "\n\t-------------------------------" << endl;
cout << "\n\t1. Ambil antrian" << endl;
cout << "\t2. Panggil antrian" << endl;
cout << "\t3. Reset antrian" << endl;
cout << "\t4. Keluar" << endl;
cout << "\n\t-------------------------------" << endl;
cout << "\n\tSilahkan masukan antrian yang akan diambil -> ";
cin >> pilihan;
switch (pilihan)
{
case 1:
cout << "\n>\tSilahkan masukan NIK pasien : ";
cin >> nik;
hasil = cari(nik);
if (hasil != -1)
{
push(person[hasil].nama);
}
else
{
cout << "\n>\tData pasien dengan NIK " << nik << " tidak ditemukan, silahkan mendaftar terlebih dahulu!" << endl;
return;
}
break;
case 2:
if (IsEmpty())
cout << "Antrian kosong!" << endl;
else {
string pasienName = pop();
cout << "\n\tSilahkan panggil pasien " << pasienName << " untuk melakukan tes rapid!" << endl;
}
break;
case 3:
Clear();
break;
case 4:
return;
break;
default:
cout << "\n\tMenu tidak tersedia!" << endl;
break;
}
Sleep(2000);
} while (true);
}
else
{
regist();
}
}
int cari(char nik[]) { //implementasi squential search
int posisi = -1;
for (int i = 0; i < 100; i++)
{
if (strcmp(nik, person[i].nik) == 0) {
posisi = i;
cout << "\t+----------------------------+";
cout << "\n\t|Data ditemukan!! |"<< endl;
cout << "\t+----------------------------+\n";
}
}
if (posisi == -1)
{
cout << "\t+----------------------------+";
cout << "\n\t|Data Tidak ditemukan!! |"<< endl;
cout << "\t+----------------------------+\n";
}
return posisi;
}
void sorting(int sortMode) { //implemetasi bubble sort
bool tukar;
int tempUmur, j, i;
char tempNIK[17];
string tempAdd, tempNama;
int total = jumlah + 1;
system("cls");
if (jumlah == -1) {
cout << "\t+----------------------------+";
cout << "\n\t|Data pasien kosong! |" << endl;
cout << "\t+----------------------------+";
return;
}
else if (sortMode == 1)// ascending
{
i = 0;
tukar = true;
while ((i <= total - 2) && (tukar))
{
tukar = false;
for (j = total - 1; j >= i + 1; j--)
{
if (person[j].umur < person[j - 1].umur)
{
{
tempUmur = person[j].umur;
person[j].umur = person[j - 1].umur;
person[j - 1].umur = tempUmur;
for (int i = 0; i < 17; i++) {
tempNIK[i] = person[j].nik[i];
person[j].nik[i] = person[j - 1].nik[i];
person[j - 1].nik[i] = tempNIK[i];
}
tempNama = person[j].nama;
person[j].nama = person[j - 1].nama;
person[j - 1].nama = tempNama;
tempAdd = person[j].address;
person[j].address = person[j - 1].address;
person[j - 1].address = tempAdd;
tukar = true;
}
}
i++;
}
}
}
else if(sortMode == 2)// descending
{
i = 0;
tukar = true;
while ((i <= total - 2) && (tukar))
{
tukar = false;
for (j = total - 1; j >= i + 1; j--)
{
if (person[j].umur > person[j - 1].umur)
{
tempUmur = person[j].umur;
person[j].umur = person[j - 1].umur;
person[j - 1].umur = tempUmur;
for (int i = 0; i < 17; i++) {
tempNIK[i] = person[j].nik[i];
person[j].nik[i] = person[j - 1].nik[i];
person[j - 1].nik[i] = tempNIK[i];
}
tempNama = person[j].nama;
person[j].nama = person[j - 1].nama;
person[j - 1].nama = tempNama;
tempAdd = person[j].address;
person[j].address = person[j - 1].address;
person[j - 1].address = tempAdd;
tukar = true;
}
}
i++;
}
}
else {
cout << "Maaf sepertinya menu nomor " << sortMode << " tidak tersedia!" << endl;
Sleep(2000);
return;
}
if (sortMode == 1)
cout << "Data pasien berdasarkan umur termuda" << endl;
else
cout << "Data pasien berdasarkan umur tertua" << endl;
for (i = 0; i <= jumlah; i++) {
int no = i + 1;
cout <<
no << ".\tNama : " << person[i].nama
<< "\n\tUmur : " << person[i].umur
<< "\n\tNIK : " << person[i].nik
<< "\n\tAlamat : " << person[i].address << endl;
}
}
void cetakHasil(string *data) { //Implementasi pointer
system("cls");
cout << "\n\t===========Hasil periksa============" << endl;
cout << "\n\tNama : " << person[jumlah].nama << endl;
cout << "\tUmur : " << person[jumlah].umur << endl;
cout << "\tNIK : " << person[jumlah].nik << endl;
cout << "\tAlamat : " << person[jumlah].address << endl;
cout << "\tHasil : " << *data << endl;
cout << "\n\t====================================" << endl;
}
string saveToTxt(string *data) { //Implementasi pointer
string charToString = person[jumlah].nik;
string fileName = charToString + "_HASILSCREENING.txt";
ofstream myfile(fileName);
if (myfile.is_open())
{
myfile << "\n\t===========Hasil periksa============" << endl;
myfile << "\n\tNama : " << person[jumlah].nama << endl;
myfile << "\tUmur : " << person[jumlah].umur << endl;
myfile << "\tNIK : " << person[jumlah].nik << endl;
myfile << "\tAlamat : " << person[jumlah].address << endl;
myfile << "\tHasil : " << *data << endl;
myfile << "\n\t===================================" << endl;
myfile.close();
return "\n\tHasil tersimpan dalam " + fileName;
}
else
{
return "\n\tGagal menyimpan file!";
}
}
void exitConfirm() {
string konfir, username, password;
SetConsoleTitle(TEXT("LOGOUT"));
system("cls");
cout << "\n\tSemua data pasien yang tersimpan akan terhapus!" << endl;
cout << "\tApakah anda yakin keluar? [Y/n] -> ";
cin >> konfir;
if (konfir == "Y" || konfir == "y")
{
cout << endl;
cout << "\tSebagai konfirmasi akhir silahkan masukan username dan password anda" << endl;
cout << "\tUsername : ";
cin >> username;
cout << "\tPassword : ";
cin >> password;
if (auth(username, password))
{
exit(0);
}
}
else
mainMenu();
}
void init() {
antrian.head = antrian.tail = -1;
}
int IsEmpty() {
if (antrian.tail == -1)
return 1;
else
return 0;
}
int IsFull() {
if (antrian.tail == MAX - 1)
return 1;
else
return 0;
}
void push(string data)
{
system("cls");
if (IsEmpty() == 1)
{
for (int i = 0; i < MAX; i++) { // cek apakah sebelumnya pasien sudah mengambil antrian
if (data == antrian.data[i])
{
cout << "\n\tGagal mengambil antrian!" << endl;
cout << "\n\t " << data << " sudah mengambil antrian sebelumnya" << endl;
return;
}
}
antrian.head = antrian.tail = 0;
antrian.data[antrian.tail] = data;
cout << "\n\t" << antrian.data[antrian.tail] << " Berhasil mendapat antrian!" << endl;
}
else if (IsFull() == 0)
{
for (int i = 0; i < MAX; i++) { // cek apakah sebelumnya pasien sudah mengambil antrian
if (data == antrian.data[i])
{
cout << "\n\tGagal mengambil antrian!" << endl;
cout << "\n\t" << data << " sudah mengambil antrian sebelumnya" << endl;
return;
}
}
antrian.tail++;
antrian.data[antrian.tail] = data;
cout << "\n\t " << antrian.data[antrian.tail] << " Berhasil mendapat antrian!" << endl;
}
else {
cout << "Antrian penuh" << endl;
}
}
string pop()
{
string e = antrian.data[antrian.head];
for (int i = antrian.head; i <= antrian.tail - 1; i++)
{
antrian.data[i] = antrian.data[i + 1];
}
antrian.tail--;
return e;
}
void Clear()
{
antrian.head = antrian.tail = -1;
cout << "\n\tAntrian berhasil direset!" << endl;
}
void Tampil()
{
if (IsEmpty() == 0)
{
cout << "\n\tDaftar antrian" << endl;
cout << "\t------------------------" << endl;
cout << "\tNo.\tNama" << endl;
for (int i = antrian.head; i <= antrian.tail; i++)
{
cout << "\t" << i + 1 << "\t" << antrian.data[i] << endl;
cout << "\t------------------------" << endl;
}
}
else
cout << "\n\tTidak ada antrian rapid test!" << endl;
cout << endl;
}