-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhospital_system_project.cpp
More file actions
111 lines (110 loc) · 2.74 KB
/
hospital_system_project.cpp
File metadata and controls
111 lines (110 loc) · 2.74 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
#include <iostream>
using namespace std;
const int specialization = 20;
const int max_queues = 5;
string allnames[specialization][max_queues];
int allstatus[specialization][max_queues];
int queue_len[specialization];
void shift_right(int spec,string names_shift[],int status_shift[]) {
int len =queue_len[spec];
for (int i = len - 1;i >= 0;i--) {
names_shift[i + 1] = names_shift[i];
status_shift[i + 1] = status_shift[i];
}
}
void shift_left(int spec, string names_shift[], int status_shift[]) {
int len = queue_len[spec];
for (int i = 0;i < len;i++) {
names_shift[i - 1] = names_shift[i];
status_shift[i - 1] = status_shift[i];
}
}
void next_patient() {
int spec;
cout << "enter the specialization\n";
cin >> spec;
int len = queue_len[spec];
if (len == 0)
cout << "no patients in this spec now ,Have rest Dr\n";
else {
cout << allnames[spec][0] << " please go to the Dr\n";
shift_left(spec,allnames[spec],allstatus[spec]);
queue_len[spec]--;
}
}
void print_patient(int spec, string names_print[], int status_print[]) {
int len = queue_len[spec];
if (len == 0)
return;
cout << "there are " << len << " patient in the specialization " << spec << "\n";
for (int i = 0;i < len;i++) {
cout << names_print[i] << " ";
if (status_print[i])
cout << "urgent\n";
else
cout << "regular\n";
}
}
void print_patients() {
cout << "********************************\n";
for (int spec = 0;spec < specialization;spec++) {
print_patient(spec, allnames[spec], allstatus[spec]);
}
}
bool add_patient() {
int spec;
string name;
int status;
cout << "please,enter the specialization,the name,the status\n";
cin >> spec >> name >> status;
int pos = queue_len[spec];
if (pos >= max_queues) {
cout << "can't add more to this specialization\n";
return false;
}
if (status == 0) {
allnames[spec][pos] = name;
allstatus[spec][pos] = status;
queue_len[spec]++;
}
else {
shift_right(spec,allnames[spec],allstatus[spec]);
allnames[spec][0] = name;
allstatus[spec][0] = status;
queue_len[spec]++;
}
return true;
}
int menu() {
int choice = -1;
while (choice == -1) {
cout << "please select the choice\n";
cout << "1: add new patients\n";
cout << "2: print all patients\n";
cout << "3: get next patient\n";
cout << "4: exit\n";
cin >> choice;
if (!(choice >= 1 && choice <= 4)) {
cout << "invalid choice..try again\n";
choice = -1;
}
}
return choice;
}
void hospital_system() {
while (true) {
int choice = menu();
if (choice == 1)
add_patient();
else if (choice == 2)
print_patients();
else if (choice == 3)
next_patient();
else
break;
}
}
int main()
{
hospital_system();
}