Return to Snippet

Revision: 20871
at November 28, 2009 15:28 by skyhook322


Initial Code
COMP 1030 - Computer Programming Concepts
Assignment 2, Fall 2009



Write the Python code for the following programming problem.  Please draw the corresponding flowchart also. You may do it by hand or use any software program. Raptor won�t work since it supports a repeat loop (both post-test and pre-test) where as Python only supports the while loop.
Write a modular 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: 
o	Yum Yum Burger = $0.99
o	Grease Yum Fries = $0.79
o	Soda Yum = $1.09

�	Allow 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 the sub-totals and the total. Add a 6% sales tax to total to produce the final purchasing price. 
�	Print to the screen a receipt showing the total of each item purchased, the sub-total of each item purchased (number purchased by price), the total, the tax and then and the final purchase price. Printing will have to be accomplished in parts in two functions as described below.

Functions:
�	main function that controls the program and calls on the other functions. 
�	getOrderNumber() that inputs the order number (must be >= 0) and returns it to the main function.
�	takeOrderAndCalculateTotal() that takes the order, calculates the sub-totals and the total value of the order. This function also prints part of the receipt (lines 1-8 in the receipt) that involves the heading, number of items purchased, the sub-totals and total. It returns the total to the calling (main) function.
�	calculateTax(total) that takes as input the total and calculates the tax on it. It returns the tax calculated.
�	calculateFinalPrice(total, tax) and calculates the final purchase price. It also prints the rest of the receipt (lines 9-11) that involves the tax and the final purchasing price and the trailing �=�.

Notes:
�	The program should be well documented. Your name, date and purpose at the beginning, the purpose of each function before its definition at the minimum. Please do not clutter your code with unnecessary comments though.
�	The program runs while the order number is not equal to zero. 
�	The valid input in getOrderNumber() for order number is a value >= 0. In case of invalid input, display an error message and let the user re-enter till a valid value is provided.
�	The only valid choices for the menu items in takeOrderAndCalculateTotal()  are 1, 2 and 3. Validate the choice, giving appropriate error message in case of invalid input. Allow user to re-enter till a valid choice is input.
�	The number of items purchased in takeOrderAndCalculateTotal() can be from 1 through 20. Validate the input. Display error message in case of invalid input and allow user to re-enter till a valid value is entered.
�	The user can enter either yes or no as response to the question in takeOrderAndCalculateTotal()

Do you want to end your order? (Enter yes or no):  

The corresponding loop should execute while the response is no. The condition should check for �no� though the user can input in any combination of lower or upper case (no, No etc.). Use the pre-defined function lower of the String class to check for any case-sensitive input.
�	Please declare and use named �constants� for the prices and the sales tax in functions where they are needed and do not use any �magic numbers� in your code, either for calculations or for displaying purposes.


Sample Input and Output :

	Please enter order number (>0). Enter 0 to stop the program : 1

	START ORDER : 1

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now -> 1
Enter the number of burgers you want : 3

Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now -> 3
Enter the number of sodas you want : 2

Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now -> 1
Enter the number of burgers you want : 1

Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now -> 2
Enter the number of fries you want : 2

Do you want to end your order? (Enter yes or no): yes

==================== R E C E I P T ============================
Number of burgers ordered		:4
Sub-total (@ $.99 each)		:$3.96
Number of fries ordered		:2
Sub-total (@ $.89 each)		:$1.58
Number of sodas ordered		:2
Sub-total (@ $1.09 each)		:$2.18
Total						:$7.72
Tax at 6%					:$0.46
Final Purchase Price 			:$8.18

Please enter order number (>0). Enter 0 to stop the program : 2


START ORDER : 2

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now -> 2
Enter the number of fries you want : 2

Do you want to end your order? (Enter yes or no): no

Enter 1 for Yum Yum Burger
Enter 2 for Grease Yum Fries
Enter 3 for Soda Yum
Enter now -> 3
Enter the number of sodas you want : 2

Do you want to end your order? (Enter yes or no): yes

==================== R E C E I P T =============================
Number of burgers ordered		:0
Sub-total (@ $.99 each)		:$0.00
Number of fries ordered		:2
Sub-total (@ $.99 each)		:$1.58
Number of sodas ordered		:2
Sub-total (@ $1.09 each)		:$2.18
Total						:$3.76
Tax at 6%					:$0.22
Final Purchase Price 			:$3.98


Please enter order number (>0). Enter 0 to stop the program : 0



HOW TO SUBMIT:

1)	Please submit the flowchart and the Python code (.py file) as two different attachments via blackboard link for Assignment 2. 
2)	Submit me a hard copy of both these attachments, with your name on it.

Initial URL


Initial Description


Initial Title
my assignment in python

Initial Tags


Initial Language
Other