Skip to content

Commit c9c9111

Browse files
authored
Create GroupE_Practical32(C++).cpp
1 parent a3c0d7c commit c9c9111

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

GroupE_Practical32(C++).cpp

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/*
2+
Pizza parlor accepting maximum M orders.
3+
Orders are served in first come first served basis. Order once placed can not be cancelled.
4+
Write C++ program to simulate the system using circular queue using array.
5+
*/
6+
7+
#include<iostream>
8+
#include<cstdlib>
9+
using namespace std;
10+
class pizza
11+
{
12+
int front,rear,q[5];
13+
public:
14+
pizza()
15+
{
16+
front=-1;
17+
rear=-1;
18+
}
19+
int isfull()
20+
{
21+
22+
if((front==0&&rear==4)||front==rear+1)
23+
{
24+
return 1;
25+
}
26+
else
27+
{
28+
return 0;
29+
}
30+
}
31+
int isempty()
32+
{
33+
if(front==-1&&rear==-1)
34+
{
35+
return 1;
36+
}
37+
else
38+
{
39+
return 0;
40+
}
41+
}
42+
void add()
43+
{
44+
if(isfull()==0)
45+
{
46+
cout<<"\n Enter the Pizza ID: ";
47+
if(front==-1&&rear==-1)
48+
{
49+
front=0;
50+
rear=0;
51+
cin>>q[rear];
52+
}
53+
else
54+
{
55+
rear=(rear+1)%5;
56+
cin>>q[rear];
57+
}
58+
char c;
59+
cout<<" Do you want to add another order ? ";
60+
cin>>c;
61+
if(c=='y'||c=='Y')
62+
add();
63+
}
64+
else
65+
{
66+
cout<<"\n Orders are full ";
67+
}
68+
69+
}
70+
void serve()
71+
{
72+
if(isempty()==0)
73+
{
74+
if(front==rear)
75+
{
76+
cout<<"\n Order served is : "<<q[front];
77+
front=-1;
78+
rear=-1;
79+
}
80+
else
81+
{
82+
cout<<"\n Order served is : "<<q[front];
83+
front=(front+1)%5;
84+
}
85+
}
86+
else
87+
{
88+
cout<<"\n Orders are empty ";
89+
}
90+
}
91+
void display()
92+
{
93+
if(isempty()==0)
94+
{
95+
for(int
96+
i=front;i!=rear;i=(i+1)%5)
97+
{
98+
cout<<q[i]<<"
99+
<- ";
100+
}
101+
cout<<q[rear];
102+
}
103+
else
104+
{
105+
cout<<"\n Orders are empty";
106+
}
107+
}
108+
void check()
109+
{
110+
int ch;
111+
cout<<"\n\n * * * * PIZZA PARLOUR * * * * \n\n";
112+
cout<<"\n 1. Add a Pizza \n 2. Display the Orders \n 3. Serve a pizza \n 4. Exit \n Enter your choice : ";
113+
cin>>ch;
114+
switch(ch)
115+
{
116+
case 1:
117+
add();
118+
break;
119+
120+
case 2:
121+
122+
display();
123+
break;
124+
125+
case 3:
126+
127+
serve();
128+
break;
129+
130+
case 4:
131+
132+
exit(0);
133+
134+
default:
135+
cout<<"Invalid choice ";
136+
137+
check();
138+
}
139+
char ch1;
140+
cout<<"\n Do you want to continue? ";
141+
cin>>ch1;
142+
if(ch1=='y'||ch1=='Y')
143+
check();
144+
}
145+
};
146+
int main()
147+
{
148+
pizza p1;
149+
p1.check();
150+
return 0;
151+
}

0 commit comments

Comments
 (0)