Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Program in C++ and chapter is stacks and queue . You will design a program to ke

ID: 3867189 • Letter: P

Question

Program in C++ and chapter is stacks and queue .

You will design a program to keep track of a restaurants wait list using a queue implemented with a linked list. Create a class named wait list that can store a name and number of guests. Use constructions to automatically what the member variables. Add following operations to your program. a. Return the 1^st 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. Create a main program to test or class. You main program should contain following options. a. Add a guest (odds the reservation name and number of guests) b. Delete a guest (the user must give you the name to the list may be empty or guest may not be in 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. Exit.

Explanation / Answer

Solution:-

The below given C++ code implements a restaurant queue and we can manage the queue by this program. After choosing the choice from menu we can add and delete the customer entry. We csn retrieve first customer in the queue and last customer in the queue.

The code is given below -

---------------------------------------------------------------------------------------------------

// Program to manage a restaurant queue

#include<iostream>

#include <string>
using namespace std;

class queue
{
int front,rear;

string queue1[20];
public:
queue()
{
front=-1;
rear=-1;
}

// retrieving first guest from the queue
void firstGuest(){
if(rear==front)
{
cout <<" queue empty";
return;
}

cout <<queue1[front+1]<<" ";

}
};

//retrieving last guest from the queue
void lastGuest()
{
if(rear==front)
{
cout <<" queue empty";
return;
}

cout <<queue1[rear]<<" ";

// Inserting guest in the queue
void insert(string x)
{
if(rear > 19)
{
cout <<"queue over flow";
front=rear=-1;
return;
}
queue1[++rear]=x;
cout <<"inserted" <<x;
}

// Deleting guest from the queue
void delete()
{
if(front==rear)
{
cout <<"queue under flow";
return;
}
cout <<"deleted" <<queue1[++front];
}

// main program to display menu
main()
{
string guest;
int i;
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 >> i;
switch(i)
{
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);
}

---------------------------------------------------------------------------------------------------

Dr Jack
Hire Me For All Your Tutoring Needs
Quick quotes • Clear explanations • Study support
Chat Now And Get Quote