-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.cpp
More file actions
1834 lines (1512 loc) · 55 KB
/
main_test.cpp
File metadata and controls
1834 lines (1512 loc) · 55 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
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
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#define _CRT_SECURE_NO_DEPRECATE
// library
#include <iostream> //cin and cout
#include <iomanip> //setw, left, right, fixed
#include <climits>
#include <cctype> //isalpha, isnum, isalnum, ispunc, isupper, islower
#include <cmath> //pow, abs, fabs, ceil, floor, sqrt
#include <cstring> //strcat, strncat, strcpy, strncpy
#include <ctime>
#include <stdlib.h>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
// typedef for client
typedef struct
{
char username[50];
char password[50];
char ic[30];
char contactnum[30];
char status[20];
char feedbacks[600];
}USER;
// typedef for doctor
typedef struct
{
char d_name[50];
char d_password[50];
char d_ic[30];
char d_contactnum[30];
}DOCTOR;
// Doctor login interface functions
void doctor_login_interface(DOCTOR d[], int* id_ptr);
int doctor_login(DOCTOR d[], int* i_ptr);
void doctor_signup(DOCTOR d[]);
// Patients login interface functions
void user_login_interface(USER c[], int* id_ptr);
int user_login(USER c[], int* i_ptr);
void user_signup(USER c[]);
// Doctor main menu functions
void doctor_mainmenu(USER c[], int id);
int doctor_resetpwd(DOCTOR d[], int* i_ptr);
void doctor_feedback(USER c[], int id);
// Patients main menu functions
void user_mainmenu(USER c[], int id);
int user_resetpwd(USER c[], int* i_ptr);
int user_update(USER c[], int id);
void diagnose(USER c[], int id);
int updatePhonenum(USER c[], int id);
int updateStatus(USER c[], int id);
void faq(USER c[], int id);
void feedback(USER c[], int id);
// Diagnose functions
void hyperglycemia_test(void);
void hypoglycemia_test(void);
//faq functions
void hyperglycemia_faq(USER c[], int id);
void hypoglycemia_faq(USER c[], int id);
//other functions
void exit(); // Function used to logout of the account
bool check_number(string str); //Check input is number or no
// _oo0oo_ _oo0oo_
// o8888888o o8888888o
// 88" . "88 88" . "88
// (| -_- |) (| -_- |)
// 0\ = /0 0\ = /0
// ___/`---'\___ ___/`---'\___
// .' \\| |// '. .' \\| |// '.
// / \\||| : |||// \ / \\||| : |||// \
// / _||||| -:- |||||- \ / _||||| -:- |||||- \
// | | \\\ - /// | | | | \\\ - /// | |
// | \_| ''\---/'' |_/ | | \_| ''\---/'' |_/ |
// \ .-\__ '-' ___/-. / \ .-\__ '-' ___/-. /
// ___'. .' /--.--\ `. .'___ ___'. .' /--.--\ `. .'___
// ."" '< `.___\_<|>_/___.' >' "". ."" '< `.___\_<|>_/___.' >' "".
// | | : `- \`.;`\ _ /`;.`/ - ` : | | | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `_. \_ __\ /__ _/ .-` / / \ \ `_. \_ __\ /__ _/ .-` / /
// =====`-.____`.___ \_____/___.-`___.-'===== =====`-.____`.___ \_____/___.-`___.-'=====
// `=---=' `=---='
//
// 佛祖保佑 永无BUG 佛祖保佑 永无BUG
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//main function
int main()
{
// Clear screen
system("CLS");
// Create an array of CLIENT structs
USER c[20];
DOCTOR d[20];
// Open input files (patients)
ifstream name_file("username.txt", ios::in);
ifstream pass_file("userpassword.txt", ios::in);
ifstream ic_file("useric.txt", ios::in);
ifstream phonenum_file("userphone.txt", ios::in);
ifstream stats_file("status.txt", ios::in);
ifstream feedback_file("feedback.txt", ios::in);
// Open input files (doctor)
ifstream doc_name_file("d_username.txt", ios::in);
ifstream doc_pass_file("d_password.txt", ios::in);
ifstream doc_ic_file("d_ic.txt", ios::in);
ifstream doc_phonenum_file("d_phone.txt", ios::in);
// Check if file opening was successful (patient)
if (!name_file)
cout << "Error opening username file\n";
else if (!pass_file)
cout << "Error opening userpassword file\n";
else if (!ic_file)
cout << "Error opening useric file\n";
else if (!phonenum_file)
cout << "Error opening user phone number file\n";
else if (!stats_file)
cout << "Error opening user status file\n";
else if (!feedback_file)
cout << "Error opening user feedback file\n";
else
{
// Read data from input files into the CLIENT array
for (int i = 0; i < 20; i++)
{
name_file >> c[i].username;
pass_file >> c[i].password;
ic_file >> c[i].ic;
phonenum_file >> c[i].contactnum;
stats_file >> c[i].status;
feedback_file >> c[i].feedbacks;
}
// Close input files
name_file.close();
pass_file.close();
ic_file.close();
phonenum_file.close();
stats_file.close();
feedback_file.close();
}
// Check if file opening was successful (doctor)
if (!doc_name_file)
cout << "Error opening doctor name file\n";
else if (!doc_pass_file)
cout << "Error opening doctor password file\n";
else if (!doc_ic_file)
cout << "Error opening doctor ic file\n";
else if (!doc_phonenum_file)
cout << "Error opening doctor phone number file\n";
else
{
// Read data from input files into the CLIENT array
for (int i = 0; i < 20; i++)
{
doc_name_file >> d[i].d_name;
doc_pass_file >> d[i].d_password;
doc_ic_file >> d[i].d_ic;
doc_phonenum_file >> d[i].d_contactnum;
}
// Close input files
doc_name_file.close();
doc_pass_file.close();
doc_ic_file.close();
doc_phonenum_file.close();
}
// Call login interface function
int decision;
int id;
do {
cout << "Are you a doctor or patient?";
cout << endl;
cout << "<1> Patient" << endl;
cout << "<2> Doctor" << endl;
cout << "--->\t";
cin >> decision;
} while (decision != 1 && decision != 2);
// Login and call respective main menu function
if (decision == 1)
{
user_login_interface(c, &id);
user_mainmenu(c, id);
}
else
{
doctor_login_interface(d, &id);
doctor_mainmenu(c, id);
}
return 0;
}
//function to validate if the string is number
bool check_number(string str) {
for (int i = 0; i < str.length(); i++) {
// Check if the character at position i is not a digit
if (isdigit(str[i]) == false) {
return false; // If a non-digit character is found, return false
}
}
return true; // If all characters are digits, return true
}
//user login function definitions
void user_login_interface(USER c[], int* id_ptr)
{
char interfaceAns;
do
{
cout << "\nDo you want to <L>ogin or <S>ign up or <R>eset password? >>> ";
cin >> interfaceAns;
interfaceAns = toupper(interfaceAns);
} while (interfaceAns != 'L' && interfaceAns != 'S' && interfaceAns != 'R');
int i;
if (interfaceAns == 'L') // If user chooses to login
{
user_login(c, &i); // Call the login function to perform login process
*id_ptr = i; // Store the user ID in the memory location pointed by id_ptr
}
else if (interfaceAns == 'S') // If user chooses to sign up
{
user_signup(c); // Call the signup function to perform sign up process
}
else if (interfaceAns == 'R') // If user chooses to reset password
{
user_resetpwd(c, &i); // Call the resetpwd function to perform password reset process
*id_ptr = i; // Store the user ID in the memory location pointed by id_ptr
main(); // Call the main function to restart the program after password reset
}
return;
}
//function for user login
int user_login(USER c[], int* i_ptr)
{
char username[50], password[50];
bool userpassopt, usernameopt;
int i;
do
{
cin.ignore(1); // Ignore a single character in the input buffer to clear any remaining newline characters
cout << "Please enter your username --> ";
cin >> username; // Read user input for username
cout << "Please enter your password --> ";
cin >> password; // Read user input for password
fflush(stdin); // Flush the input buffer to clear any remaining characters
for (int i = 0; i < 50; i++) // Iterate through the array of CLIENT objects
{
if (strcmp(c[i].username, username) == 0) // Compare the entered username with the username in CLIENT object
{
usernameopt = true; // Set usernameopt flag to true indicating username match
if (strcmp(c[i].password, password) == 0) // Compare the entered password with the password in CLIENT object
{
userpassopt = true; // Set userpassopt flag to true indicating password match
*i_ptr = i; // Store the index of the matched CLIENT object in the memory location pointed by i_ptr
break; // Break out of the loop as the login is successful
}
else
{
userpassopt = false; // Set userpassopt flag to false indicating incorrect password
}
}
else
{
usernameopt = false; // Set usernameopt flag to false indicating no username match
}
}
if ((userpassopt == false || usernameopt == false))
{
cout << "\nIncorrect password or username\n" << endl; // Display error message for incorrect username or password
}
else
{
cout << "\nLogin successful\n" << endl; // Display success message for successful login
}
} while (usernameopt == false); // Continue looping until a valid username is entered
return 0;
}
//function for user to signup
void user_signup(USER c[])
{
int phone_len, ic_len;
string name, password1, password2, contact_num, ic, stats, temp_feedback;
bool validate, validrange, validateic, validrangeic, validate2, validrangephone;
validateic = true;
validate2 = true;
validate = true;
stats = "NULL";
temp_feedback = "NULL";
// Get user's name
cout << "Please enter your name: ";
getline(cin >> ws, name);
// Get user's IC number
cout << "Please enter your ic number without '-' (123456789012): ";
do
{
cin >> ic;
// Validate if IC number is a number
bool validateic = check_number(ic);
if (validateic == true)
{
char icarray[30];
strcpy(icarray, ic.c_str());
ic_len = strlen(icarray);
// Check if IC number length is within valid range (11 to 13)
if ((ic_len < 13) && (ic_len > 11))
{
validrangeic = true;
}
else
{
validrangeic = false;
}
}
else
{
cout << "Invalid input" << endl;
}
if (validateic == false || validrangeic == false)
cout << "Please enter your ic again: ";
} while (validateic == false || validrangeic == false);
// Get user's contact number
cout << "Please enter your contact number without '-' (i.e:0183958711): ";
do
{
cin >> contact_num;
// Validate if contact number is a number
bool validate2 = check_number(contact_num);
char contactnumarray[30];
strcpy(contactnumarray, contact_num.c_str());
phone_len = strlen(contactnumarray);
// Check if contact number length is within valid range (10 to 13)
if ((phone_len <= 13) && (phone_len >= 10))
{
validrangephone = true;
}
else
{
validrangephone = false;
}
if (validate2 == false || validrangephone == false)
{
cout << "Invalid input" << endl;
cout << "Please enter your contact number again without '-' (i.e:0183958711): ";
}
} while (validate2 == false || validrangephone == false);
// Get user's password
do
{
cout << "Please enter your password: ";
cin >> password1;
cout << "Please enter your password again: ";
cin >> password2;
if (password1 != password2)
{
cout << "Different password entered \n"; // Prompt user that different passwords were entered
cout << "Please try again\n"; // Prompt user to try again
cout << "Please enter your password: "; // Prompt user to enter password again
cin >> password1;
cout << "Please enter your password again: "; // Prompt user to enter password again
cin >> password2;
}
} while (password1 != password2); // Repeat until password1 and password2 match
ofstream passwordfile("userpassword.txt", ios::app); // Create an output file stream to append to userpassword.txt file
passwordfile << password2 << endl; // Write password2 to userpassword.txt followed by newline
ofstream username("username.txt", ios::app); // Create an output file stream to append to username.txt file
username << name << endl; // Write name to username.txt followed by newline
ofstream phonenumfile("userphone.txt", ios::app); // Create an output file stream to append to userphone.txt file
phonenumfile << contact_num << endl; // Write contact_num to userphone.txt followed by newline
ofstream icfile("useric.txt", ios::app); // Create an output file stream to append to useric.txt file
icfile << ic << endl; // Write ic to useric.txt followed by newline
ofstream stats_file("status.txt", ios::app); // Create an output file stream to append to status.txt file
stats_file << stats << endl; // Write status to status.txt followed by newline
ofstream feedback_file("feedback.txt", ios::app); // Create an output file stream to append to feedback.txt file
feedback_file << temp_feedback << endl; // Write a temporary feedback to feedback.txt followed by newline
system("CLS"); // Clear screen
cout << "Sign up complete \n"; // Prompt user that sign up is complete
main(); // Call main() function to restart the program
}
//function to reset user's password
int user_resetpwd(USER c[], int* i_ptr)
{
// Input for username and new password
string username, resetpassword;
cout << "Enter your username: ";
cin >> username;
cout << "Enter your new password: ";
cin >> resetpassword;
string usernameToFind = username; // Username to find
string newPassword = resetpassword; // New password to replace
// Open the username text file for reading
ifstream usernameFile("username.txt");
if (!usernameFile.is_open()) {
cout << "Failed to open username file." << endl;
//return 1;
}
// Open the password text file for reading
ifstream passwordFile("userpassword.txt");
if (!passwordFile.is_open()) {
cout << "Failed to open password file." << endl;
usernameFile.close();
//return 1;
}
vector<string> usernames; // Vector to store usernames from file
vector<string> passwords; // Vector to store passwords from file
string line;
// Read usernames and passwords from the files into memory
while (getline(usernameFile, line)) {
usernames.push_back(line);
getline(passwordFile, line);
passwords.push_back(line);
}
usernameFile.close(); // Close username file
passwordFile.close(); // Close password file
// Search for the username to find and update the corresponding password
bool found = false;
for (size_t i = 0; i < usernames.size(); ++i) {
if (usernames[i] == usernameToFind) {
found = true;
passwords[i] = newPassword; // Update password
*i_ptr = i; // Store index of updated password
break;
}
}
if (found) {
// Write the updated passwords back to the password file
ofstream updatedPasswordFile("userpassword.txt");
if (!updatedPasswordFile.is_open()) {
cout << "Failed to open updated password file." << endl;
return 1;
}
for (size_t i = 0; i < passwords.size(); ++i) {
updatedPasswordFile << passwords[i] << endl;
}
updatedPasswordFile.close(); // Close updated password file
cout << "Password updated successfully." << endl;
}
else {
cout << "Username not found." << endl;
}
return 0;
}
// doctor login function definitions
void doctor_login_interface(DOCTOR d[], int* id_ptr)
{
char interfaceAns;
do
{
cout << "\nDo you want to <L>ogin or <S>ign up or <R>eset password? >>> ";
cin >> interfaceAns;
interfaceAns = toupper(interfaceAns);
} while (interfaceAns != 'L' && interfaceAns != 'S' && interfaceAns != 'R');
int i;
if (interfaceAns == 'L') // If doctor chooses to login
{
doctor_login(d, &i); // Call the login function to perform login process
*id_ptr = i; // Store the user ID in the memory location pointed by id_ptr
}
else if (interfaceAns == 'S') // If user chooses to sign up
{
doctor_signup(d); // Call the signup function to perform sign up process
}
else if (interfaceAns == 'R') // If user chooses to reset password
{
doctor_resetpwd(d, &i); // Call the resetpwd function to perform password reset process
*id_ptr = i; // Store the user ID in the memory location pointed by id_ptr
main(); // Call the main function to restart the program after password reset
}
return;
}
//function for doctor login
int doctor_login(DOCTOR d[], int* i_ptr)
{
char username[50], password[50];
bool userpassopt, usernameopt;
int i;
do
{
cin.ignore(1); // Ignore a single character in the input buffer to clear any remaining newline characters
cout << "Please enter your username --> ";
cin >> username; // Read user input for username
cout << "Please enter your password --> ";
cin >> password; // Read user input for password
fflush(stdin); // Flush the input buffer to clear any remaining characters
for (int i = 0; i < 50; i++) // Iterate through the array of CLIENT objects
{
if (strcmp(d[i].d_name, username) == 0) // Compare the entered username with the username in CLIENT object
{
usernameopt = true; // Set usernameopt flag to true indicating username match
if (strcmp(d[i].d_password, password) == 0) // Compare the entered password with the password in CLIENT object
{
userpassopt = true; // Set userpassopt flag to true indicating password match
*i_ptr = i; // Store the index of the matched CLIENT object in the memory location pointed by i_ptr
break; // Break out of the loop as the login is successful
}
else
{
userpassopt = false; // Set userpassopt flag to false indicating incorrect password
}
}
else
{
usernameopt = false; // Set usernameopt flag to false indicating no username match
}
}
if ((userpassopt == false || usernameopt == false))
{
cout << "\nIncorrect password or username\n" << endl; // Display error message for incorrect username or password
}
else
{
cout << "\nLogin successful\n" << endl; // Display success message for successful login
}
} while (usernameopt == false); // Continue looping until a valid username is entered
return 0;
}
//function for doctor to signup
void doctor_signup(DOCTOR d[])
{
int phone_len, ic_len;
string name, password1, password2, contact_num, ic;
bool validate, validrange, validateic, validrangeic, validate2, validrangephone;
validateic = true;
validate2 = true;
validate = true;
// Get doctor's name
cout << "Please enter your name: ";
getline(cin >> ws, name);
// Get user's IC number
cout << "Please enter your ic number without '-' (123456789012): ";
do
{
cin >> ic;
// Validate if IC number is a number
bool validateic = check_number(ic);
if (validateic == true)
{
char icarray[30];
strcpy(icarray, ic.c_str());
ic_len = strlen(icarray);
// Check if IC number length is within valid range (11 to 13)
if ((ic_len < 13) && (ic_len > 11))
{
validrangeic = true;
}
else
{
validrangeic = false;
}
}
else
{
cout << "Invalid input" << endl;
}
if (validateic == false || validrangeic == false)
cout << "Please enter your ic again: ";
} while (validateic == false || validrangeic == false);
// Get user's contact number
cout << "Please enter your contact number without '-' (i.e:0183958711): ";
do
{
cin >> contact_num;
// Validate if contact number is a number
bool validate2 = check_number(contact_num);
char contactnumarray[30];
strcpy(contactnumarray, contact_num.c_str());
phone_len = strlen(contactnumarray);
// Check if contact number length is within valid range (10 to 13)
if ((phone_len <= 13) && (phone_len >= 10))
{
validrangephone = true;
}
else
{
validrangephone = false;
}
if (validate2 == false || validrangephone == false)
{
cout << "Invalid input" << endl;
cout << "Please enter your contact number again without '-' (i.e:0183958711): ";
}
} while (validate2 == false || validrangephone == false);
// Get user's password
do
{
cout << "Please enter your password: ";
cin >> password1;
cout << "Please enter your password again: ";
cin >> password2;
if (password1 != password2)
{
cout << "Different password entered \n"; // Prompt user that different passwords were entered
cout << "Please try again\n"; // Prompt user to try again
cout << "Please enter your password: "; // Prompt user to enter password again
cin >> password1;
cout << "Please enter your password again: "; // Prompt user to enter password again
cin >> password2;
}
} while (password1 != password2); // Repeat until password1 and password2 match
ofstream passwordfile("d_password.txt", ios::app); // Create an output file stream to append to doctor_password.txt file
passwordfile << password2 << endl; // Write password2 to doctor_password.txt followed by newline
ofstream username("d_username.txt", ios::app); // Create an output file stream to append to doctor_name.txt file
username << name << endl; // Write name to doctor_name.txt followed by newline
ofstream phonenumfile("d_phone.txt", ios::app); // Create an output file stream to append to doctor_phone.txt file
phonenumfile << contact_num << endl; // Write contact_num to doctor_phone.txt followed by newline
ofstream icfile("d_ic.txt", ios::app); // Create an output file stream to append to doctor_ic.txt file
icfile << ic << endl; // Write ic to doctor_ic.txt followed by newline
system("CLS"); // Clear screen
cout << "Sign up complete \n"; // Prompt user that sign up is complete
main(); // Call main() function to restart the program
}
//function to reset doctor's password
int doctor_resetpwd(DOCTOR d[], int* i_ptr)
{
// Input for username and new password
string username, resetpassword;
cout << "Enter your username: ";
cin >> username;
cout << "Enter your new password: ";
cin >> resetpassword;
string usernameToFind = username; // Username to find
string newPassword = resetpassword; // New password to replace
// Open the username text file for reading
ifstream usernameFile("d_username.txt");
if (!usernameFile.is_open()) {
cout << "Failed to open doctor_name file." << endl;
//return 1;
}
// Open the password text file for reading
ifstream passwordFile("d_password.txt");
if (!passwordFile.is_open()) {
cout << "Failed to open d_password file." << endl;
usernameFile.close();
//return 1;
}
vector<string> usernames; // Vector to store usernames from file
vector<string> passwords; // Vector to store passwords from file
string line;
// Read usernames and passwords from the files into memory
while (getline(usernameFile, line))
{
usernames.push_back(line);
getline(passwordFile, line);
passwords.push_back(line);
}
usernameFile.close(); // Close username file
passwordFile.close(); // Close password file
// Search for the username to find and update the corresponding password
bool found = false;
for (size_t i = 0; i < usernames.size(); ++i) {
if (usernames[i] == usernameToFind) {
found = true;
passwords[i] = newPassword; // Update password
*i_ptr = i; // Store index of updated password
break;
}
}
if (found) {
// Write the updated passwords back to the password file
ofstream updatedPasswordFile("d_password.txt");
if (!updatedPasswordFile.is_open()) {
cout << "Failed to open updated password file." << endl;
return 1;
}
for (size_t i = 0; i < passwords.size(); ++i) {
updatedPasswordFile << passwords[i] << endl;
}
updatedPasswordFile.close(); // Close updated password file
cout << "Password updated successfully." << endl;
}
else {
cout << "Username not found." << endl;
}
return 0;
}
// main menu function definitions
void user_mainmenu(USER c[], int id)
{
system("CLS"); // Clear the screen
time_t ttime = time(0); // Variable to store current time
char* dt = ctime(&ttime); // Get current time as string
cout << "Today's Date and Time -->\t" << dt << endl; // Print current date and time
char status = ' '; // Variable to store status
cout << "========================================================================================================================" << endl;
cout << left << setw(25) << "Name" << left << setw(20) << "Ic number" << left << setw(23) << "Contact Number" << left << setw(25) << "Status" << left << setw(18)<< endl; // Display column headers
cout << "========================================================================================================================" << endl;
cout << left << setw(25);
cout << c[id].username; // Display username from the USER array
cout << left << setw(20);
cout << c[id].ic; // Display IC number from the USER array
cout << left << setw(23);
cout << c[id].contactnum; // Display contact number from the USER array
cout << left << setw(25);
cout << c[id].status; // Display status from the USER array
cout << endl;
cout << endl;
cout << endl;
cout << endl;
cout << endl;
char ans;
do {
cout << "Press <1> to do diagnose" << endl; // Display menu option
cout << "Press <2> to update your user profile" << endl; // Display menu option
cout << "Press <3> to review the FAQ" << endl; // Display menu option
cout << "Press <4> to review feedback from doctor" << endl; //Display doctor feedback
cout << "Press <5> to Exit" << endl << endl; // Display menu option
cout << "--->";
cin >> ans; // Get user input
cout << endl;
} while (ans != '1' && ans != '2' && ans != '3' && ans != '4' && ans != '5'); // Continue to display the menu if input is invalid
if (ans == '1')
{
system("CLS"); // Clear the screen
diagnose(c, id); // Call the diagnose() function to diagnose
}
else if (ans == '2')
{
system("CLS"); // Clear the screen
user_update(c, id); // Call the userupdate() function
}
else if (ans == '3')
{
system("CLS"); // Clear the screen
faq(c, id); // Call the faq() function
}
else if (ans == '4')
{
system("CLS"); // Clear the screen
feedback(c, id); // Call the feedback() function
}
else if (ans == '5')
{
system("CLS"); // Clear the screen
exit(); // Call the exit() function
}
else
{
cout << "invalid input please try again"; // Display error message
user_mainmenu(c, id); // Call the user_mainmenu() function recursively to retry
}
return; // Return from the function
}
//function for user to diagnose their status
void diagnose(USER c[], int id)
{
int disease; //1 for hyperglycemia, 2 for hypoglycemia, 3 for back to mainmenu
do {
cout << "Diagnose interface:\n\n";
cout << "<1> Hyperglycemia test\n";
cout << "<2> Hypoglycemia test\n";
cout << "<3> Back to main menu\n\n";
cout << "--->\t";
cin >> disease;
} while (disease != 1 && disease != 2 && disease != 3);
if (disease == 1)
hyperglycemia_test();
else if (disease == 2)
hypoglycemia_test();
else
user_mainmenu(c, id);
}
//hyperglycemia test, if has the symptoms, yes +1, if yes > 3, u have hyperglycemia
void hyperglycemia_test(void)
{
system("CLS");
int yes = 0;
char ans1, ans2, ans3, ans4, ans5, ans6;
cout << "Hyperglycemia test:\n";
do {
cout << "1. Do you have frequent urine? <Y/N>\t\t>>> ";
cin >> ans1;
ans1 = toupper(ans1);
} while (ans1 != 'Y' && ans1 != 'N');
if (ans1 == 'Y')
yes++;
do {
cout << "2. Do you have excessive thirst? <Y/N>\t\t>>> ";
cin >> ans2;
ans2 = toupper(ans2);
} while (ans2 != 'Y' && ans2 != 'N');
if (ans2 == 'Y')
yes++;
do {
cout << "3. Do you have dry mouth? <Y/N>\t\t\t>>> ";
cin >> ans3;
ans3 = toupper(ans3);
} while (ans3 != 'Y' && ans3 != 'N');
if (ans3 == 'Y')
yes++;
do {
cout << "4. Do you have exhaustion? <Y/N>\t\t>>> ";
cin >> ans4;
ans4 = toupper(ans4);
} while (ans4 != 'Y' && ans4 != 'N');
if (ans4 == 'Y')
yes++;
do {
cout << "5. Do you have nausea? <Y/N>\t\t\t>>> ";
cin >> ans5;
ans5 = toupper(ans5);
} while (ans5 != 'Y' && ans5 != 'N');
if (ans5 == 'Y')
yes++;
do {
cout << "6. Do you have high blood sugar? <Y/N>\t\t>>> ";
cin >> ans6;
ans6 = toupper(ans6);
} while (ans6 != 'Y' && ans6 != 'N');
if (ans6 == 'Y')
yes++;
if (yes > 3)
cout << "\n\nYou might have hyperglycemia, please update your user profile before seek help from doctor for more informations\n";
else
cout << "\n\nCongratulations, you doesn't seems like you are having hyperglycemia\n";
}
//hypoglycemia test, if has the symptoms, yes +1, if yes > 3, u have hypoglycemia
void hypoglycemia_test(void)
{
system("CLS");
int yes = 0;
char ans1, ans2, ans3, ans4, ans5, ans6;
cout << "Hypoglycemia test:\n";
do {