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

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...
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...
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 that displays a table consisting of four rows and five columns. The first...
"Create a program that displays a table consisting of four rows and five columns. The first column should display the numbers 1 through 4. The second and sub-sequent columns should display the result of multiplying the number in the first column by the numbers 2 through 5. If necessary, create a new project named Introductory14 Project, and save it in the Cpp8\Chap08 folder. Enter the C++ instructions into a source file named Introductory14.cpp. Also enter appropriate comments and any additional...
Objective: Create a program that displays a design or picture for someone in your quarantine household/group:...
Objective: Create a program 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 different colors...
// How to create a random number this program only creates a specific same number #include...
// How to create a random number this program only creates a specific same number #include <iostream> #include <iomanip> double random (int &seed); bool determine_larger (double rand_num); void print_results (double rand_num); using namespace std; int main() { int seed = 8; double rand_num = random (seed); print_results (rand_num); return 0; } // function: random number // does:generates a random number between (0, 1) double random (int &seed) { int const MODULUS = 15749; int const MULTIPLIER = 69069; int const...
C++ Program -------------------- Project 5-1: Monthly Sales Create a program that reads the sales for 12...
C++ Program -------------------- Project 5-1: Monthly Sales Create a program that reads the sales for 12 months from a file and calculates the total yearly sales as well as the average monthly sales. Console Monthly Sales COMMAND MENU m - View monthly sales y - View yearly summary x - Exit program Command: m MONTHLY SALES Jan        14317.41 Feb         3903.32 Mar         1073.01 Apr         3463.28 May         2429.52 Jun         4324.70 Jul         9762.31 Aug        25578.39 Sep         2437.95 Oct         6735.63 Nov          288.11 Dec         2497.49...
// Creates a Breakfast class // and instantiates an object // Displays Breakfast special information using...
// Creates a Breakfast class // and instantiates an object // Displays Breakfast special information using System; using static System.Console; using System.Globalization; class DebugNine2 {    static void Main()    {       Breakfast special = new Breakfast("French toast", 4.99);       //Display the info about breakfast       WriteLine(special.INFO);       // then display today's special       WriteLine("Today we are having {0} for {1}",          special.Name, special.Price.ToString("C2", CultureInfo.GetCultureInfo("en-US")));   } } class Breakfast {    public string INFO =       "Breakfast is the most important meal of the day.";       // Breakfast constructor requires...
Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX....
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 separately....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT