Please write code in C++ Please using a queue implemented with a linked list and
ID: 3919626 • Letter: P
Question
Please write code in C++
Please using a queue implemented with a linked list and follow all specific instructions. Name file lab9.cpp
Please include screenshot of all outputs. Thanks!
You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list. Make sure to read pages 1. Create a class named waitList that can store a name and number of guest:s Use constructors to automatically initialize the member variables 2. Add the following operations to your program a. Return the first person in the queue b. Return the last person in the queue c. Add a person to the queue d. Delete a person from the queue 3. Create a main program to test your class. Your main program should contain the following options a. Add a guest (adds the reservation name and number of guests) b. 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) C. Show last guest waiting (return NONE if the queue is empty) d. Show first guest waiting (return NONE if the queue is empty) e. ExitExplanation / Answer
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<alloc.h>
class waitList
{
struct node
{
char name[10];
int number;
node *next;
} *f,*r,*temp;
public:
waitList()
{
f = r = NULL;
}
void first_person();
void last_person();
void add_person(char str[], int no);
void delet_person(char str[]);
void display();
};
// show first person in queue
void waitList ::first_person()
{
if(f==NULL)
cout<<" Quesu is empty ";
else
cout<<" First Person in queue is : "<<f->name<<" Number of guests: "<<f->number;
}
// show last person in queue
void waitList ::last_person()
{
if(f==NULL)
cout<<" Quesu is empty ";
else
cout<<" Last Person in queue is : "<<r->name<<"Number of guests:"<<r->number;
}
void waitList :: display()
{
if(f == NULL)
cout <<" Empty";
else
{ temp = f;
while(temp != NULL)
{
cout <<" "<<temp->name<<" " <<temp->number;
temp=temp->next;
}
}
}
//Add given person in queue
void waitList :: add_person(char str[], int no)
{ temp = new node();
strcpy(temp->name, str);
temp->number = no;
if(f==NULL)
{ f = temp;
r = temp;
}
else
{ temp->next = NULL;
r->next = temp;
r = temp;
}
}
//delete given person from the queue
void waitList :: delet_person(char str[])
{
if (f == NULL)
cout<<" Queue is empty ";
else
{
temp = f; struct node *temp1;
if(strcmp(str,temp->name)==0)
{
f = temp->next;
cout<<" "<<temp->name<<"is deleted";
free(temp);
}
else
{ temp1 = f;
temp= temp1->next;
while(temp != NULL)
{
if(strcmp(str,temp->name)==0)
break;
temp1= temp;
temp=temp->next;
}
if(temp == NULL)
cout<<" Record does not exist";
else
temp1->next = temp->next;
}
}
}
void main()
{
int ch,no;
waitList obj,obj1;
char str[10];
clrscr();
do
{
cout<<" ================";
cout<<" 1.Add Person 2.Delete Person 3.First person 4.Last person 5.Exit";
cout<<" ================";
cout<<" Enter your choice ";
cin>>ch;
switch(ch)
{
case 1: cout<<" Enter Name & Number of guests : ";
cin>>str>>no;
obj.add_person(str,no);
obj.display();
break;
case 2: cout<<" Enter Name";
cin>>str;
obj.delet_person(str);
obj.display();
break;
case 3: obj.first_person();
break;
case 4:obj.last_person();
break;
case 5:cout<<"Exiting......";
break;
default : cout<<"wrong Choice";
}
}while(ch!= 5);
getch();
}