People go to the beach and often buy a bunch of stuff that will only be used at the beach. Pretend you own a beach-side emporium that sells the usual stuff: inflatable toys, suntan lotion, shark-tooth necklaces, flip flops, and the like. You made 26 sales today, and you have captured that sales data in a comma separated text file that lists the day's sales. Here are the first several lines,

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 6PE
icon
Related questions
Question

People go to the beach and often buy a bunch of stuff that will only be used at the beach. Pretend you own a beach-side emporium that sells the usual stuff: inflatable toys, suntan lotion, shark-tooth necklaces, flip flops, and the like. You made 26 sales today, and you have captured that sales data in a comma separated text file that lists the day's sales. Here are the first several lines,

alita,frisbee,11.5,3
betty,shark-tooth necklace,9.25,4
carlos,squirt gun,9.75,5
diego,flip flops,7.77,1
elena,snorkle,9.5,2

Shown below is the data separated out so it is easy to read. But the file itself is comma separated, like the above. The file contains no column names, but if it did the columns would be named Customer Name, Item, Price, Quantity. For example, alita bought 3 frisbees at $11.50 each.

alita frisbee 11.5 3
betty shark-tooth necklace 9.25 4
carlos squirt gun 9.75 5
diego flip flops 7.77 1
elena snorkle 9.5 2
frank umbrella 32.2 3

Shown above is only part of the data file. As we said, the file itself has 26 rows of 4 data items per row.

Your program should read the file and print each row along with the total for each order. For example, elena bought 2 snorkels at $9.50 each, so her order total would be $19.00. We will assume there is no sales tax.

Additionally, after printing the row data, your program should print grand total for the day (the sum of all the 26 individual totals) To repeat, for each record your program should print the name, item purchased, price, quantity purchased, and the order total for that customer. After printing all the file data with calculations, you need to print the total sales for the day.

The comma-separated text file you need to use can be accessed using this link:   makewaves.txt.  

Clicking the link probably opens the file in your browser. Save the file somewhere you can find it. But the name of the file must be makewaves.txt, and the 26 data rows must not be altered in any way.

Here is and approximation of what your print-out should look like using the first 5 rows as an example. Your output should look similar, with all currency values rounded to 2 decimal places, but yours will have all 26 records and at the end a display of the sales total for the whole day (grand total the 26 individual totals). Your output should look similar; it need not be exact. But everything must line up neatly, including the decimal places. It's time we get good at formatting output.

Name Item Price Quantity Total alita frisbee 11.50 3 34.50 betty shark-tooth necklace 9.25 4 37.00 Carlos squirt gun 9.75 5 48.75 dieg0 flip flops 7.77 1 7.77 elena snorkel 9.50 2 19.00 ... and 21 more rows... ... and then print the total sales for the day

Your python program needs to accomplish the following:

  • Your code needs to read the makewaves.txt data from the supplied text file. Do not modify the file, and it needs to keep its current name and structure. I will use my copy of the file to test your program. So, the file opened must be named makewaves.txt and it must contain the same records used in the link above.
  • You need to print the 4 pieces of information in all 26 rows along with a total for that person's purchase. Printouts need to be neat and properly aligned, where the names and items are left justified and decimals line up for currency values. If you format the currencies to 2 decimal places, which is a requirement, this will be easier to do.
  • You need to process the data with a loop, and that loop should be able to work properly even if the number of purchases in the file varies from day today. That is, don't use 26 as a magic number. The program should work no matter how many records the file might contain.
  • Your program must have at least 2 functions written by you. The first one is a main() function which reads the data file. You could easily have more than 2 functions if you choose, but you need 2 minimum, one of which is named main() that reads the data.
  • The second function must calculate the total for each customer, receiving as parameters the price and quantity for each customer when called from the main loop. Knowing how to do arguments/return values is a goal of the exercise.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Software products
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning