Question

You will design a program to keep track of a restaurants waitlist using a queue implemented...

You will design a program to keep track of a restaurants waitlist using a queue implemented with a linked list.

  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:
    1. Return the first person in the queue
    2. Return the last person in the queue
    3. Add a person to the queue
    4. Delete a person from the queue
  3. Create a main program to test your class. Your main program should contain the following options.
    1. Add a guest (adds the reservation name and number of guests)
    2. 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)
    3. Show last guest waiting (return NONE if the queue is empty)
    4. Show first guest waiting (return NONE if the queue is empty)
    5. Exit (Language: C++)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

//c++ program for QUEUE using linked list for waitList class

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <string>
#include <string.h>
using namespace std;

//node class definition for data and links
class node
{
public :
string name;
int guestnum;
node *next;

};

//waitList class is implemented various operations

class waitList:public node
{
node *head;
int front,rare;
public :

//constructor taking default data
waitList()
{
front=-1;
rare=-1;
head =new node;
head->next=NULL;
head->name="jklji";
head->guestnum=6;
rare ++;
}

//push method to add data to list

void push(string nm,int x)
{
if (rare < 0 )
{
head =new node;
head->next=NULL;
head->name=nm;
head->guestnum=x;
rare ++;
}
else
{
node *temp,*temp1;
temp=head;
rare++;
while(temp->next != NULL)
temp=temp->next;
temp1=new node;
temp->next=temp1;
temp1->next=NULL;
temp1->name=nm;
temp1->guestnum=x;
} }

//displaying all data in wait list

void display()
{
node *temp;
temp=head;
if (rare < 0)
{
cout <<" queue under flow";
return;
}
while(temp != NULL)
{
cout <<temp->name<< " "<<temp->guestnum<<endl;
temp=temp->next;
}
}

//removing head node using pop method
void pop()
{
node *temp;
temp=head;
if( rare < 0 || front >rare)
{
cout <<"queue under flow";
return;
}
if(front == rare)
{
front = rare =-1;
head=NULL;
return;
}
front++;
head=head->next;
}

//del method for removing node if name equals to any node name.
void del(string nm)
{
node *temp,*temp1;
temp=head;
if( rare < 0)
{
cout <<"queue under flow";
return;
}
if(temp->name==nm)
{
cout<<temp->name<<"data node is deleting"<<endl;
head=temp->next;
rare--;
return;
}
while((temp != NULL))
{
if(temp->name==nm)
{
cout<<temp->name<<"data node is deleting"<<endl;
temp1->next=temp->next;
rare--;
return;
}
temp1=temp;
temp=temp->next;

}

}

//shows first node name
string showfirst()
{
if( rare < 0)
{
cout <<"queue under flow";
return NULL;
}
return head->name;
}

//shows last node name
string showlast()
{

node *temp;
temp=head;
if( rare < 0)
{
cout <<"queue under flow";
return NULL;
}
while(temp->next != NULL)
{
temp=temp->next;
cout<<"nm"<<temp->name;
}

return temp->name;
}
};
int main()
{
string name;
waitList obj;

int numguest;
int ch;
while(1)
{
cout <<"\nQUEUE OPERATIONS :\n1.PUSH\n2.POP\n3.DISPLAY\n4.OTHER OPERATIONS\n enter your choice:\n";
cin >> ch;
switch(ch)
{
case 1:
cout <<"\n enter restaurant name and number of guests :";
cin>>name;
cin>>numguest;
obj.push(name,numguest);
break;

case 2: obj.pop();
break;
case 3: obj.display();
break;
case 4: while(1)
{
cout <<"\nOTHER OPERATIONS :\n1.ADD \n2.DELETE\n3.SHOW FIRST GUEST\n4.SHOW LAST GUEST\n5.DISPLAY\n6.EXIT\n enter your choice:\n";
cin >> ch;
switch(ch)
{
case 1:
cout <<"\n enter restaurant name and number of guests :";
cin>>name;
cin>>numguest;
obj.push(name,numguest);
break;

case 2: cout <<"\n enter name of guest to delete :";
cin>>name;
obj.del(name);
break;
case 3: name=obj.showfirst();
cout<<"first person is:"<<name;
break;
case 4: name=obj.showlast();
cout<<"last person is:"<<name;
break;
case 5: obj.display();
break;
case 6: exit(0);
default: cout<<"Invalid choice.Try again\n";
}
};
default: cout<<"Invalid choice.Try again\n";
}
}

return 0;
}

//output of the screenshot is shown below

X D:\Users\ssssss\Documents\qu.exe QUEUE OPERATIONS: 11.PUSH 2.POP 3.DISPLAY 4.OTHER OPERATIONS enter your choice: 3 jklji 6

Add a comment
Know the answer?
Add Answer to:
You will design a program to keep track of a restaurants waitlist using a queue implemented...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • below i added the code, but while running it, makefile.win error showing. how i fix this?...

    below i added the code, but while running it, makefile.win error showing. how i fix this? 1.)waitlist.h #include<iostream> using namespace std; class guest{    public:    string name;    guest*next;    guest*prev;    guest(string);    }; class waitList{    int numberOfGuests;    guest* first;    guest* last;    public:        waitList();        void addPerson(string);        void deletePerson(string);        guest* getFirst();        guest* getLast();    }; 2.)waitlist.cpp #include<iostream> #include"waitlist.h" using namespace std; guest::guest(string name){    this->name...

  • Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names...

    Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names and phone numbers. ·         a. Define a class contactList that can store a name and up to 3 phone numbers (use an array for the phone numbers). Use constructors to automatically initialize the member variables. b.Add the following operations to your program: i. Add a new contact. Ask the user to enter the name and up to 3 phone numbers. ii. Delete a contact...

  • Please use C++,thank you! Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, o...

    Please use C++,thank you! Write an AddressBook class that manages a collection of Person objects. Use the Person class developed in question 2. An AddressBook will allow a person to add, delete, or search for a Perso n object in the address book The add method should add a person object to the address book. The delete method should remove the specified person object from the address book 0 .The search method that searches the address book for a specified...

  • CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class....

    CS 373 Home Work project 11 Create a queue class by priviate inherting the unorderedArrayListType class. A queue class is a First-In-First-Out data structure. To understand a queue, think of a checkout line at a grocery store: the person at the front is served first (removed), and people are added to the line from the back end. class queue : private unorderedArrayListType { public: bool isEmpty() const; // test whether queue is empty // Post: returns true if queue is...

  • Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user...

    Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...

  • // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. //...

    // Java Queue LinkedList Assignment // A queue is implemented using a singly linked list. // the variable: back "points" at the first node in the linked list // new elements ( enqueued) are added at the back // the variable: front "points" at the last node in the linked list. // elements are removed (dequeued) from the front // // Several queue instance methods are provided for you; do not change these // Other instance methods are left for...

  • Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds value...

    Array-based Queue Lecture 6 Two Class Exercises | Class Exercise #1 - Create an array-based queue that holds values of double data type. 1.) Create a program that produces the following output OUTPUT: Q Quit Enter your choice: e Enter an item: 1.1 E Enqueue D Dequeue s-show queue ← showMenuO function called in main) OQuit // screen clears-.. continue enqueuing.screen clearing with each iteration Enter your choice: e Queue is full. E Enqueue D Dequeue s Show queue 0...

  • (JAVA) Using classes and inheritance, design an online address book to keep track of the names

    (JAVA)Using classes and inheritance, design an online address book to keep track of the names, addresses, phone numbers and birthdays of family members, friends and business associates. Your program should be able to handle a maximum of 500 entries.Define the following classes: Class Address to store a street name, city, state and zip code. Class Date to store the day, month and year. Class Person to store a person's last name and first name. Class ExtPerson that extends the class...

  • In this lab, using C++, you will create an abstract data type, using a doubly-linked circular...

    In this lab, using C++, you will create an abstract data type, using a doubly-linked circular structure to store the values and links. You must create it by your own and not use any existing containers. You will need a QueueNode. You can use a struct for this, as each node will not have any associated functions. It will have members for data, and the next and previous pointers. Data will be positive integers. There will be no NULL pointers....

  • language:python VELYIEW Design a program that you can use to keep information on your family or...

    language:python VELYIEW Design a program that you can use to keep information on your family or friends. You may view the video demonstration of the program located in this module to see how the program should function. Instructions Your program should have the following classes: Base Class - Contact (First Name, Last Name, and Phone Number) Sub Class - Family (First Name, Last Name, Phone Number, and Relationship le. cousin, uncle, aunt, etc.) Sub Class - Friends (First Name, Last...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT