Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part IlI: Bullding Burgers (6 points) (Place your answer to this problem in the 'burgerpy file) Burgers-To-Go has hired you to develop a new food

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Part IlI: Bullding Burgers (6 points) (Place your answer to this problem in the "'burgerpy" file) Burgers-To-Go has hired you to develop a new food ordering system for its customers. Each customer will type in a code representing the structure of his or her order, and your program will calculate the total cost of the order. An order code is defined as a (case-sensitive) string of letters; each letter represents some element of the burger (the protein type, a topping, or a condiment). The valid codes for protein types, toppings, and condiments are as follows: Protein Toppings ($0.50 each) Condiments (free) Letter Condiment Letter Patty Type Price $2.00 T Turkey $2.50 V Veggie $2.25 Letter Topping k Ketchup u Mustard y Mayonnaise a A.1. steak sauce q Barbecue sauce 1 Lettuce t Tomato o Onion p Pickle 1 Jalapeo peppers c Cheese b Bacon s Sauted onions m Sauted mushrooms f Fried onions B Beef For example, "T mmy" re resents a turkey burger with pickle, hea ($4.50), while "Bcbgg" represents a beef hamburger with cheese, bacon, and heavylextra barbecue sauce ($3.00) vylextra sauted mushrooms, lettuce, and mayonnaise Complete the burger) function, which takes a single string parameter representing a customer order. This function returns either a number or a string, depending on the contents of its parameter. Your function should process its parameter one character at a time (a for loop is a good way to do this), keeping track of several values: The type of protein that has been ordered . The total number of toppings that have been ordered The total number of condiments that have been ordered A valid order MUST include exactly one protein, plus up to five toppings and up to two condiments. The elements of an rder may hr arraneed in any order; for example, condiments and toppings may be mixed together, 'with the protein type at order may be arranged in any order; for example, condiments and toppings may be mixed together, with the protein type at the end. Toppings and condiments may be repeated (indicating extra quantities of that topping or condiment); repeating a topping or condiment still counts toward the limit for that type of element, so 3 t' Ctomato") characters will only allow the customer to add up to 2 additional toppings (likewise, 2 copies of a single condiment means that no additional condiments may be ordered) If the parameter string is a valid order (exactly one protein, 0-5 toppings, and 0-2 condiments), your function should return a float representing the total cost of the order: protein cost + (0.5 x number of toppings) (don't worry if the cost doesn't have exactly two digits after the decimal point) If the order is invalid because it contains too many protein types (or no protein type at all), or because it contains too many toppings or condiments, your function should return the exact string "invalid order" (all lowercase). - If the parameter string contains an invalid character (e.g, an 'x', which is not present in any of the three tables above), your function should immediately terminate and return the exact string "unrecognized order code" (all lowercase). Hint: You can simplify your classification tests by using the 1n operator with a single string that holds all the valid letters for that category. For example, letter in BTV" will return True if the variable letter matches any protein type. CSE 101 (Section 01)-Spring 2019 Lab #3 Page 5 Your general logical structure will probably look something like the following: e protein toppings0 e condiments 0 For each character in the parameter o If the current character is a protein type: Ifprotein is currently "", set it to the current character (and optionally record the price in a new variable Otherwise, return an "invalid order" message (to reflect the extra protein) Your general logical structure will probably look something like the following: e protein. e toppings0 e condiments0 For each character in the parameter: o If the current character is a protein type: Ifprotein is currently, set it to the current character (and optionally record the price in a new variable . Otherwise, return an "invalid order" message (to reflect the extra protein) o Otherwise, if the current character represents a topping: If toppings is less than 5, increment its value by1 Otherwise, return an invalld order message (to reflect too many toppings) o Otherwise, if the current character represents a condiment: If condiment s is less than 2, increment its value by 1 Otherwise, return an "invalid order" message (to reflect too many condiments) o Otherwise, return an "unrecognized order code" error message. . If protein is equal to the empty string.", return the invalid order" error message Otherwise, calculate and return the total cost of the order Examples: Function Call Return Value Notes burger (Bck") burger ("Tpmlmy) 4.5 burger ("altop") burger ("VtojsT*) burger ("Isucjv") burger ("Bqebkamfy") invalid order burger ("Toxpk") 2.5 Valid: Beef burger with cheese and ketchup Vald: Turkey burger with assorted add-ons No protein option included Two protein options selected Valid, even though the protein is at the end Too many condiments ordered invalid order invalid order 4.25 unrecognized order code is not a valid option o Otherwise, if the current character represents a topping: If toppings is less than 5, increment its value by 1 Otherwise, return an "invalid order" message (to reflect too many toppings) o Otherwise, if the current character represents a condiment: If condiments is less than 2, increment its value by 1 Otherwise, return an "invalid order" message (to reflect too many condiments) o Otherwise, return an "unrecognized order code" error message. .Iprotein is equal to the empty string ", return the invalid order error message. . Otherwise, calculate and return the total cost of the order Examples: Function Call Return Value Notes burger ("Bck burger ("Tpmlmy4.5 burger ("altop") burger ("VtojsT*) burger ("lsucjv") burger("Bqcbksmfy") invalid order burger(*Toxpk.) burger ("Vqltopjn*) nvalid order Valid: Beef burger with cheese and ketchup Valid: Turkey burger with assorted add-ons No protein option included Two protein options selected Valid, even though the protein is at the end Too many condiments ordered 2.5 invalid order invalid order 4.25 unrecognized order code x is not a valid option Too many toppings ordered

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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

List the advantages and disadvantages of the pay programs. page 505

Answered: 1 week ago