Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your brother-in-law, the barista, has heard that you're learning to program. He has asked you to program his POS (point of sale) system to handle

Your brother-in-law, the barista, has heard that you're learning to program. He has asked you to program his POS (point of sale) system to handle his new price list. Fortunately, the POS system he has uses Python as its scripting language. You gladly accept the job.

Drinks

This is a simple espresso stand. It only sells three drinks.

Americano

Espresso

Cappuccino

As you can see, he's not local, otherwise he would have to have a Cafe Latte on the menu as well.

Sizes

The drinks come in two sizes.

Medium, 12 oz.

Large, 16 oz.

Prices

The pricing on Americano is the simplest. Mediums are $0.99 per cup; larges, $1.29 per cup.

The pricing on Espresso is a bit more complicated. $1.75 per cup for medium; $2.25 per cup for large. However, there is a volume discount. The mediums are 3 for $4.25; larges are 3 for $5.50.

The pricing on Cappuccino is similar. $2.29 per cup for medium; $2.59 per cup for large. For cappuccino, the volume discount is 10% off for 4 or more cups.

The User Interface

Placing an order requires three pieces of information.

The type of drink The type of drink can be handled using a single character: A E C

The drink size The size can be handled using a single character as well: M L

The quantity The quantity is an integer.

Based on the order, the POS system shall echo the order and calculate the price. All of the drinks in the order will be the same size and kind. The POS system shall collect the information using three separate questions.

Minimal Version

For the minimal version of the assignment, the system needs to handle only a single order. Here is an example. (In the examples which follow, bold is used to show user input is and the underscore character ( _ ) is used to show that the system is waiting for input.)

Enter number of drinks: 5 Enter drink size (M L): M Enter kind of drink (A E C): E The order is 5 medium espressos. Total bill: $7.75

Note: This is 1*$4.25 + 2*$1.75.

The minimal assignment only needs to accept upper-case responses.

Unrecognized input

If the user inputs a non-numeric value for the number of drinks the program shall not crash. The system shall print out an error message and ask again.

Enter number of drinks: 5R Error in number of drinks. Please try again. Enter number of drinks: _

If the number of drinks is not a positive integer value, the system shall print out an error message and ask again.

Enter number of drinks: 5R Error in number of drinks. Please try again. Enter number of drinks: 5.3 Error in number of drinks. Please try again. Enter number of drinks: _

If the user inputs an unrecognized value for the size or kind of drink, the system shall print out an error message and ask again.

Enter number of drinks: 5 Enter drink size (M L): N Error in drink size. Please try again. Enter drink size (M L): _

The system shall keep asking until acceptable input is given. When the order is complete, the system shall echo the order and print out the total cost.

Enter number of drinks: 5R Error in number of drinks. Please try again. Enter number of drinks: 5.3 Error in number of drinks. Please try again. Enter number of drinks: 5 Enter drink size (M L): N Error in drink size. Please try again. Enter drink size (M L): K Error in drink size. Please try again. Enter drink size (M L): M Enter kind of drink (A E C): C The order is 5 medium cappuccinos. Total bill: $10.31

Note: This is 5*$2.29 - 10%, or $11.45 - $1.145. The print-out shall always show cents, that is, have exactly two places after the decimal point. (Just let the system round the way that it wants.)

Notes for the Minimal Version

The judicious use of functions will simplify writing the assignment. You should have functions to handle input, processing, and output.

For example, a function could handle getting the number of drinks from the user. This would include:

displaying the initial prompt for the number of drinks

getting the input from the user

validating the input (checking to make sure that it is numeric and positive)

displaying the error message and asking again when the input is invalid

returning the validated input value

Each of the three input questions can be handled in this way.

Similarly, handling the calculation of the price can be separated into three different functions, one for each kind of drink. You can have a single function to get the price. It should take the number, size, and kind of drink as three parameters. Looking forward (if you read the extra-credit option), it will be best if this function returns the calculated price. This single price function can call the drink-specific price calculation functions.

And finally, you can create a function that will format and print the output. This is echoing the order and giving the total price.

One of the primary benefits of making all these smaller, separate functions is that you can work on them independently of each other. So, for example, once you have the calculations for espresso drinks working, you don't have to mess with that code (and possibly mess it up) when you go to work on prices for a different kind of drink.

Another benefit of breaking the problem and its solution into smaller chunks, it makes the problem and its solution (the resulting code) more easy to understand and more manageable. In fact, the main for the minimal assignment can just call a few functions. Here it is in pseudo code.

get the number of drinks get the drink size get the kind of drink calculate the price print out the summary

Standard Version

For the standard version of the assignment, the POS system will be modified to handle multiple orders. After completing one order, the system shall ask if there is another order. If the answer is yes, the system prompt again for the new order. The single character 'y' is sufficient. The system shall also keep a running total of the orders filled. After the last order, the total value of the orders for the system shall be displayed.

The order is 5 medium cappuccinos. Total bill: $10.31 Is there another order? Y Enter the number of drinks: _

The blank response, just pressing the return key, shall also be interpreted as 'yes'.

The order is 5 medium cappuccinos. Total bill: $10.31 Is there another order? Enter the number of drinks: _

Any response to this question which is neither 'y' nor empty shall be interpreted as "no" and the system shall end.

The order is 5 medium cappuccinos. Total bill: $10.31 Is there another order? B Total orders for the day: $156.28

Remember that the running total of the orders needs to be kept by the system. The grand total shall be printed with exactly two places after the decimal. (Note: depending on your implementation, the grand total could be off from what you might expect, based on adding the total bill figures for the individual orders. This is due to rounding errors. However, it should not be off by more cents than the number of orders. So, if there were 15 orders, you would expect the grand total to be within 15 cents of sum of the 15 total bill figures given during the run of the program.)

In the standard version of the assignment, the POS system shall accept lower-case input as equivalent to upper-case.

Notes for the Standard Version

The use of functions to get the input and calculate the output should make moving from the minimal version to the standard version much easier. In fact, the change should be limited to main, the driver function that just calls the other "worker" functions

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_2

Step: 3

blur-text-image_3

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 Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions

Question

5-8 What are the advantages and disadvantages of the BYOD movement?

Answered: 1 week ago