Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This program read the quantity of several items item and their prices.
- // It calculates the total price and prints the total bill.
- // The input will come from a data file and the output will go to
- // an output file.
- // Mitchell
- // SUPPLY THE INCLUDE FILE NEEDED FOR FILE ACCESS.
- #include <fstream>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- int main()
- {
- ifstream dataIn; // defines an input stream for a data file
- int quantity; // contains the amount of items purchased
- string itemDesc; // description of the item
- float itemPrice; // contains the price of each item
- // DECLARE VARIABLE(S) HERE TO CALCULATE TOTAL BILL.
- dataIn.open("transaction.txt"); // This opens the input file.
- if (!dataIn) { // Abort the program if we cannot find the input.
- cout << "Input file, transaction.txt, not found. Stopping.\n";
- return(1);
- }
- cout << "\n";
- cout << "\t----------------------------------------\n"; // CHANGE TO LOOP
- cout << "\t Sales Order \n";
- cout << "\t----------------------------------------\n"; // CHANGE TO LOOP
- cout << "\t\t\t Unit Cost Total\n";
- cout << "\t----------------------------------------\n"; // CHANGE TO LOOP
- cout << setprecision(2) << fixed;
- while (dataIn >> quantity )
- {
- dataIn >> itemDesc >> itemPrice;
- //WRITE THE CODE IN HERE THAT YOU WILL NEED TO COMPLETE EACH LINE ITEM
- cout << "\t " << setw(4) << left << quantity << setw(17) << itemDesc
- << setw(6) << itemPrice << setw(10) << right << "99.99" << "\n";
- //WRITE THE CODE IN HERE THAT YOU WILL NEED TO CALCULATE THE TOTAL BILL
- }
- //WRITE THE CODE IN HERE THAT YOU WILL NEED TO OUTPUT THE TOTAL BILL
- cout << "\t----------------------------------------\n"; // CHANGE TO LOOP
- cout << "\t\t\t Total sale: " << setw(10) << right << "99.99" << "\n"; // CHANGE THE 99.99 TO SOMETHING ELSE
- cout << "\t----------------------------------------\n"; // CHANGE TO LOOP
- //WRITE THE CODE IN HERE THAT YOU WILL NEED TO PROPERLY CLEAN UP THE FILES
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement