-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathQueueMenu.cpp
289 lines (190 loc) · 4.5 KB
/
QueueMenu.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct Customer {
char name[101];
int priority;
Customer *next, *prev;
} *head = NULL, *tail = NULL, *curr = NULL;
struct Customer *createNewNode (char name[], int priority){
struct Customer* temp = (struct Customer*) malloc (sizeof(struct Customer));
strcpy (temp->name, name);
temp->priority = priority;
temp->next = NULL;
temp->prev = NULL;
return temp;
}
void push (Customer *node){
// Push One
if (head == NULL){
head = tail = node;
head->prev = NULL;
tail->next = NULL;
}
// Push Head
else if (node->priority < head->priority){
node->next = head;
head->prev = node;
head = node;
head->prev = NULL;
}
// Push Tail
else if (node->priority >= tail->priority){
node->prev = tail;
tail->next = node;
tail = node;
tail->next = NULL;
}
// Push Mid
else {
curr = head;
while (curr->next->priority <= node->priority){
curr = curr->next;
}
Customer *a = curr;
Customer *b = curr->next;
a->next = node;
node->prev = a;
node->next = b;
b->prev = node;
}
}
void pop (Customer *node){
// Pop One
if (head == tail){
free (head);
head = tail = NULL;
}
else {
head = head->next;
free (head->prev);
head->prev = NULL;
}
}
void popAll (){
while (head != NULL){
pop(head);
}
}
int main(){
int menu = 0;
do {
system ("cls");
// Title
puts ("==============================");
puts ("|SUNIB Restaurant Reservation|");
puts ("==============================");
puts ("\nWaiting Line:");
// Print Queue
int num = 1;
curr = head;
if (curr == NULL){
printf ("Queue is empty!\n");
}
else {
while (curr != NULL){
printf ("%d. %s\n", num, curr->name);
curr = curr->next;
num++;
}
}
// Menu
puts ("\n1. Add Customer to Queue");
puts ("2. Serve One");
puts ("3. Serve All");
puts ("4. Dismiss Queue");
puts ("0. Exit\n");
do {
printf (">> ");
scanf ("%d", &menu); getchar();
}
while (menu < 0 || menu > 4);
if (menu == 1){
int priority;
char checker[21];
bool flag = false;
char name[101];
do {
system ("cls");
printf ("Input your Membership and Name (Membership [space] Name formatted): ");
scanf ("%s %s", checker, name); getchar();
if (strcmp (checker, "VVIP") == 0 || strcmp (checker, "VIP") == 0 || strcmp (checker, "Member") == 0 || strcmp (checker, "Guest") == 0){
flag = true;
}
}
while (!flag);
if (strcmp (checker, "VVIP") == 0){
priority = 0;
}
else if (strcmp (checker, "VIP") == 0){
priority = 1;
}
else if (strcmp (checker, "Member") == 0){
priority = 2;
}
else {
priority = 3;
}
Customer *node = createNewNode (name, priority);
push (node);
}
else if (menu == 2){
curr = head;
if (curr == NULL){
printf ("\nThe queue is empty!");
getchar();
}
else {
if (curr->priority == 0){
printf ("\nAttention! %s is being served at VVIP Table.", curr->name);
}
else if (curr->priority == 1) {
printf ("\nAttention! %s is being served at VIP Table.", curr->name);
}
else if (curr->priority == 2) {
printf ("\nAttention! Member %s is being served at Regular Table.", curr->name);
}
else if (curr->priority == 3) {
printf ("\nAttention! Guest %s is being served at Regular Table.", curr->name);
}
getchar();
pop (curr);
}
}
else if (menu == 3){
curr = head;
if (curr == NULL){
printf ("\nThe queue is empty!");
getchar();
}
else {
while (curr != NULL){
if (curr->priority == 0){
printf ("\nAttention! %s is being served at VVIP Table.", curr->name);
}
else if (curr->priority == 1) {
printf ("\nAttention! %s is being served at VIP Table.", curr->name);
}
else if (curr->priority == 2) {
printf ("\nAttention! Member %s is being served at Regular Table.", curr->name);
}
else if (curr->priority == 3) {
printf ("\nAttention! Guest %s is being served at Regular Table.", curr->name);
}
curr = curr->next;
}
getchar();
popAll();
}
}
else if (menu == 4){
printf ("\nEnd of the day :)");
getchar();
popAll();
}
}
while (menu != 0);
system ("cls");
printf ("Thank youu :)\n");
return 0;
}