Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Trish runs a small business called Trish's Swap Shop, where she sells a variety of items including books, DVDs , and games. To help manage

Trish runs a small business called Trish's Swap Shop, where she sells a variety of items including books, DVDs, and games. To help manage her business more efficiently, she wants to generate a daily sales report that categorizes and totals her sales for each category of items sold.
You will write a program that creates this daily sales report.
The source of data for your program will be a text file called "sales.txt". This file will contain the details of each sale made during a day. Each line in the file represents one sale and contains the following fields separated by a comma:
Date and time of the sale (in the format YYYY-MM-DD HH:MM:SS)
Category of the item sold (Book, DVD, or Game)
Price of the item sold (in dollars)
Here's an example of what a line in "sales.txt" could look like:
2023-07-1610:15:30, Book, 15.99
A sample data file is available on Blackboard.
write a program that does the following:
Tries to open "sales.txt". If the file is not present, the program should print "File 'sales.txt' not found" and terminate.
If the file is present, read each line of the file using a loop. Split each line into its components (date/time, category, and price) using the split() function.
The program should maintain a running total of the sales for each category.
After all the data from sales.txt has been read, the program should write the totals for each category to a new file called "daily_report.txt". This file should have one line for each category, like this:
Sample Content of daily_report.txt:
Books: $107.80
DVDs: $27.76
Games: $78.67
Please make sure that your program can handle cases where the sales.txt file contains extra spaces before or after the commas, or at the beginning or end of lines.
The program should also handle situations where the price on a line could not be converted to a float. In that case, the program should print an error message to the console to inform the user there is invalid data, and tell the user where the error occurred:
Error on line 12: Could not convert "sixty-seven cents" to price format
Error on line 22: Could not convert "4.04s" to price format
Error on line 36: Could not convert "4 dollars" to price format

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

More Books

Students also viewed these Databases questions