Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Manage the queue at the Secretary of State office Objectives To understand how to use a menu of possible actions repeatedly with a sentinel loop,

Manage the queue at the Secretary of State office

Objectives

To understand how to use a menu of possible actions repeatedly with a sentinel loop, understand how to add and remove elements of a list, and think about how to create a more complicated program by breaking it into manageable pieces.

Description

Imagine that we are creating an app to manage the queue at the Secretary of State office. As customers arrive, they are added to the end of the queue. When workers are available to help the customers, they will call the name of the first person in the queue, and remove them from the queue. Another option for the app is to print out the entire queue so customers can see where they stand.

The menu options are (1) Add a customer to the queue (2) Serve the customer (3) Print out the queue (4) Quit the application.

At the beginning of the day, the queue is empty. When a customer is added to the queue, you will have to prompt for the customer's name. When a customer is served, you should print the message "Now serving customer Jon." if the first name in the queue is Jon, so Jon is called to the counter and removed from the queue.

If the app user enters anything besides '1', '2', '3', or '4', you should print out the message "Unknown menu option." and display the menu again. When the user enters the option 4, the program should just exit without printing anything.

NOTE: You should think about handling the case where the user tries to serve a customer when there are no customers in the queue. If that happens, you should print out the message "No customers to serve.". Get everything else working first, then work on that part.

Following is an example run of what the program should look like after 'jon', 'ben', and 'anika' have already been added to the queue:

(1) Add a customer to the queue. (2) Serve customer. (3) Print queue. (4) Exit. 1 What is the customer's name? bridget (1) Add a customer to the queue. (2) Serve customer. (3) Print queue. (4) Exit. 3 ['jon', 'ben', 'anika', 'bridget'] (1) Add a customer to the queue. (2) Serve customer. (3) Print queue. (4) Exit. 2 Now serving customer jon. (1) Add a customer to the queue. (2) Serve customer. (3) Print queue. (4) Exit. 3 ['ben', 'anika', 'bridget'] (1) Add a customer to the queue. (2) Serve customer. (3) Print queue. (4) Exit. 4 

To attack a problem such as this one, you need to think about the structure of the program without getting bogged down in the details at first. It is a good strategy to get the menu and loop structure working first. To do this, for each menu option you can simply print out a statement like "add customer to queue", "print the queue" etc as the user enters the appropriate option. Then once you know that part is all working correctly, substitute the print statements with the code that will actually manipulate the queue. Look at zyDE 9.6.1 for inspiration, and make changes as needed for this problem.

If you ask the TAs for help on this lab, the first thing they will do is ask to see your thought processes. They will not help you with any code until you can describe your process to them. And you should not write any code before you understand how the structure of the program will work and have written down the steps. You can write down your thought processes on paper, or in the form of comments in a .py file that you will then add code to around the comments.

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

Advances In Databases And Information Systems 14th East European Conference Adbis 2010 Novi Sad Serbia September 2010 Proceedings Lncs 6295

Authors: Barbara Catania ,Mirjana Ivanovic ,Bernhard Thalheim

2010th Edition

3642155758, 978-3642155758

More Books

Students also viewed these Databases questions

Question

2. Define communication.

Answered: 1 week ago