-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOOP_cp_final.cpp
More file actions
443 lines (404 loc) · 14.3 KB
/
OOP_cp_final.cpp
File metadata and controls
443 lines (404 loc) · 14.3 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
#include<iostream>
#include<fstream>
#include<stdlib.h>
#include<iomanip>
#include<conio.h>
using namespace std;
class patient{
private:
int app_no;
string name, symptoms, dob, blood_group, address, adhar_no, mobile_no, disease;
public:
void menu(char type);
void get_data();
void insert(char type);
void get_record();
void display_records(char type);
void particular_record(char type);
void discharge_patient(char type);
void Main_menu();
int get_appointno(){
return app_no;
}
string get_name(){
return name;
}
string get_symptoms(){
return symptoms;
}
string get_dob(){
return dob;
}
string get_blood_group(){
return blood_group;
}
string get_address(){
return address;
}
string get_adhar_no(){
return adhar_no;
}
string get_mobile_no(){
return mobile_no;
}
string get_disease(){
return disease;
}
};
class covid : public patient{
private:
int oxy;
char vent, oxy_required;
public:
void get_oxy(){
char ch;
cout<<"\n\t\t\tEnter oxygen level: ";
cin>>oxy;
if(oxy < 94){
oxy_required='Y';
cout<<"\t\t\tVentilator required..."<<endl;
cin>>ch;
if(ch=='Y'){
vent='Y';
}
else{
vent='N';
}
}
else{
oxy_required='N';
vent='N';
cout<<"\t\t\tOxygen and Ventilator not needed..."<<endl;
}
}
void get_cov();
};
covid project;
patient pat;
fstream file;
char x;
void patient::menu(char type){
int choice,ch;
do{
//system("cls");
cout<<endl;
cout<<"\t\t\t 1. Add new Patient"<<endl;
cout<<"\t\t\t 2. Display all Patients"<<endl;
cout<<"\t\t\t 3. Display particular Patient"<<endl;
cout<<"\t\t\t 4. Discharge Patient"<<endl;
cout<<"\t\t\t 5. Back to Main Menu"<<endl;
cout<<"\t\t\t 6. Exit"<<endl<<endl;
cout<<"\t\t\t-----------------"<<endl;
cout<<"\t\t\tChoose[1/2/3/4/5/6]"<<endl;
cout<<"\t\t\t-----------------"<<endl<<endl;
cout<<"\t\t\tEnter your choice: ";
cin>>choice;
switch(choice){
case 1:
insert(type);
break;
case 2:
display_records(type);
break;
case 3:
particular_record(type);
break;
case 4:
discharge_patient(type);
break;
case 5:
Main_menu();
case 6:
exit(0);
default:
cout<<"\n\t\t\tInvalid choice... Please try again..";
break;
}
cout<<"\n\t\t\tPress 1 for Menu or 0 to exit : ";
cin>>ch;
system("cls");
}while(ch==1);
}
void patient::get_data(){
system("cls");
cout<<"-----------------------------------------------------------------------------------------------------------------------------------------------";
cout<<"----------------------------------------------------------------------------------------------------------ADD NEW RECORD------------";
cout<<"--------------------------------------------------------------"<<endl;
cout<<"\t\t\tAppointment number.............................";
cin>>app_no;
cin.ignore();
cout<<"\t\t\tPatient name...................................";
getline(cin,name);
cout<<"\t\t\tSymptoms.......................................";
getline(cin,symptoms);
cout<<"\t\t\tDisease........................................";
getline(cin,disease);
cout<<"\t\t\tDate of birth..................................";
getline(cin,dob);
cout<<"\t\t\tBlood Group....................................";
getline(cin,blood_group);
cout<<"\t\t\tPatient address................................";
getline(cin,address);
cout<<"\t\t\tAadhar number(xxxx yyyy zzzz)..................";
getline(cin,adhar_no);
while(1){
if(adhar_no.length() != 14){
cout<<"\t\t\tAadhar number(xxxx yyyy zzzz)..................";
getline(cin,adhar_no);
}
else
break;
}
cout<<"\t\t\tMobile number..................................";
getline(cin,mobile_no);
while(1){
if(mobile_no.length() != 10){
cout<<"\t\t\tMobile number..................................";
getline(cin,mobile_no);
}
else
break;
}
}
void patient::insert(char type){
do{
if(type=='N'){
file.open("normalpat.dat",ios::app | ios::binary);
pat.get_data();
file.write((char*)&pat,sizeof(pat));
file.close();
cout<<"\n\t\t\tRecord added successfully";
cout<<"\n\t\t\tAdd Another Patient record (Y,N)";
cin>>x;
system("cls");
}
else{
file.open("covidpat.dat",ios::app | ios::binary);
project.get_data();
project.get_oxy();
file.write((char*)&project,sizeof(project));
file.close();
cout<<"\n\t\t\tRecord added successfully";
cout<<"\n\t\t\tAdd Another Patient record (Y,N)";
cin>>x;
system("cls");
}
}while(x == 'y' || x == 'Y');
}
void patient::get_record(){
//system("cls");
cout<<setw(6)<<app_no<<setw(15)<<name<<setw(15)<<symptoms<<setw(15)<<disease<<setw(15)<<dob<<setw(6)<<blood_group<<setw(6)<<address<<setw(15)<<adhar_no
<<setw(15)<<mobile_no<<endl;
}
void covid::get_cov(){
//system("cls");
cout<<setw(6)<<project.get_appointno()<<setw(8)<<project.get_name()<<setw(8)<<project.get_symptoms()<<setw(10)<<project.get_disease()<<setw(11)<<project.get_dob()
<<setw(6)<<project.get_blood_group()<<setw(15)<<project.get_address()<<setw(25)<<project.get_adhar_no()<<setw(15)<<project.get_mobile_no()<<setw(10)<<oxy<<setw(15)
<<oxy_required<<setw(15)<<vent<<endl;
}
void patient::display_records(char type){
system("cls");
if(type=='C'){
file.open("covidpat.dat",ios::in | ios::binary);
//project.get_record();
if(! file)
{
cout<<"\t\t\tFile not found";
}
else
{
cout<<"app_no "<<"name "<<"symptoms "<<"disease "<<"dob "<<"blood_group "
<<"address "<<"adhar_no "<<"mobile_no "<<"oxy "<<"oxy_required "
<<"vent"<<endl<<endl;
file.read((char*)&project,sizeof(project));
while (!file.eof())
{
project.get_cov();
file.read((char*)&project,sizeof(project));
}
file.close();
}
}
else{
file.open("normalpat.dat",ios::in | ios::binary);
//project.get_record();
if(!file)
{
cout<<"\t\t\tFile not found";
}
else
{
//cout<<"app_no"<<"name"<<"symptoms"<<"disease"<<"dob"<<"blood_group"
//<<"address"<<"adhar_no"<<"mobile_no"<<endl;
file.read((char*)&pat,sizeof(pat));
while (!file.eof())
{
pat.get_record();
file.read((char*)&pat,sizeof(pat));
}
file.close();
}
}
}
void patient::particular_record(char type){
system("cls");
if(type=='C'){
cout<<"---------------------------------------------------------------------------------------------------------------------------------------------------";
cout<<"---------------------------------------------------------------------------------------------------------PARTICULAR RECORD--------------------------------------------------------------"<<endl;
int no, flag=0, c;
file.open("covidpat.dat",ios::in | ios::binary);
if(!file){ //if file open fails
cout<<"\nFile not found";
}
else{
do{
cout<<"\nEnter the appointment number: ";
cin>>no;
file.read((char*)&project, sizeof(project));
while(!file.eof()){
if(no==project.get_appointno()){
flag=1;
cout<<"\n------------------------------------------------------------------------------------------------------------------------------------------------------------\n";
cout<<setw(6)<<"app_no"<<setw(15)<<"name"<<setw(15)<<"symptoms"<<setw(15)<<"disease"<<setw(10)<<"dob"<<setw(6)<<"blood_group"<<setw(6)<<"address"<<setw(15)
<<"adhar_no"<<setw(15)<<"mobile_no"<<setw(15)<<"oxy"<<setw(15)<<"oxy_required"<<setw(15)<<"vent"<<endl;
cout<<"\n------------------------------------------------------------------------------------------------------------------------------------------------------------\n";
project.get_cov();
cout<<"\n------------------------------------------------------------------------------------------------------------------------------------------------------------\n";
break;
}
file.read((char*)&project, sizeof(project));
}
if(flag==0){
cout<<"\nItem not found...";
}
cout<<"\nIf you want to search another one record press 1 to continue and 0 to menu.....";
cin>>c;
}while(c==1);
}
system("cls");
file.close();
project.menu(type);
}
else{
cout<<"---------------------------------------------------------------------------------------------------------------------------------------------------";
cout<<"---------------------------------------------------------------------------------------------------------PARTICULAR RECORD--------------------------------------------------------------"<<endl;
int no, flag=0, c;
file.open("normalpat.dat",ios::in | ios::binary);
if(!file){ //if file open fails
cout<<"\nFile not found";
exit(0);
}
else{
do{
cout<<"\nEnter the appointment number: ";
cin>>no;
file.read((char*)&pat, sizeof(pat));
while(!file.eof()){
if(no==pat.get_appointno()){
flag=1;
cout<<"\n-------------------------------------------------------------------------------------------------------------------------------\n";
cout<<setw(6)<<"app_no"<<setw(15)<<"name"<<setw(15)<<"symptoms"<<setw(15)<<"disease"<<setw(15)<<"dob"<<setw(6)<<"blood_group"<<setw(6)<<"address"<<setw(15)
<<"adhar_no"<<setw(15)<<"mobile_no"<<endl;
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n";
pat.get_record();
cout<<"\n--------------------------------------------------------------------------------------------------------------------------------\n";
break;
}
file.read((char*)&pat, sizeof(pat));
}
if(flag==0){
cout<<"\nItem not found...";
}
cout<<"\nIf you want to search another one record press 1 to continue and 0 to menu.....";
cin>>c;
}while(c==1);
}
system("cls");
file.close();
pat.menu(type);
}
}
void patient::discharge_patient(char type){
if(type=='C'){
int no;
cout<<"\nEnter the appointment number: ";
cin>>no;
fstream file2;
file2.open("discharged.dat", ios::out | ios::binary);
file.open("covidpat.dat", ios::in | ios::binary);
if(!file){
cout<<"\nFile not found";
//exit(0);
}
else{
file.read((char*)&project, sizeof(project));
while(!file.eof()){
if(no != project.get_appointno()){
file2.write((char*)&project, sizeof(project));
}
file.read((char*)&project,sizeof(project));
}
}
file2.close();
file.close();
remove("covidpat.dat");
rename("discharged.dat","covidpat.dat");
}
else{
int no;
cout<<"\nEnter the appointment number: ";
cin>>no;
fstream file2;
file2.open("discharged_nor.dat", ios::out | ios::binary);
file.open("normalpat.dat", ios::in | ios::binary);
if(!file){
cout<<"\nFile not found";
//exit(0);
}
else{
file.read((char*)&pat, sizeof(pat));
while(!file.eof()){
if(no != pat.get_appointno()){
file2.write((char*)&pat, sizeof(pat));
}
file.read((char*)&pat,sizeof(pat));
}
}
file2.close();
file.close();
remove("normalpat.dat");
rename("discharged_nor.dat","normalpat.dat");
}
}
void patient::Main_menu(){
system("cls");
int ch;
cout<<"\t\t\t-----------------------"<<endl;
cout<<"\t\t\t| Sancheti Hospital |"<<endl;
cout<<"\t\t\t-----------------------"<<endl<<endl;
cout<<"\t\t\t1. Normal Patient"<<endl;
cout<<"\t\t\t2. Covid Patient"<<endl;
cout<<"\t\t\t3. Exit"<<endl;
cout<<"\t\t\tEnter your choice: ";
cin>>ch;
switch(ch){
case 1:
system("cls");
//char nor='N';
cout<<"\n\t\t\t******** Normal patient records ********"<<endl<<endl;
pat.menu('N');
break;
case 2:
system("cls");
//char cov='C';
cout<<"\n\t\t\t******** Covid Patient records ********"<<endl<<endl;
project.menu('C');
break;
case 3:
exit(0);
}
}
int main(){
pat.Main_menu();
return 0;
}