Student Lab 1: Input, Processing, and Output



Lab 5: Repetition StructuresThis lab accompanies Chapter 5 of Gaddis, T. (2016). Starting out with programming logic and design (4th ed.). Boston, MA: Addison-Wesley.Lab 5.5 – Programming Challenge 1 – Yum Yum Burger JointWrite the Flowchart for the following programming problem and the pseudocode below. A restaurant wants you to write a program that will calculate the cost of purchasing a meal. This program will include decisions and loops. Details of the program are as follows:Your menu items only include the following food with accompanied price: Yum Yum Burger = .99Grease Yum Fries = .79Soda Yum = 1.09Allow the user of the program to purchase any quantity of these items on one order. Allow the user of the program to purchase one or more types of these items on one order.After the order is placed, calculate total and add a 6% sales tax. Print to the screen a receipt showing the total purchase price.Your sample output might look as follows:Enter 1 for Yum Yum BurgerEnter 2 for Grease Yum FriesEnter 3 for Soda YumEnter now ->1Enter the number of burgers you want 3Do you want to end your order? (Enter yes or no): noEnter 1 for Yum Yum BurgerEnter 2 for Grease Yum FriesEnter 3 for Soda YumEnter now ->3Enter the number of sodas you want 2Do you want to end your order? (Enter yes or no): noEnter 1 for Yum Yum BurgerEnter 2 for Grease Yum FriesEnter 3 for Soda YumEnter now ->1Enter the number of burgers you want 1Do you want to end your order? (Enter yes or no): noEnter 1 for Yum Yum BurgerEnter 2 for Grease Yum FriesEnter 3 for Soda YumEnter now ->2Enter the number of fries you want 2Do you want to end your order? (Enter yes or no): yesThe total price is $ 8.1832Do you want to end program? (Enter no to process a new order): noEnter 1 for Yum Yum BurgerEnter 2 for Grease Yum FriesEnter 3 for Soda YumEnter now ->2Enter the number of fries you want 2Do you want to end your order? (Enter yes or no): noEnter 1 for Yum Yum BurgerEnter 2 for Grease Yum FriesEnter 3 for Soda YumEnter now ->3Enter the number of sodas you want 2Do you want to end your order? (Enter yes or no): yesThe total price is $ 3.9856Do you want to end program? (Enter no to process a new order): yesThe PseudocodeModule main() Call declareVariables(endProgram, endOrder, totalBurger, totalFry, totalSoda, total, tax, subtotal, option, burgerCount, fryCount, sodaCount)//Loop to run program againWhile endProgram == “no”Call resetVariables(totalBurger, totalFry, totalSoda, total, tax, subtotal)//Loop to take in orderWhile endOrder == “no”Display “Enter 1 for Yum Yum Burger”Display “Enter 2 for Grease Yum Fries”Display “Enter 3 for Soda Yum”Input optionIf option == 1 ThenCall getBurger(totalBurger, burgerCount)Else If option == 2 ThenCall getFry(totalFry, fryCount)Else If option == 3 ThenCall getSoda(totalSoda, sodaCount)End IfDisplay “Do you want to end your order? (Enter no to add more items: )”Input endOrderEnd WhileCall calcTotal(burgerTotal, fryTotal, sodaTotal, total, subtotal, tax)Call printReceipt(total)Display “Do you want to end the program? (Enter no to process a new order)”Input endProgramEnd WhileEnd ModuleModule declareVariables(String Ref endProgram, String Ref endOrder, Real Ref totalBurger, Real Ref totalFry, Real Ref totalSoda, Real Ref total, Real Ref tax, Real Ref subtotal, Real Ref option, Real Ref burgerCount, Real Ref fryCount, Real Ref sodaCount)Declare String endProgram = “no”Declare String endOrder = “no”Declare Real totalBurger = 0Declare Real totalFry = 0Declare Real totalSoda = 0Declare Real total = 0Declare Real tax = 0Declare Real subtotal = 0Declare Integer option = 0Declare Integer burgerCount = 0Declare Integer fryCount = 0Declare Integer sodaCount = 0End ModuleModule resetVariables (Real Ref totalBurger, Real Ref totalFry, Real Ref totalSoda, Real Ref total, Real Ref tax, Real Ref subtotal)//reset variablestotalBurger = 0totalFry = 0totalSoda = 0total = 0tax = 0subtotal = 0End ModuleModule getBurger(Real Ref totalBurger, Integer burgerCount)Display “Enter the number of burgers you want”Input burgerCountSet totalBurger = totalBurger + burgerCount * .99End ModuleModule getFry(Real Ref totalFry, Integer fryCount)Display “Enter the number of fries you want”Input fryCountSet totalFry = totalFry + fryCount * .79End ModuleModule getSoda(Real Ref totalSoda, Integer sodaCount)Display “Enter the number of sodas you want”Input sodaCountSet totalSoda = totalSoda + sodaCount * 1.09End ModuleModule calcTotal(Real totalBurger, Real totalFry, Real totalSoda, Real Ref total, Real subtotal, Real tax)Set subtotal = totalBurger + totalFry + totalSodaSet tax = subtotal * .06Set total = subtotal + taxEnd ModuleModule printReceipt(Real total)Display “Your total is $”, totalEnd ModuleThe FlowchartPASTE FLOWCHART HEREThe Python Code for Review#the main functiondef main(): endProgram = 'no' print while endProgram == 'no': totalBurger = 0 totalFry = 0 totalSoda = 0 endOrder = 'no' while endOrder == 'no': print print 'Enter 1 for Yum Yum Burger' print 'Enter 2 for Grease Yum Fries' print 'Enter 3 for Soda Yum' option = input('Enter now ->') if option == 1: totalBurger = getBurger(totalBurger) elif option == 2: totalFry = getFry(totalFry) elif option == 3: totalSoda = getSoda(totalSoda) else: print 'You have entered an invalid option!!!' endOrder = raw_input('Do you want to end your order? (Enter yes or no): ') print total = calcTotal(totalBurger, totalFry, totalSoda) printReceipt(total) endProgram = raw_input('Do you want to end program? (Enter no to process a new order): ') #this function will get burger orderdef getBurger(totalBurger): burgerCount = input('Enter the number of burgers you want ') totalBurger = totalBurger + burgerCount * .99 return totalBurger#this function will get fry orderdef getFry(totalFry): fryCount = input('Enter the number of fries you want ') totalFry = totalFry + fryCount * .79 return totalFrydef getSoda(totalSoda): sodaCount = input('Enter the number of sodas you want ') totalSoda = totalSoda + sodaCount * 1.09 return totalSodadef calcTotal(totalBurger, totalFry, totalSoda): subtotal = totalBurger + totalFry + totalSoda tax = subtotal * .06 total = subtotal + tax return totaldef printReceipt(total): print 'The total price is $', total # calls mainmain() ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download