You will design a program to keep track of a restaurants waitlist using a queue
ID: 665925 • Letter: Y
Question
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list using c++.
1. Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables.
·
2. Add the following operations to your program:
Return the first person in the queue
Return the last person in the queue
Add a person to the queue
Delete a person from the queue
3. Create a main program to test your class. Your main program should contain the following options.
Add a guest (adds the reservation name and number of guests)
Delete a guest (the user must give you the name to delete, the list may be empty or the guest may not be in the list)
Show last guest waiting (return NONE if the queue is empty)
Show first guest waiting (return NONE if the queue is empty)
Exit
Explanation / Answer
#include<iostream>
#include<stdlib.h>
#include <string>
using namespace std;
class queue
{
string queue1[5];
int rear,front;
public:
queue()
{
rear=-1;
front=-1;
}
void insert(string x)
{
if(rear > 4)
{
cout <<"queue over flow";
front=rear=-1;
return;
}
queue1[++rear]=x;
cout <<"inserted" <<x;
}
void delete()
{
if(front==rear)
{
cout <<"queue under flow";
return;
}
cout <<"deleted" <<queue1[++front];
}
void lastGuest()
{
if(rear==front)
{
cout <<" queue empty";
return;
}
cout <<queue1[rear]<<" ";
}
void firstGuest(){
if(rear==front)
{
cout <<" queue empty";
return;
}
cout <<queue1[front+1]<<" ";
}
};
main()
{
string guest;
int c;
queue qu;
while(1)
{
cout <<" 1.Add a guest 2.delete a guest 3.show last guest waiting 4.first guest waiting 5.exit Enter ur choice";
cin >> c;
switch(c)
{
case 1: cout <<"enter the guest";
cin >> guest;
qu.insert(guest);
break;
case 2: qu.delete(); break;
case 3: qu.lastGuest();break;
case 4: qu.firstGuest();break;
default: exit(0);
}
}
return (0);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.