Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Heya I need with this assignment that is based on the Cable company program below. 1.1 Draw a flowchart for your program based on your

Heya I need with this assignment that is based on the Cable company program below.

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

We had the option to do it via arrays, hoping someone could help me write it using arrays? He is the original code for the problem:

#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; void main() { //Variable Dcelaration int accountNumber; char customerType; int numOfPremChannels; int numOf BasicServConn; double amountDue; cout << fixed << showpoint; cout << setprecision(2); cout << "This program computes a cable bill." << endl; cout << "Enter account number (an integer): "; cin >> accountNumber; cout << endl; cout << "enter customer type: " << "R or r (Residential), " << "B or b (Business)"; cin >> customerType; cout << endl; switch(customerType) { case 'r': case 'R': cout << "Enter the number of premium channels:"; cin >> numOfPremChannels; cout << endl; amountDue = RES_BILL_PROC_FEES + RES_BASIC_SERV_COST + numOfPremChannels * RES_COST_PREM_CHANNEL; cout << "Account Number: " << accountNumber; cout << endl; cout << "Amount Due: $" << amountDue << endl; break; case 'b': case 'B': cout << "Enter number of basic service connections: "; cin >> numOfBasicServConn; cout << endl; cout << "Enter number of premium channels: "; cin >> numOfPremChannels; cout << endl; 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; cout << "Account Number: " << accountNumber << endl; cout << "Amount Due: $" << amountDue << endl; break; default: cout << "Invalid customer type" << endl; } } 

Here is my code so far:

#include "stdafx.h" #include  #include  #include  using namespace std; const int numberofcustomers = 20; //needs to be declared before hand and can be changed //residential customers constants const double resBillProc = 4.50; const double resBasicServCost = 20.50; const double resCostPremChan = 7.50; //business customers constants const double busBillProc = 15.00; const double busBasicServCost = 75.00; const double busBasicConnCost = 5.00; const double busCostPremChan = 50.00; void calcCustRes(int premiumChanNum[][2], char customerType[][1], string customerID[], int i, ofstream& outFile, double resSum); void calcCustBus(int premiumChanNum[][2], char customerType[][1], int basicServNum[][3], string customerID[], int i, ofstream& outFile, double busSum); int main() { string customerID[numberofcustomers]; //store customer IDs char customerType[numberofcustomers][1]; //storing customer type int premiumChanNum[numberofcustomers][2];//store number of premiumChannels int basicServNum[numberofcustomers][3]; // store number of basic server connections double averSpendRes; double averSpendBus; int resNum = 0; int busNum = 0; double resSum; double busSum; char fileName[60]; ifstream inFile; ofstream outFile; cout << "Enter in the input file name: "; cin >> fileName; //user inputs file name inFile.open(fileName); //opens input file if (!inFile) { cout << "Cannot open the input file." << endl; //checks the user to tell them they opened the wrong file return 0; } cout << "Enter in the input file name: "; cin >> fileName; //user inputs file name outFile.open(fileName); //opens input file if (!outFile) { cout << "Cannot open the output file." << endl; //checks the user to tell them they opened the wrong file return 0; } for (int i = 0; i < numberofcustomers; i++) { inFile >> customerID[i]; inFile >> customerType[i][1]; inFile >> premiumChanNum[i][2]; inFile >> basicServNum[i][3]; } //now to compare said data for (int i = 0; i < numberofcustomers; i++) { if (customerType[i][1] == 'r' || customerType[i][1] == 'R') { resNum++; calcCustRes(premiumChanNum, customerType, customerID, i, outFile, resSum); } else if (customerType[i][1] == 'b' || customerType[i][1] == 'B') { busNum++; calcCustBus(premiumChanNum, customerType, basicServNum, customerID, i, outFile, busSum); } } averSpendBus = busSum / busNum; averSpendRes = busSum / busNum; outFile << "Average spending of residential: " << averSpendRes << endl; outFile << "Average spending of businesses: " << averSpendBus << endl; inFile.close(); outFile.close(); } void calcCustRes(int premiumChanNum[][2], char customerType[][1], string customerID[], int i, ofstream& outFile, double resSum) { double amountDue = 0; outFile << "Customer ID: " << customerType[i][1] << customerID[i] << endl; outFile << "Number of premium channels: " << premiumChanNum[i][2] << endl; amountDue = resBillProc + resBasicServCost + (premiumChanNum[i][2]) * resCostPremChan; outFile << "Bill: $" << amountDue << endl << endl; resSum += amountDue; } void calcCustBus(int premiumChanNum[][2], char customerType[][1], int basicServNum[][3], string customerID[], int i, ofstream& outFile, double busSum) { double amountDue = 0; outFile << "Customer ID: " << customerType[i][1] << customerID[i] << endl; outFile << "Number of premium channels: " << premiumChanNum[i][2] << endl; outFile << "Number of basic connections: " << basicServNum[i][3] << endl; if (basicServNum[i][3] <= 10) { amountDue = busBillProc + busBasicServCost + (premiumChanNum[i][2]) * busCostPremChan; outFile << "Bill: $" << amountDue << endl << endl; } else { amountDue = busBillProc + busBasicServCost + (basicServNum[i][3] - 10) * busBasicConnCost + (premiumChanNum[i][2]) * busCostPremChan; outFile << "Bill: $" << amountDue << endl << endl; } busSum += amountDue; } I am having issues coming up with the last way to find the average, which is all I need help with if im doing this with arrays 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

10th Edition

0137916787, 978-0137916788

More Books

Students also viewed these Databases questions

Question

Exposure to SQL desirable but not required

Answered: 1 week ago