-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHospitalSystem.cpp
134 lines (113 loc) · 2.86 KB
/
HospitalSystem.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
#include<iostream>
using namespace std;
const int MAX_SPECIALIZATION = 20;
const int MAX_QUEUE = 5;
string names[MAX_SPECIALIZATION+1][MAX_QUEUE+1];
int status[MAX_SPECIALIZATION+1][MAX_QUEUE+1];
int queue_length[MAX_SPECIALIZATION+1];
int menu() {
int choice = -1;
while (choice == -1) {
cout << "\nEnter your choice:\n";
cout << "1) Add new patient\n";
cout << "2) Print all patients\n";
cout << "3) Get next patient\n";
cout << "4) Exit\n";
cin >> choice;
if (!(1 <= choice && choice <= 4)) {
cout << "Invalid choice. Try again\n";
choice = -1; // loop keep working
}
}
return choice;
}
void shift_left(int spec, string names_sp[], int status_sp[])
{
int len = queue_length[spec];
for (int i = 1; i < len; ++i) {
names_sp[i-1] = names_sp[i];
status_sp[i-1] = status_sp[i];
}
queue_length[spec]--;
}
void shift_right(int spec, string names_sp[], int status_sp[]){
int len = queue_length[spec];
for(int i=len-1; i >=0; --i){
names_sp[i+1] = names_sp[i];
status_sp[i+1] = status_sp[i];
}
queue_length[spec]++;
}
bool add_patient(){
int spec;
string name;
int st;
cout <<"Enter specialization, name, statis: ";
cin >> spec >> name >> st;
int pos = queue_length[spec];
if(pos >= MAX_QUEUE){
cout <<"Sorry we can't add more patients for this specialization\n";
return false;
}
if (st ==0){
names [spec][pos] == name;
status[spec][pos] = st;
queue_length[spec]++;
}
else{
shift_right (spec, names[spec], status[spec]);
names [spec][0] = name;
status[spec][0]= st;
}
return true;
}
void print_pationt(int spec, string names_sp[], int status_sp[]){
int len = queue_length[spec];
if(len ==0)
return ;
cout <<"There are " <<len << " patinets in specialization " << spec << "\n";
for (int i =0; i < len; ++i){
cout << names_sp[i] <<" ";
if (status_sp[i])
cout << " urgent\n ";
else
cout << " regular\n ";
}
cout <<"\n";
}
void print_patients(){
cout <<"****************************\n";
for (int spec = 0; spec < MAX_SPECIALIZATION; ++spec) {
print_pationt(spec, names[spec], status[spec]);
}
}
void get_next_patients(){
int spec;
cout <<"Entre specialization: ";
cin >> spec;
int len = queue_length[spec];
if (len ==0){
cout << "No pationts in this moment. Have a rest, Dr\n";
return;
}
cout << names[spec][0] << "Please go with Dr\n";
shift_left(spec, names[spec], status[spec]);
}
void hospital_system(){
while ( true)
{
int choice = menu();
if (choice ==1)
add_patient();
else if (choice ==2 )
print_patients();
else if (choice ==3)
get_next_patients();
else
break;
}
}
int main(){
hospital_system();
return 0;
}