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

Please answer in C++!! Create a class named waitList that can store a name and n

ID: 666774 • Letter: P

Question

Please answer in C++!!

Create a class named waitList that can store a name and number of guests. Use constructors to automatically initialize the member variables.

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

Create a main program to test your class. Your main program should contain the following options. Create a menu for your 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

Thank you!!

Explanation / Answer

#include <stdio.h>
#define MAX 50
int queue_array[MAX];
int rear = - 1;
int front = - 1;
main()
{
    int choice;
    while (1)
    {
        printf("1.Insert element to queue ");
        printf("2.Delete element from queue ");
        printf("3.Display all elements of queue ");
        printf("4.Quit ");
        printf("Enter your choice : ");
        scanf("%d", &choice);
        switch (choice)
        {
            case 1:
            insert();
            break;
            case 2:
            delete();
            break;
            case 3:
            display();
            break;
            case 4:
            exit(1);
            default:
            printf("Wrong choice ");
        } /*End of switch*/
    } /*End of while*/
} /*End of main()*/
insert()
{
    int add_item;
    if (rear == MAX - 1)
    printf("Queue Overflow ");
    else
    {
        if (front == - 1)
        /*If queue is initially empty */
        front = 0;
        printf("Inset the element in queue : ");
        scanf("%d", &add_item);
        rear = rear + 1;
       queue_array[rear] = add_item;
    }
} /*End of insert()*/
delete()
{
    if (front == - 1 || front > rear)
    {
        printf("Queue Underflow ");
        return ;
    }
    else
    {
        printf("Element deleted from queue is : %d ", queue_array[front]);
        front = front + 1;
    }
} /*End of delete() */
display()
{
    int i;
    if (front == - 1)
        printf("Queue is empty ");
    else
    {
        printf("Queue is : ");
        for (i = front; i <= rear; i++)
            printf("%d ", queue_array[i]);
       printf(" ");
    }
} /*End of display() */