-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE-32_completed.cpp
111 lines (97 loc) · 1.84 KB
/
E-32_completed.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
#include <iostream>
#define n 5
using namespace std;
class queue
{
int front = -1, rear = -1, input, size = 0, position;
int queue[n];
public:
void stats()
{
cout << "Front is " << front << endl;
cout << "Rear is " << rear << endl;
cout << "Size is " << size << endl;
}
void enqueue();
void dequeue();
void display();
};
void queue::enqueue()
{
position = (rear + 1) % n;
if (front == position)
{
cout << "Parlour is full" << endl;
}
else
{
rear = (rear + 1) % n;
cout << "Enter Order No : ";
cin >> input;
queue[rear] = input;
if (front == -1)
{
front = rear;
}
size++;
}
}
void queue::dequeue()
{
if (size == 0)
{
cout << "Parlour is empty";
}
else
{
cout << "Order No. " << queue[front] << " is processed. " << endl;
front = (front + 1) % n;
size--;
}
}
void queue::display()
{
if (size == 0)
{
cout << "Parlour is empty" << endl;
}
else
{
for (int i = front; i != rear; i = ((i + 1) % n))
{
cout << queue[i] << " ";
}
cout << queue[rear] << endl;
}
}
int main()
{
int ch;
queue obj;
while (1)
{
cout << "\n\t\t\t***** MENU *****\n"
<< endl;
cout << "1. Take Order, 2. Serve Order, 3. Current Orders, 4. Close Parlour" << endl;
cin >> ch;
cout << endl;
if (ch == 1)
{
obj.enqueue();
}
if (ch == 2)
{
obj.dequeue();
}
if (ch == 3)
{
obj.display();
}
if (ch == 4)
{
cout << "Parlour is closed\nThank You Visit Again.";
exit(1);
}
}
return 0;
}