In: Computer Science
Design and implement a C++ program with functions to
calculate the pre-tax charge:
If the customer subscribes to a phone plan called Plan200, then he
is charged $5 for the first 200 minutes. For each additional
minutes, the customer will be charged $0.10.
If the customer subscribes to a phone plan called Max20, then he is
charged $0.05 for each minute up to $20. (I.e., the customer never
needs to pay more than $20.)
If the customer is not subscribed to any phone plan, then he is
charged $0.10 for each minute of the phone calls.
To find out whether and which plan the user is
subscribed to, your program can display a message such as:
Please choose one of the following options:
Enter A if you are subscribed to Plan200;
B if you are subscribed to Max20;
or
any other keys if you are not
subscribed to any plan.
Your choice:
And then read the user's input. You can use numbers instead of
characters.
You can also choose to give the user a free hand to enter this
information, such as:
Please enter the phone plan you are subscribed to
(none if you are not subscribed to any):
#include <iostream>
using namespace std;
//Declaring all the required functions
void Plan200(int min);
void Max20(int min);
void NoPlan(int min);
int main()
{
int n,min;
//Displaying the menu for the user
cout<<"Select Your Plan\nPress 1 for Plan200\nPress 2 for Max20\nPress Any Other Key If You are not Subscribed to any Plan\n";
//Taking choice Input
cout<<"Enter Your Choice: ";
cin>>n;
//Taking Input of number of Minutes Spoken
cout<<"Enter Number of Minutes Spoken: ";
cin>>min;
//If User Selects 1,Calling Plan200() Function
if(n==1)
Plan200(min);
//IF USer Selects 2,Calling Max20() Function
else if (n==2)
Max20(min);
//Other Than That,Calling NoPlan() Function
else
NoPlan(min);
}
//Function for Plan200 Plan
void Plan200(int min){
//if min less than or equal to 200, charging is $20
if(min<=200)
cout<<"You Will Be charged $20 For the First 200 Minutes.";
else{
//Calculating total
double total=20+((min-200)*0.1);
//printing total
cout<<"You Will be charged $"<<total;
}
}
//Function for Max20 Plan
void Max20(int min){
//Calculating total Bill
double total=0.05*min;
//if bill is less than or equal to $20, printing it
if(total<=20)
cout<<"You Will be charged $"<<total;
//else printing $20 as bill
else
cout<<"You Will be Charged $20";
}
//Function for No Plan
void NoPlan(int min){
//Calculating total
double total=0.1*min;
//printing the total
cout<<"You will be charged $"<<total;
}