CIS 331 Assignment #4 CIS 221 PA5 – Grocery Transaction This is an individual assignment. Your program code must be your own work. Objectives from previous PAs plus: · Use dialog boxes for user input...

1 answer below »
Everything is on the attached file, please keep it as simple as possible, as this is an introductory python course


CIS 331 Assignment #4 CIS 221 PA5 – Grocery Transaction This is an individual assignment. Your program code must be your own work. Objectives from previous PAs plus: · Use dialog boxes for user input and message output · Correctly use global and local variables · Structure program tasks as functions · Correctly call functions; return a value from a function Read through all of the instructions before beginning your work. For this assignment, you will write a program that reads sales data from a text file, and then allows the user to enter coupon amounts, calculate discount, and calculate a final sales total. The program will then print a receipt to the screen, displaying the details of the transaction. The discount and coupon options can be executed in any order and multiple times. Once the sales total has been calculated and displayed, the program will end. The text file contains one line of text for each item purchased. Each line consists of the item name and the price, with comma delimiters (remember that each line, except for the last one, also contains a newline character, even though we can’t see it in the text file). Things to consider for writing a well-structured program: · Any validation of menu input should check against one, and only one, value (letter). Instead of checking against “d” and “D”, for example, use the appropriate method so that only one check is needed. · Think about any values that should be created as named constants - set them up as such. · If an input modification or a calculation results in a value that will be needed later, use an assignment so that the same modification or calculation doesn’t have to be done multiple times. · In addition to sys, you will need to import some tkinter functionality for the dialog boxes. Use the following at the beginning of your program: · You will need multiple global variables; it’s also good practice to initialize lists and named constants at the beginning of the program. You’ll need lists for items, item prices, and coupon amounts. You’ll need global variables for item total, coupon total, discount amount, and card number. · Tackle one task at a time. Make sure you can successfully read in the file data before displaying the menu. Then work on validating menu options, then work on the remaining functions. Before you begin coding, read through the instructions and get familiar with what the program should do. Along with your flowchart/pseudocode, identify which variables and/or lists will be used in each of the functions. Determine whether a function is simply using the value of a variable or changing it – this will impact how you identify that variable inside the function. Expected Behavior of your Program Your program will have a total of 5 functions. The main() function will call a function asks for a file name, then reads the data from that file; this readdata() function will use try/except for the file input and list creation, breaking the initial large list into two lists: one containing each item purchased and one containing the purchase price. Once the 2 lists have been created, get the sum of all the prices to find the item total. Any problems in the above processing should trigger an exception with an appropriate message, and the program should end. (HINT: since the menu is displayed in the main() function, after it displays the message, the readdata() function can return a value that would prevent the menu from displaying and end the program.) At this point, the program will end. Any valid file name should work. These screen shots show 2 examples of the file name being hard-coded – this is not acceptable and will result in lost points. The program must accept any file that contains valid data. If a valid file name is entered, display a message in a dialog box. When the user clicks “OK”, the text menu will appear in the shell. Menu functionality: Once the file data is ready for processing, the program should return to the main() function and should repeatedly present a menu of options, as shown below, until a) the user enters ‘e’ to Exit or b) the total has been printed and the transaction is complete. These are the only allowable options – the user should be able to enter lower- or uppercase letters and your program should use the most efficient way of validating the input. An invalid entry should trigger an error message, and again present the menu, like this: With a grocery checkout transaction, the tasks don’t necessarily all have to be completed in a specific order. We can enter a coupon, get the customer’s card number, enter another coupon, etc. Some tasks may not execute at all. If the customer has no coupons, there’s no need to run that part of the program. What this means is that each unique task should be coded within a function – a particular function is called only if the user says they want to do that task. Taking another look at the menu, we can see that in addition to the main() and readdata() functions, the program should have the following functions: · coupons() · discount() · total() The coupon() function should allow the user to enter as many coupons as they want, then should display the coupon total before returning to main() to redisplay the menu. If they select c again to enter more coupons, the additional coupons should be added to the total. The discount() function should allow the user to enter their customer discount card number into a dialog box. *** We will not validate this card number – any entry will be accepted. In real life, the number would be validated and recorded along with the transaction data. *** A discount of 7% should be recorded for later use before returning to main() to redisplay the menu. Note: It may appear as though nothing happens when ‘d’ is entered – the dialog box may be hidden behind another window. Find it, enter a number, and click OK. The menu should reappear, and behind the scenes, you will have applied the discount percentage. When the user selects the Total option from the menu, your program will call the total() function. This function will print a receipt header that includes your last name, the items sold for this transaction, the totals for items, coupons, discount, tax, and the final total. After the final total, print gas points and discount card number that the user previously entered. If they did not enter a card, this section should not print. Once the printing is complete, the program should end. Calculations: · Discount applies only if the user entered their discount card number – no number, no discount. Discount is applied to item total minus coupons. · Tax is 5.5% and should be created as a named constant. Sales tax is applied to item total minus coupons, minus discount amount. · Gas points are calculated based on item total minus coupons, minus discount amount; 1 point for every $10, no rounding. Scenario 1 – with discount, no coupons: Scenario 2 – with coupons, no discount: Scenario 3: If the user does not enter coupons or card number, those lines should not print on the receipt. In the following screenshot you can see that the only menu option selected was the Total, so there are no references to coupons, discounts, or gas points on the receipt. Deliverable: Submit the flowchart/pseudocode and the .py file separately to the assignment in Canvas. You will not submit a .zip file and you do not need to upload the grocery.txt file. Onions,.95 Butter,3.29 Parmesan,2.49 Pasta,1.19 Dog food,15.89 Paper towels,1.29 Soup,.99 Spinach,1.89 Eggs,2.69 Coffee,3.69 Bananas,1.72 Chicken,5.21 Soup,1.49 Mustard,1.19 Apples,2.37 Salad,2.49
Answered Same DayApr 14, 2021

Answer To: CIS 331 Assignment #4 CIS 221 PA5 – Grocery Transaction This is an individual assignment. Your...

Pulkit answered on Apr 15 2021
144 Votes
80647/1.PNG
80647/2.PNG
80647/3.PNG
80647/grocery.txt
Onions,.95
Butter,3.29
Parmesan,2.49
Pasta,1.19
Dog food,15.89
Paper towels,1.29

Soup,.99
Spinach,1.89
Eggs,2.69
Coffee,3.69
Bananas,1.72
Chicken,5.21
Soup,1.49
Mustard,1.19
Apples,2.37
Salad,2.49
80647/main.py
from tkinter import *
from tkinter import messagebox
from tkinter import simpledialog
# Global variables
items = [] # List with item names
item_prices = [] # List with item prices
coupon_amounts = [] # List with coupon amounts
item_total = coupon_total = discount_percent = card_number = 0
def readdata():
global item_total # Use global variable
try:
file_name = simpledialog.askstring('File', 'Enter the file name') # Ask for input using tkinter
file = open(file_name) # Open the entered file
a = list(file) # List of lines in file
for item in a:
name, price = item.strip('\n').split(',') # remove \n(newline) if present and split on comma
items.append(name)
item_prices.append(float(price))
file.close()
item_total = round(sum(item_prices), 2) # Round sum of item prices
messagebox.showinfo('Success', 'File read successfully')
return 1 # File opened successfully
except:
# Error in opening file, or other error
messagebox.showerror('Error', 'Unable to open file')
...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here