-
Notifications
You must be signed in to change notification settings - Fork 0
/
Practical_32(C++).cpp
114 lines (106 loc) · 2.69 KB
/
Practical_32(C++).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
/*
Pizza parlor accepting maximum M orders.
Orders are served in first come first served basis. Order once placed can not be cancelled.
Write C++ program to simulate the system using circular queue using array.
*/
#include<iostream>
#include<cstdlib>
using namespace std;
class pizza {
int front, rear, q[5];
public:
pizza() {
front = -1;
rear = -1;
}
int isfull() {
if ((front == 0 && rear == 4) || front == (rear + 1) % 5) {
return 1;
} else {
return 0;
}
}
int isempty() {
if (front == -1 && rear == -1) {
return 1;
} else {
return 0;
}
}
void add() {
if (isfull() == 0) {
cout << "\n Enter the Pizza ID: ";
if (front == -1 && rear == -1) {
front = 0;
rear = 0;
cin >> q[rear];
} else {
rear = (rear + 1) % 5;
cin >> q[rear];
}
char c;
cout << " Do you want to add another order? ";
cin >> c;
if (c == 'y' || c == 'Y')
add();
} else {
cout << "\n Orders are full ";
}
}
void serve() {
if (isempty() == 0) {
if (front == rear) {
cout << "\n Order served is : " << q[front];
front = -1;
rear = -1;
} else {
cout << "\n Order served is : " << q[front];
front = (front + 1) % 5;
}
} else {
cout << "\n Orders are empty ";
}
}
void display() {
if (isempty() == 0) {
for (int i = front; i != rear; i = (i + 1) % 5) {
cout << q[i] << " <- ";
}
cout << q[rear];
} else {
cout << "\n Orders are empty";
}
}
void check() {
int ch;
cout << "\n\n * * * * PIZZA PARLOUR * * * * \n\n";
cout << "\n 1. Add a Pizza \n 2. Display the Orders \n 3. Serve a pizza \n 4. Exit \n Enter your choice : ";
cin >> ch;
switch (ch) {
case 1:
add();
break;
case 2:
display();
break;
case 3:
serve();
break;
case 4:
exit(0);
default:
cout << "Invalid choice ";
check();
}
char ch1;
cout << "\n Do you want to continue? ";
cin >> ch1;
if (ch1 == 'y' || ch1 == 'Y')
check();
}
};
int main() {
pizza p1;
p1.check();
return 0;
}