Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Nicole Sickafoose
- // Principles of Programming I 130
- // Fall 2011
- //
- // Internet Bill Program
- // 3
- //
- // 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.
- //
- #include <fstream>
- #include <iomanip>
- #include <iostream>
- #include <string>
- using namespace std;
- int main (void)
- {
- const float AMTDUEC = 19.95;//This is the only applicable answer for option C
- ifstream dataFile; //This file contains the data necessary for computation
- ofstream infoFile; //This file will contain the output
- float amtDueA, //
- amtDueB, //
- savingsB, //
- aSavingsC, //
- bSavingsC, //
- numHours; //
- char serviceCode;//
- string accountNum, //
- inDataFile, //This is a user specified input file
- outDataFile,//This is a user specified output file
- outConst; //This is to save space in the output part of the code
- outConst = "Account Number Service Code Hours Amt Due";
- cout << "Please enter name of input file: ";
- cin >> inDataFile;
- cout << endl;
- cout << "Please enter name of output file: ";
- cin >> outDataFile;
- cout << endl;
- dataFile.open(inDataFile.c_str());
- infoFile.open(outDataFile.c_str());
- dataFile >> accountNum;
- dataFile >> serviceCode;
- dataFile >> numHours;
- if (numHours > 744)
- {
- cout << endl;
- cout << left << setw(8) << "Input" << setw(8) << accountNum << setw(8) << serviceCode << setw(8) << numHours << setfill(5) << "*";
- cout << " Hours Exceed Threshold " << setfill(5) << "*" << endl;
- cout << endl;
- }
- if (serviceCode != A or serviceCode != B or serviceCode != C)
- {
- cout << endl;
- cout << left << setw(8) << "Input" << setw(8) << accountNum << setw(8) << serviceCode << setw(8) << numHours << setfill(5) << "*";
- cout << " Invalid Service Code " << setfill(5) << "*" << endl;
- cout << endl;
- }
- amtDueA = (numHours - 10) * 2.25;
- amtDueB = (numHours - 20) * 1.25;
- savingsB = amtDueA - amtDueB;
- aSavingsC = amtDueA - AMTDUEC;
- bSavingsC = amtDueB - AMTDUEC;
- if (serviceCode == A)
- {
- if (numHours <= 10)
- {
- infoFile << outConst;
- infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << "9.95" << endl;
- infoFile << endl;
- }
- else if (numHours > 10)
- {
- infoFile << outConst;
- infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << amtDueA << endl;
- if ((savingsB > 0) && (aSavingsC > 0))
- {
- infoFile << setw(33) << "Savings for Package B" << setw(15) << savingsB << endl;
- infoFile << setw(33) << "Savings for Package C" << setw(15) << aSavingsC << endl;
- }
- else if ((savingsB > 0) && (aSavingsC <= 0))
- {
- infoFile << setw(33) << "Savings for Package B" << setw(15) << savingsB << endl;
- }
- else if ((savingsB <= 0) && (aSavingsC > 0))
- {
- infoFile << setw(33) << "Savings for Package C" << setw(15) << aSavingsC << endl;
- }
- else if ((savingsB <= 0) && (aSavingsC <= 0))
- {
- infoFile << " ";
- }
- }
- }
- if (serviceCode == B)
- {
- if (numHours <= 20)
- {
- infoFile << outConst;
- infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << "14.95" << endl;
- infoFile << endl;
- }
- else if (numHours > 20)
- {
- infoFile << outConst;
- infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << amtDueB << endl;
- if (bSavingsC > 0)
- {
- infoFile << setw(33) << "Savings for Package C" << setw(15) << bSavingsC << endl;
- }
- else if (bSavingsC <= 0)
- {
- infoFile << " ";
- }
- }
- }
- if (serviceCode == C)
- {
- infoFile << outConst;
- infoFile << setw(10) << accountNum << setw(15) << serviceCode << setw(17) << numHours << setw(16) << AMTDUEC << endl;
- }
- dataFile.close();
- infoFile.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment