Data Structure Lab
Practical 32 :
Problem Statement :
Pizza parlor accepting maximum M orders. Orders are served in first come first served basis. Order once placed cannot be cancelled. Write C++ program to simulate the system using circular queue using array.
Check Out Code Here 👇
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author : SPPU CSE GURU | |
#include<iostream> | |
using namespace std; | |
class Queue{ | |
private: | |
int front,rear,max; | |
int Q[5]; | |
public: | |
Queue(){ | |
front=-1; | |
rear=-1; | |
max=5; | |
} | |
int IsFull(); | |
int IsEmpty(); | |
void EnQueue(); | |
void DeQueue(); | |
void Display(); | |
}; | |
int Queue::IsFull(){ | |
if((rear+1)%max==front){ | |
return 1; | |
} | |
else{ | |
return 0; | |
} | |
} | |
int Queue::IsEmpty(){ | |
if(front==-1 && rear==-1){ | |
return 1; | |
} | |
else{ | |
return 0; | |
} | |
} | |
void Queue::EnQueue() | |
{ | |
int data; | |
cout<<"Enter Order no. to Add "<<endl; | |
cin>>data; | |
if(IsFull()){ | |
cout<<"Order Queue is Full"<<endl; | |
} | |
else{ | |
if(front==-1){ | |
front=rear=0; | |
} | |
else{ | |
rear=(rear+1)%max; | |
} | |
Q[rear]=data; | |
} | |
} | |
void Queue::DeQueue() | |
{ | |
if(IsEmpty()){ | |
cout<<"Empty"<<endl; | |
} | |
else{ | |
cout<<Q[front]<<" Order Delivered Successfully!!! "<<endl; | |
if(front==rear){ | |
front=rear=-1;; | |
} | |
else{ | |
front=(front+1)%max; | |
} | |
} | |
} | |
void Queue::Display(){ | |
int temp; | |
temp=front; | |
if(IsEmpty()){ | |
cout<<"Order Queue is Empty"<<endl; | |
} | |
else{ | |
cout<<"Order Queue is : "; | |
while(temp!=rear){ | |
cout<<Q[temp]<<' '; | |
temp=(temp+1)%max; | |
} | |
cout<<Q[temp]; | |
} | |
} | |
int main(){ | |
int choice; | |
char res; | |
Queue obj; | |
do | |
{ | |
cout<<"\n1.Add Order \n2.Deliver Order"<<endl; | |
cout<<"Enter your Choice : "<<endl; | |
cin>>choice; | |
cout<<endl; | |
switch(choice) | |
{ | |
case 1: | |
obj.EnQueue(); | |
obj.Display(); | |
break; | |
case 2: | |
obj.DeQueue(); | |
obj.Display(); | |
break; | |
} | |
cout<<"\nDo you want to continue (y or n)"<<endl; | |
cin>>res; | |
}while(res=='y'); | |
} |
Code can get updated so also come back later to see if there is any changes. Also if there is any problem with code you can comment below. Do share with your friends.😊
Comments
Post a Comment