Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a complete C++ program that reworks the Cellular Bill calculation program

ID: 3539037 • Letter: W

Question

Write a complete C++ program that reworks the Cellular Bill calculation program below (marked with****). Give your source file a meaningful name, such as CellBillFun.cpp. Your new cell bill program must use 3 functions with parameters, as follows:






Account Number:    XXXXXXX


Service Type:           Regular (or Premium, depending on the character received)


Total Minutes:         XXXX


Amount Due:           $XXX.XX




Your main function will still prompt the user for the account number and service code. Based on the service code, main will ask for the correct number of minutes, then call your functions above as needed to finish the job. In addition you must :



****^^Code that needs to be reworked^^*******


#include <iostream>
using namespace std;
int main()
{
       // declare variables
    string accountNumber = "";
    char serviceCode = ' ';
    int numMinUsed = 0;
    int over=0;
    int minDay = 0, minNight = 0;
    double bill = 0.0;

    cout.setf(ios::fixed,ios::floatfield);
    cout.precision(2);

    //prompt user account number
    cout<<"Please enter your account number:";
    cin>>accountNumber;

    //prompt user for service code
    cout<<"Please enter service code: (R/P only)";
    cin>>serviceCode;

        while(serviceCode!='r'&&serviceCode!='R'&&serviceCode!='p'&&serviceCode!='P')

    {cout<<"Must be P or R ";
        cout<<"Please enter service code Premium or Regular: (R/P only)";
        cin>>serviceCode;
     }

    //prompt user for minutes usage
    if (serviceCode == 'P'|| serviceCode=='p'){
        cout<<"Enter minutes used during the day:";
        cin>>minDay;
    while(minDay<0)
        {
          cout<<"Enter minutes used during the day:";
          cin>>minDay;
          }
          cout<<"Enter minutes used during the night:";
          cin>>minNight;
     while(minNight<0)
        {
          cout<<"Enter minutes used during the night:";
          cin>>minNight;
          }

        cout<<" Account #: " << accountNumber;
        cout<<" Service type: " << serviceCode;
        cout<<" Minutes used during Day: " << minDay;
        cout<<" Minutes used during Night: " <<minNight;
        bill=25;                  //base cost

    if(minDay > 75){
    over = minDay - 75;
      bill =bill+ over * .10;    //add cost of extra daytime minutes
      }

    if(minNight > 100){
       over = minNight - 100;      //add cost of extra nighttime minutes
       bill =bill+ over * .05;
       }

    }

    else{                     //service code is R
        cout<<"Enter minutes used:";
        cin>>numMinUsed ;
    while(numMinUsed<0)
        {
        cout<<"Enter minutes used:";
        cin>>numMinUsed;
          }

    cout<<" Account #: " << accountNumber;
    cout<<" Service type: " <<serviceCode;
    bill = 10;              //base price
    if(numMinUsed > 50)
      {
         over = numMinUsed - 50;
         bill =bill+ over * .20; //mins over 50 is .20
        }

}
    cout<<" Your total bill is: $" <<bill << endl;
    return 0;

}

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;


double calcRegBill(int numMinUsed )

{

double bill = 10; //base price

if(numMinUsed > 50)

{

int over = numMinUsed - 50;

bill =bill+ over * .20; //mins over 50 is .20

}

return bill;

}


double calcPremBill(int minDay, int minNight)

{

double bill=25; //base cost


if(minDay > 75){

int over = minDay - 75;

bill =bill+ over * .10; //add cost of extra daytime minutes

}


if(minNight > 100){

int over = minNight - 100; //add cost of extra nighttime minutes

bill =bill+ over * .05;

}

return bill;

}


void printBill(string accountNumber, char serviceCode, int numMinUsed, double bill)

{

cout<<" Account Number: " << accountNumber;

cout<<" Service Type: " ;

if(serviceCode=='P'||serviceCode=='P')

cout<<"Premium";

else

cout<<"Regular";

cout<<" Total Minutes: " << numMinUsed;

cout<<" Amount Due: $"<<bill<<" ";

}


int main()

{

// declare variables

string accountNumber = "";

char serviceCode = ' ';

int numMinUsed = 0;

int over=0;

int minDay = 0, minNight = 0;

double bill = 0.0;


cout.setf(ios::fixed,ios::floatfield);

cout.precision(2);


char ch = 'y';

while(ch=='y'||ch=='Y'){

//prompt user account number

cout<<"Please enter your account number:";

cin>>accountNumber;


//prompt user for service code

cout<<"Please enter service code: (R/P only)";

cin>>serviceCode;


while(serviceCode!='r'&&serviceCode!='R'&&serviceCode!='p'&&serviceCode!='P')

{

cout<<"Must be P or R ";

cout<<"Please enter service code Premium or Regular: (R/P only)";

cin>>serviceCode;

}

  

//prompt user for minutes usage

if (serviceCode == 'P'|| serviceCode=='p'){

cout<<"Enter minutes used during the day:";

cin>>minDay;

while(minDay<0){

cout<<"Enter minutes used during the day:";

cin>>minDay;

}

cout<<"Enter minutes used during the night:";

cin>>minNight;

while(minNight<0){

cout<<"Enter minutes used during the night:";

cin>>minNight;

}

bill = calcPremBill(minDay, minNight);

printBill(accountNumber, serviceCode, minDay+minNight, bill);

}


else{ //service code is R

cout<<"Enter minutes used:";

cin>>numMinUsed ;

while(numMinUsed<0){

cout<<"Enter minutes used:";

cin>>numMinUsed;

}


bill = calcRegBill(numMinUsed);

printBill(accountNumber, serviceCode, numMinUsed, bill);

}

cout<<"Continue?(y ):";

cin>>ch;

while(ch!='y'&&ch!='Y'&&ch!='n'&&ch&&'N'){

cout<<"Continue?(y ):";

cin>>ch;

}

}

cout<<" Your total bill is: $" <<bill << endl;

return 0;


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote