Question: Rewrite the Programming Example page 236 in chapter 4 ( Cable Company Billing ). Expected Program and Design: 1. Write a pseudo code before starting
Rewrite the Programming Example page 236 in chapter 4 ( Cable Company Billing ). Expected Program and Design: 1. Write a pseudo code before starting your program ( do not use SWITCH, replace it with IF structures ) 1.1 Draw a flowchart for your program based on your pseudo code 2. Identify your constants 3. Your input will come from a text file of at least 15 customers 3.1 Input file format - customerType accountNumber premiumChannels ( i.e residential example: R12345 5 , business example B12345 16 8 ) 4. Precision should be two decimal places 5. Calculate the running average for residential and business customer spending 6. Print all customer's bill to a single file and the end of the file you should have the average summary for each customer type. 6.1 Pay attention to details when you formatting your output
Note: Use all chapter concepts and make your final as a true representation of what we have learned this semester. Turn in program design ( pseudo code and/or flow chart ) input file output file .cpp file of your program ( make sure you include your header and comment your code ) Extra credit Implement your program using arrays, covered in chapter 8, and user defined simple data types to hold customer data.
#include
#include
#include
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
int accountNumber;
char customerType;
int numOfPremChannels;
int numOfBasicServConn;
double amountDue;
int rescount=0,buscount=0;
double ressum=0.00,bussum=0.00;
double resavg,busavg;
ifstream fin;
ofstream fout;
//open input file
fin.open("custin.txt",ios::in);
if(fin.fail())
{
cout<<"Unable to open file "< exit(0); } //open ouput file fout.open("custout.txt",ios::out); fout << fixed << showpoint; fout << setprecision(2); fout << "This program computes a cable " << "bill." << endl; //read from input file while(!fin.eof()) { //read customer type from file fin >> customerType; //read account number from file fin >> accountNumber; //If customer type is residential if(customerType=='r' || customerType=='R' ) { //read number of prem channels from file fin >> numOfPremChannels; amountDue = RES_BILL_PROC_FEES + RES_BASIC_SERV_COST + numOfPremChannels * RES_COST_PREM_CHANNEL; //write into output file fout << "Account number: " << accountNumber << endl; fout << "Amount due: $" << amountDue << endl< //compute running average of residential cusomer's amount due rescount+=1; ressum+=amountDue; resavg=ressum/rescount; } //If customer type is business else if(customerType=='b' || customerType=='B' ) { //read number of service connection from file fin >> numOfBasicSevConn; //read number of prem channels from file fin >> numOfPremChannels; 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; fout << "Account number: " << accountNumber << endl; //Step 7f fout << "Amount due: $" << amountDue << endl< //compute running average of business cusomer's amount due buscount+=1; bussum+=amountDue; busavg=bussum/buscount; } else fout << "Invalid customer type.in "< } fout< fout< fin.close(); fout.close(); return 0; } How would I implement arrays? And is this correct? Does this code effeciently use Input/output Control Structures User Defined Functions User Defined simple data type/namepsaces/strings I feel like it does seem to work, but I'm stuck on how to implement this into an array
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
