Question

In: Computer Science

Create a program that: Creates a sales receipt, displays the receipt entries and totals, and saves...

Create a program that:

  • Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file
    • Prompt the user to enter the
      • Item Name
      • Item Quantity
      • Item Price
    • Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made
    • Save the item name, quantity, item price, and extended price to a file
      • When you create the file, prompt the user for the name they want to give the file
      • Separate the items saved with commas
      • Each entry should be on a separate line in the text file
    • Ask the user if they have more items to enter
  • Once the user has finished entering items
    • Close the file with the items entered
    • Display the sales total
    • If the sales total is more than $100
      • Calculate and display a 10% discount
    • Calculate and display the sales tax using 8% as the sales tax rate
      • The sales tax should be calculated on the sales total after the discount
    • Display the total for the sales receipt

Save the program and submit it to this site for grading.


(This is Python)

Solutions

Expert Solution

Code in python

# with open("Exam1_Q3.txt", "r") as filestream:
#     for line in range(i,filestream.size()):
#         currentline = filestream[i].split("|")
#         print(currentline)
total_sales = 0
item_name = input("Enter item name: ")
item_quantity = int(input("Enter item quantity: "))
item_price = float(input("Enter item price: "))
item_ex_price = item_quantity * item_price
total_sales+=item_ex_price
#items separated with comma and ends with a new line
data = "Item: %s,Quantity: %d,Price: $%d,Extended Price: $%d\n" % (item_name, item_quantity, item_price, item_ex_price)
print(data)

#save to file
filename = input("Enter file name: ")
f = open(filename, 'w') 
f.write(data)

more_entry = input("Do you have more items to enter? y/n: ")
while more_entry=="y":
    item_name = input("Enter item name: ")
    item_quantity = int(input("Enter item quantity: "))
    item_price = float(input("Enter item price: "))
    item_ex_price = item_quantity * item_price
    total_sales+=item_ex_price
    data = "Item: %s,Quantity: %d,Price: $%d,Extended Price: $%d\n" % (item_name, item_quantity, item_price, item_ex_price)
    f.write(data)
    more_entry = input("Do you have more items to enter? y/n: ")

f.close()

print("Total sales = $%f" % (total_sales))
if(total_sales>100):
    discount = 0.1*total_sales
    print("Discount = $%f" % (discount))
    total_sales -= discount

sales_tax = 0.08*total_sales
print("Tax = $%f" % (sales_tax))
total_sales += sales_tax

print("Total = $%f" % (total_sales))

Sample Console Input/Output

Enter item name: mango
Enter item quantity: 2
Enter item price: 20
Item: mango,Quantity: 2,Price: $20,Extended Price: $40

Enter file name: output.txt
Do you have more items to enter? y/n: y
Enter item name: orange
Enter item quantity: 4
Enter item price: 40
Do you have more items to enter? y/n: y
Enter item name: apple
Enter item quantity: 1
Enter item price: 10
Do you have more items to enter? y/n: n
Total sales = $210.000000
Discount = $21.000000
Tax = $15.120000
Total = $204.120000

Contents of output.txt after execution

Item: mango,Quantity: 2,Price: $20,Extended Price: $40
Item: orange,Quantity: 4,Price: $40,Extended Price: $160
Item: apple,Quantity: 1,Price: $10,Extended Price: $10

Let me know in comments if you have any doubts. Do leave a thumbs up if this was helpful.


Related Solutions

Create a Python program that: Creates a sales receipt, displays the receipt entries and totals, and...
Create a Python program that: Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file Prompt the user to enter the Item Name Item Quantity Item Price Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made Save the item name, quantity, item price, and extended price to a file When you create the file, prompt the user...
Create a python program that: Creates a sales receipt, displays the receipt entries and totals, and...
Create a python program that: Creates a sales receipt, displays the receipt entries and totals, and saves the receipt entries to a file Prompt the user to enter the Item Name Item Quantity Item Price Display the item name, the quantity, and item price, and the extended price (Item Quantity multiplied by Item Price) after the entry is made Save the item name, quantity, item price, and extended price to a file When you create the file, prompt the user...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer, as shown in Figure 10-30. For a residential cus- tomer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. If necessary, create a...
In this exercise, you will create a program that displays the amount of a cable bill....
In this exercise, you will create a program that displays the amount of a cable bill. The amount is based on the type of customer shown in figure 10-30. For a residential customer, the user will need to enter the number of premium channels only. For a business customer, the user will need to enter the number of connections and the number of premium channels. Use a separate void function for each customer type. Enter your C++ instructions into the...
Create a program that creates a sorted list from a data file. The program will prompt...
Create a program that creates a sorted list from a data file. The program will prompt the user for the name of the data file. Create a class object called group that contains a First Name, Last Name, and Age. Your main() function should declare an array of up to 20 group objects, and load each line from the input file into an object in the array. The group class should have the following private data elements: first name ,last...
Welcome to the Bruins Goalie Saves Analysis This program will calculate the percentage of saves for...
Welcome to the Bruins Goalie Saves Analysis This program will calculate the percentage of saves for a hockey goalie for 4 games after you have entered the games and saves for the goalie. Enter the number of goals for game #1: 3 Enter the number of saves for game #1: 22 The percent saves for game #1 is 88.0% Enter the number of goals for game #2: 4 Enter the number of saves for game #2: 33 The percent saves...
In C, create a program that displays the minimum and maximum values stored in a data...
In C, create a program that displays the minimum and maximum values stored in a data file "datafile.txt". Use the following function prototype:  void minmaxarray(float value, float *min, float *max);
Create a program in JAVA that displays a design or picture for someone in your quarantine...
Create a program in JAVA that displays a design or picture for someone in your quarantine household/group: a pet, a parent, a sibling, a friend. Make them a picture using the tools in TurtleGraphics and run your program to share it with them! Use a pen object, as well as any of the shape class objects to help you create your design. You must use and draw at least 5 shape objects. - You must use a minimum of 4...
java program Create a program that creates and prints a random phone number using the following...
java program Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes.  Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint:   Think though the easiest way to construct the phone number. Each digit does do not have to be determined...
Create a program “Fib.java” and a method called “double[] getFib)” that creates an array with a...
Create a program “Fib.java” and a method called “double[] getFib)” that creates an array with a length of 15 that contains the first 15 numbers in the Fibonacci sequence and returns it. Set the first element to 0 and the second element to 1, then use a for loop to fill out the rest of the array.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT