Write a program that reads a item name, unit price, and number of

advertisement
Feb 21 Programming Work (Due 2/26/08)
File I/O:
Part – I. shopping-list
Write a program that reads an item name, unit price, and number of items from a file
called shopping-list.txt into appropriate variables. The program then calculates and
outputs a heading line of “Item, Unit Price, Item Count, Subtotal”, the information read
from input file, and calculated subtotal, and total expense in the last line into an output
file called shopping-expense.txt.
Two files: shopping-list.txt and shopping-expense.txt
Input file shopping-list.txt has the following format:
Milk 3.99 5
Apple 0.89 10
Output file shopping-expense.txt should look nicer as:
Item
Unit Price
Item Count
Subtotal
**************************************************
Milk
$3.99
5
$19.95
Apple
$0.89
12
$10.68
Total Expense: $30.63
The program needs following variables:
ifstream fin;
ofstream fout;
// input file stream variable
// output file stream variable
string item;
double unitPrice, total;
int itemCount;
Part – II. Programming Exercises 6 (on page 166) from chapter 3.
Note:
1. Open and close files properly.
2. Outputs floating-point numbers in a fixed decimal format with a decimal point
and trailing zeros, set the manipulators fixed and showpoint. Also you should use
setw, setfill, and setprecision to manipulate the output.
Submission: The printout of your program with your name on it.
Download