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: 3850559 • 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:

For $10.00: the first 50 minutes are free. Charges for over 50 minutes are $0.20 per minute.

Premium service:

For $25.00:

a. 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.

b. 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 a service code (char), and the number of minutes the service was used (int). 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 type of service, and the total cost. 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.

Note:- (Using C++)

Explanation / Answer

C++ Code:

#include<bits/stdc++.h>
using namespace std;
int main()
{
   char service_code;
   cout<<"Enter the service code(p or r):";
   cin>>service_code;
   service_code=toupper(service_code);
   double cost=0.0;
   if(service_code=='R')
   { int time;
   cost = 10.0;
   cout<<"Enter the time(in min):";
cin>>time;
       if(time>50)
       cost += ((time-50)*0.20);
   }
   else if(service_code == 'P')
   { cost = 25.0;
       int day_time;
       int night_time;
       cout<<"Enter the number of minutes at day time:";
       cin>>day_time;
       cout<<"Enter the number of minutes at night time:";
       cin>>night_time;
       if(day_time>75)
       {
           cost += (day_time - 75)*0.10;
       }
       if(night_time > 100)
       {
           cost += (night_time-100)*0.05;
       }
      
      
   }
   else
   {
       cout<<"Invalid Service...Exiting!";
       return 0;
   }
   cout<<"The service you are using is: ";
   if(service_code == 'R')
   cout<<"Regular!"<<endl;
   else
   cout<<"Premium!"<<endl;
   cout<<"Your total cost is: $"<<cost<<endl;
   return 0;
}

Output:

Enter the service code(p or r):p
Enter the number of minutes at day time:125
Enter the number of minutes at night time:200
The service you are using is: Premium!
Your total cost is: $35

Enter the service code(p or r):r
Enter the time(in min):100
The service you are using is: Regular!
Your total cost is: $20

Enter the service code(p or r):w
Invalid Service...Exiting!

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