Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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,

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 only wait in the normal customers queue, and VIP customers can only wait in the VIP customers queue.

Each time a new customer comes; the user should input the customer name and whether he/she is VIP, then put the user in the corresponding queue.

You should always serve VIP customers first! When add/ serve customers, you also need to print out the current customer name, and names of all customers in each queue.

If you want to add one customer but the corresponding queue is full, your program should print: Error: Normal customers queue is full or Error: VIP customers queue is full. When you want to serve one customer, if both queues are empty, your program should print: Error: Both queues are empty.

You may restrict the capacity of each queue to 3 for testing simplicity.

Each queue (normal or VIP) should be an instance of the CircularQueue class. Therefore, this class should be included in your program.

Following is the output from a sample run of the program:

Add, Serve, or Exit: add

Enter the name of the person to add: Alice

Is the customer VIP? False

add Alice to the line.

people in the line: ]Alice]

VIP customers queue: ]]

Add, Serve, or Exit: add

Enter the name of the person to add: Bob

Is the customer VIP? False

add Bob to the line.

people in the line: ]Alice, Bob]

VIP customers queue: ]]

Add, Serve, or Exit: add

Enter the name of the person to add: John

Is the customer VIP? False

add John to the line.

people in the line: ]Alice, Bob, John]

VIP customers queue: ]]

Add, Serve, or Exit: add

Enter the name of the person to add: Mike

Is the customer VIP? True

add Mike to VIP line.

people in the line: ]Alice, Bob, John]

VIP customers queue: ]Mike]

Add, Serve, or Exit: add

Enter the name of the person to add: Lucy

Is the customer VIP? True

add Lucy to the line. people in the line: ]Alice, Bob, John]

VIP customers queue: ]Mike, Lucy]

Add, Serve, or Exit: add

Enter the name of the person to add: Wilson

Is the customer VIP? False

Error: Normal customer queue is full

people in the line: ]Alice, Bob, John]

VIP customers queue: ]Mike, Lucy]

Add, Serve, or Exit: serve

Mike has been served

people in the line: ]Alice, Bob, John]

VIP customers queue: ]Lucy]

Add, Serve, or Exit: serve

Lucy has been served

people in the line: ]Alice, Bob, John]

VIP customers queue: ]]

Add, Serve, or Exit: serve

Alice has been served

people in the line: ]Bob, John]

VIP customers queue: ]]

Add, Serve, or Exit: serve

Bob has been served

people in the line: ]John]

VIP customers queue: ]]

Add, Serve, or Exit: serve

John has been served

people in the line: ]]

VIP customers queue: ]] Add, Serve, or Exit: serve

Error: Queues are empty

people in the line: ]]

VIP customers queue: ]]

Add, Serve, or Exit: exit Quitting

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Joline Morrison, Mike Morrison

2nd Edition

? 061906448X, 978-0619064488

Students also viewed these Databases questions

Question

7. Where Do We Begin?

Answered: 1 week ago