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

Write a program that calculates and prints the bill for a cellular telephone com

ID: 3692380 • Letter: W

Question

Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. Its rates vary, depending on the type of service. The rates are computed as follows: Regular service: $10.00 plus first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute. Premium service: $25.00 plus: For calls made from 6:00 a.m. to 6:00 p.m., the first 75 minutes are free; charges for more than 75 minutes are $0.10 per minute. For calls made from 6:00 p.m. to 6:00 a.m., the first 100 minutes are free; charges for more than 100 minutes are $0.05 per minute. Your program should prompt the user to enter an account number, a service code (type char), and the number of minutes the service was used. A service code of r or R means regular service; a service code of p or P means premium service. Treat any other character as an error. Your program should output the account number, type of service, number of minutes the telephone service was used, and the amount due from the user. For the premium service, the customer may be using the service during the day and the night. Therefore, to calculate the bill, you must ask the user to input the number of minutes the service was used during the day and the number of minutes the service was used during the night.

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

const double REG_SERV_CHARGES = 10.00;
const int REG_FREE_MINUTES = 50;
const double REG_RATE_OVER_50 = 0.20;

const double PREM_SERV_CHARGES = 25.00;
const int PREM_FREE_DAY_MINUTES = 75;
const double PREM_DAY_RATE_OVER_75 = 0.10;

const int PREM_FREE_NIGHT_MINUTES = 100;
const double PREM_NIGHT_RATE_OVER_100 = 0.05;

int getMinutes (string promptMessage);
void regularAmtDue (int minUsed, double &amtDue);
void premiumAmtDue (int dayMin, int nightMin, double &amtDue);
void writeOutput (int minutes1, int minutes2, double amtDue, char service);

int main()
{

char serviceType;

int minutesUsed;
int minutesUsedPN;

double amountDue;

cout << fixed << showpoint;
cout << setprecision(2);

cout << "Enter service type: (r or R) for regular, "
<< "(p or P) for premium service: " << endl;
cin >> serviceType;
cout << endl;

switch (serviceType)
{
   case 'r':
case 'R':
  
       // call getMinutes for minutes of service here

   // call regularAmtDue here
  
           // call writeOutput here
          
break;
case 'p':
case 'P':

       // call getMinutes for day minutes here

       // call getMinutes for night minutes here

           // call premiumAmtDue here

           // call writeOutput here
          
break;
default:
cout << "Invalid Service Type" << endl;
   }//end switch
system("PAUSE");
   return 0;
} // end main


int getMinutes (char promptMessage)
{
  

//-------------------------------------------------------------------
// getMinutes is a value returning function that accepts a string and
// prompts the user for the number of minutes then returns this value
// to main.
//-------------------------------------------------------------------

} // end getMinutes


void regularAmtDue (int minUsed, double &amtDue)
{
if (minUsed <= 50)
{
amtDue = REG_SERV_CHARGES;
}
else if (minUsed > 50)
{
amtDue = REG_SERV_CHARGES + minUsed * REG_RATE_OVER_50;
}

} // end regularAmtDue


void premiumAmtDue (int dayMin, int nightMin, double &amtDue)
{
if (dayMin <= 75)
{
amtDue = PREM_SERV_CHARGES;
}
else if (nightMin > 100)
{
amtDue = PREM_SERV_CHARGES + (nightMin * PREM_NIGHT_RATE_OVER_100);
}
else if(nightMin > 100 && dayMin > 75)
{
amtDue = PREM_SERV_CHARGES + (dayMin * PREM_DAY_RATE_OVER_75)
+ (nightMin * PREM_NIGHT_RATE_OVER_100);
}
else
{
amtDue = PREM_SERV_CHARGES + (dayMin * PREM_DAY_RATE_OVER_75);
}

} // end premiumAmtDue


void writeOutput (int minutes1, int minutes2, double amtDue, char service)
{
if (service == 'r' || 'R')
{
minutes2 = 0;
amtDue = 0;
cout << "Your service is regular." << endl;
cout << "Your bill is " << regularAmtDue << endl;
}
if (service == 'p' || 'P')
{
amtDue = 0;
cout << "Your service is premium." << endl;
cout << "Your bill is " << premiumAmtDue << endl;
}

} // end writeOutput

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