Write the program in C++ only Please read carefully and answer correctly** Write
ID: 3812666 • Letter: W
Question
Write the program in C++ only
Please read carefully and answer correctly**
Write a program that calculates and prints the bill for a cellular telephone company. The company offers two types of service: regular and premium. The rates vary depending on the type of service. The rates are computed as follows: Regular: $10 base charge. First 50 minutes are free. Charges for over 50 minutes are $0.20 per minute. Premium: $25 base charge. First 200 minutes are free. Charges for over 200 minutes are $0.05 per minute.
The user inputs the phone number, type of service (R or P), and the number of minutes used. Calculate and display the base charge and minutes charge. Create the following functions:
getValues Prompt for the phone number, type of service, and minutes used. Values
are returned using reference variables. Validate that the minutes are
positive, and that the code is P or R. Use loops for validation.
calcCharges Receives the type of service and minutes used. Calculates the base charge
and the minutes charge and returns both using reference variables.
printResults Receives the phone number, type of service, minutes used, base charge,
and minutes charge. Calculates the total charge and prints the bill as
formatted below.
Sample Program Output: (Test Case 1)
Enter phone number: 555-1234
Enter type of service (R or P): R
Enter number of minutes used: 45
Charges for: 555-1234
Service type: R
Minutes used: 45
Base cost: $ 10.00
Minutes cost: $ 0.00
Total due: $ 10.00
Press any key to continue…
Explanation / Answer
#include <iostream>
#include <string.h>
using namespace std;
string phoneNumber;
string type;
int minits;
double baseCost;
double minitsCost;
double totalDue;
void getValues();
void calcCharges();
void printResults();
int main(){
getValues();
calcCharges();
printResults();
return 0;
}
void getValues(){
cout<<"Enter phone number:";
cin >> phoneNumber;
cout<<"Enter type of service (R or P):";
cin >> type;
cout<<"Enter number of minutes used:";
cin >> minits;
}
void calcCharges(){
if(type.compare("R")==0){
baseCost = 10.0;
minitsCost =0.0;
if(minits>50){
minitsCost = (minits-50)*0.20;
}
totalDue = baseCost + minitsCost;
}
if(type.compare("P")==0){
baseCost = 50.0;
minitsCost =0.0;
if(minits>200){
minitsCost = (minits-50)*0.05;
}
totalDue = baseCost + minitsCost;
}
}
void printResults(){
cout<<"Charges for:"<<phoneNumber<<endl;
cout<<"Service type:"<<type<<endl;
cout<<"Minutes used:"<<minits<<endl;
cout<<"Base cost:"<<baseCost<<endl;
cout<<"Minutes cost:"<<minitsCost<<endl;
cout<<"Total due:"<<totalDue<<endl;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.