Advertisement
Guest User

Untitled

a guest
Mar 18th, 2014
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.14 KB | None | 0 0
  1. // This program read the quantity of several items item and their prices.
  2. // It calculates the total price and prints the total bill.
  3. // The input will come from a data file and the output will go to
  4. // an output file.
  5.  
  6. // Mitchell
  7. // SUPPLY THE INCLUDE FILE NEEDED FOR FILE ACCESS.
  8. #include <fstream>
  9. #include <iostream>
  10. #include <iomanip>
  11. using namespace std;
  12. int main()
  13. {  
  14.   ifstream dataIn;                 // defines an input stream for a data file
  15.  
  16.   int quantity;                    // contains the amount of items purchased
  17.   string itemDesc;                 // description of the item
  18.   float itemPrice;                // contains the price of each item
  19.   // DECLARE VARIABLE(S) HERE TO CALCULATE TOTAL BILL.
  20.  
  21.  
  22.   dataIn.open("transaction.txt");  // This opens the input file.
  23.  
  24.   if (!dataIn)   {   // Abort the program if we cannot find the input.
  25.     cout << "Input file, transaction.txt, not found. Stopping.\n";
  26.     return(1);
  27.   }
  28.  
  29.   cout << "\n";
  30.   cout << "\t----------------------------------------\n";  // CHANGE TO LOOP
  31.   cout << "\t      Sales Order \n";
  32.   cout << "\t----------------------------------------\n";  // CHANGE TO LOOP
  33.   cout << "\t\t\t    Unit Cost     Total\n";
  34.   cout << "\t----------------------------------------\n";  // CHANGE TO LOOP
  35.  
  36.   cout << setprecision(2) << fixed;
  37.  
  38.   while (dataIn >> quantity )
  39.   {
  40.      dataIn  >> itemDesc >> itemPrice;
  41.      //WRITE THE CODE IN HERE THAT YOU WILL NEED TO COMPLETE EACH LINE ITEM
  42.      cout << "\t  " << setw(4) << left << quantity << setw(17) << itemDesc
  43.           << setw(6) << itemPrice << setw(10) << right << "99.99" << "\n";
  44.      //WRITE THE CODE IN HERE THAT YOU WILL NEED TO CALCULATE THE TOTAL BILL
  45.   }  
  46.  
  47.   //WRITE THE CODE IN HERE THAT YOU WILL NEED TO OUTPUT THE TOTAL BILL
  48.   cout << "\t----------------------------------------\n"; // CHANGE TO LOOP
  49.   cout << "\t\t\t Total sale: " << setw(10) << right << "99.99" << "\n"; // CHANGE THE 99.99 TO SOMETHING ELSE
  50.   cout << "\t----------------------------------------\n"; // CHANGE TO LOOP
  51.  
  52.     //WRITE THE CODE IN HERE THAT YOU WILL NEED TO PROPERLY CLEAN UP THE FILES
  53.  
  54.   return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement