-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
137 lines (115 loc) · 2.88 KB
/
Copy pathmain.cpp
File metadata and controls
137 lines (115 loc) · 2.88 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
#include <iostream>
#include <windows.h>
#include <fstream>
#include <sstream>
using namespace std;
class Hospital{
private:
string Name,Address,BGroup;
public:
Hospital():Name(""),Address(""),BGroup(""){}
void setName(string name){
Name =name;
}
void setAddress(string address){
Address=address;
}
void setBGroup(string group){
BGroup=group;
}
string getName(){
return Name;
}
string getAddress(){
return Address;
}
string getBGroup(){
return BGroup;
}
};
void admit(Hospital patient){
system("cls");
string name,address,group;
cout<<"\tEnter name of patient: ";
cin>>name;
patient.setName(name);
cout<<"\tEnter Address of patient: ";
cin>>address;
patient.setAddress(address);
cout<<"\tEnter Blood Group of patient: ";
cin>>group;
patient.setBGroup(group);
ofstream outfile("Hospital.txt",ios::app);
if(!outfile){
cout<<"\tError:File Can't Open!!"<<endl;
}else{
outfile<<"\t"<<patient.getName()<<" : "<<patient.getAddress()<<" : "<<patient.getBGroup()<<endl<<endl;
cout<<"\tpatient Admitted!"<<endl;
}
outfile.close();
Sleep(2000);
}
void discharge(){
system("cls");
string name;
cout<<"\tEnter Name of patient: ";
cin>>name;
ifstream infile("Hospital.txt");
ofstream outfile("Hospital Temp.txt");
if(!infile || !outfile){
cout<<"\tError:File can't open!"<<endl;
}
else{
string line;
bool found=false;
while(getline(infile,line)){
stringstream ss;
ss<<line;
string patientName;
ss>>patientName;
if(name == patientName){
found=true;
cout<<"\tpatient Discharged!"<<endl;
}
else{
outfile<<line<<endl;
}
}
if(!found){
cout<<"\tIncorrect Name!"<<endl;
}
}
outfile.close();
infile.close();
remove("Hospital.txt");
rename("Hospital Temp.txt","Hospital.txt");
Sleep(2000);
}
int main(){
Hospital patient;
bool exit=false;
while(!exit){
system("cls");
int val;
cout<<"\tHopital Management System"<<endl;
cout<<"\t*************************"<<endl;
cout<<"\t1.Admit Patient."<<endl;
cout<<"\t2.Discharge Patient."<<endl;
cout<<"\t3.Exit."<<endl;
cout<<"\tEnter Choice(1,2,3): ";
cin>>val;
if(val==1){
admit(patient);
}
else if(val==2){
discharge();
}
else if(val==3){
system("cls");
exit=true;
cout<<"\tGood Luck!"<<endl;
Sleep(2000);
}
Sleep(2000);
}
}