Guest User

Untitled

a guest
Feb 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.03 KB | None | 0 0
  1. // Nicole Sickafoose
  2. // Principles of Programming I 130
  3. // Fall 2011
  4. //
  5. // Internet Bill Program
  6. // 3
  7. //
  8. // This program will ask for file information from the user, read data from the corresponding file, perform calculations depending on whether the data satisfies certain requirements, and store the final output in an output file in order to calculate an internet server bill.
  9. //
  10. #include <fstream>
  11. #include <iomanip>
  12. #include <iostream>
  13. #include <string>
  14.     using namespace std;
  15. int main (void)
  16.  
  17. {
  18.     const float AMTDUEC = 19.95;//This is the only applicable answer for option C
  19.     ifstream    dataFile;   //This file contains the data necessary for computation
  20.     ofstream    infoFile;   //This file will contain the output
  21.     float       amtDueA,    //
  22.    
  23.                 amtDueB,    //
  24.                 savingsB,   //
  25.                 aSavingsC,  //
  26.                 bSavingsC,  //
  27.                 numHours;   //
  28.     char        serviceCode;//
  29.     string      accountNum, //
  30.                 inDataFile, //This is a user specified input file
  31.                 outDataFile,//This is a user specified output file
  32.                 outConst;   //This is to save space in the output part of the code
  33.  
  34.     outConst = "Account Number    Service Code       Hours         Amt Due";
  35.  
  36.     cout << "Please enter name of input file: ";
  37.     cin  >> inDataFile;
  38.     cout << endl;
  39.  
  40.     cout << "Please enter name of output file: ";
  41.     cin  >> outDataFile;
  42.     cout << endl;
  43.  
  44.     dataFile.open(inDataFile.c_str());
  45.     infoFile.open(outDataFile.c_str());
  46.  
  47.     dataFile >> accountNum;
  48.     dataFile >> serviceCode;
  49.     dataFile >> numHours;
  50.  
  51.     if (numHours > 744)
  52.     {
  53.         cout << endl;
  54.         cout << left << setw(8) << "Input" << setw(8) << accountNum << setw(8) << serviceCode << setw(8) << numHours << setfill(5) << "*";
  55.         cout << " Hours Exceed Threshold " << setfill(5) << "*" << endl;
  56.         cout << endl;
  57.     }
  58.    
  59.     if (serviceCode != A or serviceCode != B or serviceCode != C)
  60.     {
  61.         cout << endl;
  62.         cout << left << setw(8) << "Input" << setw(8) << accountNum << setw(8) << serviceCode << setw(8) << numHours << setfill(5) << "*";
  63.         cout << " Invalid Service Code " << setfill(5) << "*" << endl;
  64.         cout << endl;
  65.     }
  66.    
  67.     amtDueA   = (numHours - 10) * 2.25;
  68.     amtDueB   = (numHours - 20) * 1.25;
  69.     savingsB  = amtDueA - amtDueB;
  70.     aSavingsC = amtDueA - AMTDUEC;
  71.     bSavingsC = amtDueB - AMTDUEC;
  72.  
  73.     if (serviceCode == A)
  74.     {
  75.         if (numHours <= 10)
  76.         {
  77.             infoFile << outConst;
  78.             infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << "9.95" << endl;
  79.             infoFile << endl;
  80.         }
  81.         else if (numHours > 10)
  82.         {
  83.             infoFile << outConst;
  84.             infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << amtDueA << endl;
  85.             if ((savingsB > 0) && (aSavingsC > 0))
  86.             {
  87.                 infoFile << setw(33) << "Savings for Package B" << setw(15) << savingsB << endl;
  88.                 infoFile << setw(33) << "Savings for Package C" << setw(15) << aSavingsC << endl;
  89.             }
  90.             else if ((savingsB > 0) && (aSavingsC <= 0))
  91.             {  
  92.                 infoFile << setw(33) << "Savings for Package B" << setw(15) << savingsB << endl;
  93.             }
  94.             else if ((savingsB <= 0) && (aSavingsC > 0))
  95.             {
  96.                 infoFile << setw(33) << "Savings for Package C" << setw(15) << aSavingsC << endl;
  97.             }
  98.             else if ((savingsB <= 0) && (aSavingsC <= 0))
  99.             {
  100.                 infoFile << " ";
  101.             }
  102.         }
  103.     }
  104.     if (serviceCode == B)
  105.     {  
  106.         if (numHours <= 20)
  107.         {
  108.             infoFile << outConst;
  109.             infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << "14.95" << endl;
  110.             infoFile << endl;
  111.         }
  112.         else if (numHours > 20)
  113.         {
  114.             infoFile << outConst;
  115.             infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << amtDueB << endl;
  116.             if (bSavingsC > 0)
  117.             {
  118.                 infoFile << setw(33) << "Savings for Package C" << setw(15) << bSavingsC << endl;
  119.             }
  120.             else if (bSavingsC <= 0)
  121.             {
  122.                 infoFile << " ";
  123.             }
  124.         }
  125.     }
  126.     if (serviceCode == C)
  127.     {
  128.         infoFile << outConst;
  129.         infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << AMTDUEC << endl;
  130.     }
  131.  
  132.     dataFile.close();
  133.     infoFile.close();
  134.  
  135.     return 0;
  136. }
Add Comment
Please, Sign In to add comment