Project 0, Shopping List
Short Description:
Write a program that will produce a cost estimate for a shopping trip.
This assignment is worth 0 points.
Goals
When you finish this homework, you should have:
- Written a medium sized program involving multiple files.
- Performed a functional decomposition of a medium sized problem.
- Demonstrated good programming techniques.
- Preformed a reasonably thorough review of programming discussed in your introduction to programming class.
Formal Description
You have started using the HelpMeCook app, which is a great application for planning dinners. Unfortunately, it wants to do all of your shopping for you at HighPrice.com. Fortunately, you have found a way around the system. You have convinced HelpMeCook to write the shopping list to a file. This file consists of an item description, the cost of the item at HighPrice.com and the quantity of each item needed.
The output file from HelpMeCook might be
Bananas| 2.00 1
Sugar| 1.80 1
Milk| 3.00 2
Nilla Wafers| 3.45 4
Eggs| 2.99 1
Note, the app puts a bar (|) after the item description.
Additionally, you have found that MyLocalStore.com has a web page that will take a list of items as described above and return the cost for each item. The output from MyLocalStore.com is a file containing the item description and the price for each item.
An example file from MyLocalStore.com might be
Bananas| 1.40
Sugar| 0.99
Milk| 1.38
Nilla Wafers| 2.99
Eggs| 1.00
This file also has the bar after the item description.
You may assume that
- The files are free from errors.
- The items in the files are in the same order.
- Both stores sell the same items.
To simplify things, your basic system creates a file called shopping.txt. This file contains the names of the files containing the shopping list for HighPrice.com and the shopping list for MyLocalStore.com. The file might contain
HighDinner.dat
LocalDinner.dat
Your task is to write a program that computes
- The savings for each item.
- The total cost at HighPrice.com
- The total cost at MyLocalStore.com
You should output this in the following format
- An item number starting with 1.
- This should be in a column 4 characters wide and right justified.
- The Item description, not including the bar.
- This should be in a column 20 characters wide.
- Quantity of the item.
- This should be in a column 5 characters wide.
- The price per unit at HighPrice.com
- This should be in a column 7 characters wide.
- The price per unit at MyLocalStore.com
- This should be in a column 7 characters wide.
- The total cost at MyLocalStore.com
- This should be in a column 7 characters wide.
- The total savings for this item.
- This should be in a column 7 characters wide.
Finally, print the total cost for each store and the total savings. Please see the example below for the exact format.
A B C D E F G
123412345678901234567890123451234567123456712345671234567
1 Bananas 1 2.00 1.40 1.40 0.60
2 Sugar 1 1.80 0.99 0.99 0.81
3 Milk 2 3.00 1.38 2.76 3.24
4 Nilla Wafers 4 3.45 2.99 11.96 1.84
5 Eggs 1 2.99 1.00 1.00 1.99
Total cost at MyLocalStore.com 18.11
Savings 8.48
Please note,
- all dollar amounts are rounded to pennies.
- the first two lines are provided for reference and are ont par of the output.
- The second line shows filed widths
- The first line shows the filed letter (from the description)
Example Files
Other Notes
Required Files
A single tar file containing the source code and makefile for this program.
Please use this Makefile.
Submission
You don't have to do this program, so you don't need to submit it.