Answered step by step
Verified Expert Solution
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 YYYYMMDD 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:
:: Book,
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 datetime 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 "dailyreport.txt This file should have one line for each category, like this:
Sample Content of dailyreport.txt:
Books: $
DVDs: $
Games: $
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 : Could not convert "sixtyseven cents" to price format
Error on line : Could not convert s to price format
Error on line : Could not convert dollars" to price format
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started