-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hospital_managment_system.cpp
307 lines (304 loc) · 7.8 KB
/
Hospital_managment_system.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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct record{
char name[50];
char surname[50];
char policlinicName[50];
int id;
struct record*next;
};
struct record* Add(struct record*head){
struct record*new_record;
new_record=(struct record*)malloc(sizeof(struct record));
printf("Enter the Name :\n");scanf("%s",&new_record->name);
printf("Enter the surname :\n");scanf("%s",&new_record->surname);
printf("Enter the policlinic Name :(Orthodontics,Endoscopy,Implant,Cardiology)\n");scanf("%s",&new_record->policlinicName);
printf("Enter the id :\n");scanf("%d",&new_record->id);
if(head==NULL){
head=new_record;
head->next=NULL;
printf("You added the first pation");
}
else{
new_record->next=head;
head=new_record;
printf("Added pation");
}
return head;
}
struct record* print(struct record*head){
struct record*control=head;
while(head!=NULL){
printf("Name:%s surname:%s policlinic:%s id:%d\n",head->name,head->surname,head->policlinicName,head->id);
head=head->next;
}
head=control;
return head;
}
struct record* search(struct record*head){
int ctr;
printf("1-By name: 2-By surname: 3-By policlinic name:");scanf("%d",&ctr);
struct record*control=head;
switch(ctr){
case 1:
char Name[50];
printf("Enter the pation Name:");scanf("%s",&Name);
while(head!=NULL){
if(strcmp(head->name,Name)==0){
printf("Name:%s Surname:%s policlinicName:%s id:%d",head->name,head->surname,head->policlinicName,head->id);
break;
}
head=head->next;
}
break;
case 2:
char SurName[50];
printf("Enter the pation surname:");scanf("%s",&SurName);
while(head!=NULL){
if(strcmp(head->surname,SurName)==0){
printf("Name:%s Surname:%s policlinicName:%s id:%d",head->name,head->surname,head->policlinicName,head->id);
break;
}
head=head->next;
}
break;
case 3:
char policlinic[50];
printf("Enter the pation policlinic name:");scanf("%s",&policlinic);
while(head!=NULL){
if(strcmp(head->policlinicName,policlinic)==0){
printf("Name:%s Surname:%s policlinicName:%s id:%d",head->name,head->surname,head->policlinicName,head->id);
break;
}
head=head->next;
}
break;
}
head=control;
return head;
}
struct record* Delete(struct record*head){
int ctr;
printf("1-By name: 2-By surname: 3-By policlinic name:");scanf("%d",&ctr);
switch (ctr){
case 1:
char Name[50];
printf("Enter the name that you wanna delete:");scanf("%s",&Name);
if((strcmp(head->name,Name)==0)&&(head->next==NULL)){
free(head);
head=NULL;
printf("You delete the pation by name %s succesfully",Name);
}
else if((strcmp(head->name,Name)==0)&&(head->next!=NULL)){
struct record*tmp=head->next;
free(head);
head=tmp;
printf("You delete the pation by name %s succesfully",Name);
}
else{
struct record*tmp=head;
struct record*p=head;
while(tmp->next!=NULL){
if(strcmp(tmp->name,Name)==0){
p->next=tmp->next;
free(tmp);
printf("You delete the pation by name %s succesfully",Name);
break;
}
p=tmp;
tmp=tmp->next;
}
if(strcmp(tmp->name,Name)==0){
p->next=NULL;
free(tmp);
printf("You delete the pation by name %s succesfully",Name);
}
}
return head;
case 2:
char Surname[50];
printf("Enter the surname that you wanna delete:");scanf("%s",&Surname);
if((strcmp(head->surname,Surname)==0)&&(head->next==NULL)){
free(head);
head=NULL;
printf("You delete the pation by surname %s succesfully",Surname);
}
else if((strcmp(head->surname,Surname)==0)&&(head->next!=NULL)){
struct record*tmp=head->next;
free(head);
head=tmp;
printf("You delete the pation by surname %s succesfully",Surname);
}
else{
struct record*tmp=head;
struct record*p=head;
while(tmp->next!=NULL){
if(strcmp(tmp->surname,Surname)==0){
p->next=tmp->next;
free(tmp);
printf("You delete the pation by surname %s succesfully",Surname);
}
p=tmp;
tmp=tmp->next;
}
if(strcmp(tmp->surname,Surname)==0){
p->next=NULL;
free(tmp);
printf("You delete the pation by surname %s succesfully",Surname);
}
}
return head;
case 3:
char Policlinic[50];
printf("Enter the Policlinic name that you wanna delete:");scanf("%s",&Policlinic);
if((strcmp(head->policlinicName,Policlinic)==0)&&(head->next==NULL)){
free(head);
head=NULL;
printf("You delete the pation by policlinic name %s succesfully",Policlinic);
}
else if((strcmp(head->policlinicName,Policlinic)==0)&&(head->next!=NULL)){
struct record*tmp=head->next;
free(head);
head=tmp;
printf("You delete the pation by policlinic name %s succesfully",Policlinic);
}
else{
struct record*tmp=head;
struct record*p=head;
while(tmp->next!=NULL){
if(strcmp(tmp->policlinicName,Policlinic)==0){
p->next=tmp->next;
free(tmp);
printf("You delete the pation by policlinic name %s succesfully",Policlinic);
}
p=tmp;
tmp=tmp->next;
}
if(strcmp(tmp->policlinicName,Policlinic)==0){
p->next=NULL;
free(tmp);
printf("You delete the pation by policlinic name %s succesfully",Policlinic);
}
}
return head;
}
}
struct record* sortByName(struct record*head){
char *lst[50]={};
int counter=0;
struct record*ctr=head;
while(head!=NULL){
lst[counter]=head->name;
counter+=1;
head=head->next;
}
int lstLen=counter;
int control=0;
while(control<lstLen){
for(int i=0;i<(lstLen-1);i++){
if(strcmp(lst[i],lst[i+1])>0){
char *k=lst[i];
lst[i]=lst[i+1];
lst[i+1]=k;
}
}
control+=1;
}
for(int i=0;i<lstLen;i++){
printf("%s ",lst[i]);
}
printf(" (you sorted the pations by their names succesfully)");
head=ctr;
return head;
}
struct record* sortBySurname(struct record*head){
char *lst[50]={};
int counter=0;
struct record*ctr=head;
while(head!=NULL){
lst[counter]=head->surname;
counter+=1;
head=head->next;
}
int lstLen=counter;
int control=0;
while(control<lstLen){
for(int i=0;i<(lstLen-1);i++){
if(strcmp(lst[i],lst[i+1])>0){
char *k=lst[i];
lst[i]=lst[i+1];
lst[i+1]=k;
}
}
control+=1;
}
for(int i=0;i<lstLen;i++){
printf("%s ",lst[i]);
}
printf(" (you sorted the pations by their surnames succesfully)");
head=ctr;
return head;
}
struct record* sortByPoliclinicname(struct record*head){
char *lst[50]={};
int counter=0;
struct record*ctr=head;
while(head!=NULL){
lst[counter]=head->policlinicName;
counter+=1;
head=head->next;
}
int lstLen=counter;
int control=0;
while(control<lstLen){
for(int i=0;i<(lstLen-1);i++){
if(strcmp(lst[i],lst[i+1])>0){
char *k=lst[i];
lst[i]=lst[i+1];
lst[i+1]=k;
}
}
control+=1;
}
for(int i=0;i<lstLen;i++){
printf("%s ",lst[i]);
}
printf(" (you sorted the pations by their policlinic names succesfully)");
head=ctr;
return head;
}
int main(){
struct record*head=NULL;
int choice;
printf("****Hospital Managment System****\n");
printf("1 -- Add a new pation:\n");
printf("2 -- search a pation:\n");
printf("3 -- Delete a pation:\n");
printf("4 -- Sort pations by their names:\n");
printf("5 -- Sort pations by their surnames:\n");
printf("6 -- Sort pations by their policlinic names:\n");
printf("7 -- exit\n");
printf("8 -- Display the pations:\n");
while(1){
scanf("%d",&choice);
switch(choice){
case 1:head=Add(head);
break;
case 2:head=search(head);
break;
case 3:head=Delete(head);
break;
case 4:head=sortByName(head);
break;
case 5:head=sortBySurname(head);
break;
case 6:head=sortByPoliclinicname(head);
break;
case 7:exit(0);
case 8:head=print(head);
break;
break;
}
}
}