-
-
Save anonymous/080b7d21dc929325371f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <iomanip> | |
#include <fstream> | |
using namespace std; | |
//Named constants residential customers | |
const double RES_BILL_PROC_FEES = 4.50; | |
const double RES_BASIC_SERV_COST = 20.50; | |
const double RES_COST_PREM_CHANNEL = 7.50; | |
//Named constants business customers | |
const double BUS_BILL_PROC_FEES = 15.00; | |
const double BUS_BASIC_SERV_COST = 75.00; | |
const double BUS_BASIC_CONN_COST = 5.00; | |
const double BUS_COST_PREM_CHANNEL = 50.00; | |
int main() | |
{ | |
//Variable declaration and intialization | |
int accountNumber; | |
char customerType; | |
int numOfPremChannels; | |
int numOfBasicServConn; | |
double amountDue; | |
//declaring file streams | |
ifstream inFile; | |
ofstream outFile; | |
//open the file streams | |
inFile.open("input.txt"); | |
//check wheather file exists or not | |
if(!inFile) | |
{ | |
cout <<"\n=============== ERROR! ==================\n\n"; | |
cout <<" Could Not Find Input Data File!\n"; | |
cout <<"\n=========================================\n\n\n"; | |
return 1; | |
} | |
outFile.open("output.txt"); | |
cout <<"\n==========================================\n\n"; | |
cout <<" PROGRAM TO COMPUTE THE CABLE BILL\n"; | |
cout <<"\n==========================================\n\n"; | |
//use while loop to get the acoount numbers and customer type from the file | |
//Hint:use eof (end of file) | |
while (!inFile.eof()) | |
{ | |
cout<< "The account number is: "; | |
inFile>> accountNumber; | |
cout<<accountNumber<<"\n"; | |
cout << "The customer type: " | |
<< "R or r (Residential), " | |
<< "B or b (Business): "; | |
inFile>> customerType; | |
//only printed to screen for now | |
cout << customerType; | |
switch (customerType) | |
{ | |
case 'r': | |
case 'R': | |
cout << "\n\nEnter the number" | |
<< " of premium channels: "; | |
cin >> numOfPremChannels; | |
cout << "\n\n"; | |
amountDue = RES_BILL_PROC_FEES | |
+ RES_BASIC_SERV_COST | |
+ numOfPremChannels * | |
RES_COST_PREM_CHANNEL; | |
cout << "Premium Channels = " << numOfPremChannels; | |
cout << "\nAmount Due = $" << amountDue << endl << endl << endl; | |
//writing to a outputfile (to be done) | |
break; | |
case 'b': | |
case 'B': | |
cout << "\n\nEnter the number of basic " | |
<< "service connections: "; | |
cin >> numOfBasicServConn; | |
cout << "\nEnter the number" | |
<< " of premium channels: "; | |
cin >> numOfPremChannels; | |
cout << "\n\n"; | |
if (numOfBasicServConn<= 10) | |
amountDue = BUS_BILL_PROC_FEES | |
+ BUS_BASIC_SERV_COST | |
+ numOfPremChannels * | |
BUS_COST_PREM_CHANNEL; | |
else | |
amountDue = BUS_BILL_PROC_FEES | |
+ BUS_BASIC_SERV_COST | |
+ (numOfBasicServConn - 10) * | |
BUS_BASIC_CONN_COST | |
+ numOfPremChannels * | |
BUS_COST_PREM_CHANNEL; | |
//writing to an ouputfile: to be done, once double-printing is debugged | |
cout << "Basic Service Connections = " << numOfBasicServConn; | |
cout << "\nPremium Channels = " << numOfPremChannels; | |
cout << "\nAmount Due = $" << amountDue << endl << endl << endl; | |
break; | |
default: | |
//writing to an outputfile: to be done, once double-printing is debugged | |
//invalid account prints 2x for some reason, is that fixable? | |
cout << "\n\nThe account number "<< accountNumber <<" has an invalid customer type"; | |
cout<<"\n\n\n"; | |
cout<<"Account type is invalid"; | |
cout<<"\n\n"; | |
outFile << "The account number " << accountNumber <<" has an invalid customer type"; | |
break; | |
}//end switch | |
} | |
//close inputfile | |
inFile.close(); | |
//close outputfile | |
outFile.close(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment