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

//Mobile Service Provider //A mobile service provider has 3 different data plans

ID: 3726652 • Letter: #

Question

//Mobile Service Provider
//A mobile service provider has 3 different data plans for its customers:
// A - $39.99 per month, 4 GB included.$10 each additional GB
//B - $59.99 per month, 8 GB included. $5 each additional GB
//C - 69.99 per month, unlimited data
//Write a program that calculates a customers monthly bill. It should ask which package the customer has purchased and how many GB used.
//It should then display the total amount due.

Input Validation: Switch must be used. Be sure the user only selects package A, B, or C. Cannot use any code from beyond Chapter 4

Explanation / Answer

#include <iostream>

using namespace std;

float calculate(char, float);

int main()
{
char plan='A'; // to choose which plan
float usage=0.0; // total GB used
float totalCost=0.0; // Amount pay by the user
  
int option ;
  
while(1){
cout<<"Please select the option ";
cout<<" 1. Calculte bill ";
cout<<" 2. Display ";
cout<<" 3. Exit ";
cin>>option;
switch(option){
case 1:
cout<<" Enter the package (A,B or C): ";
cin>>plan;
cout<<" Enter the usage (in GB) : ";
cin>>usage;
totalCost = calculate(plan, usage);
break;
case 2:
cout<<" Customer in package : "<<plan<<" ";
cout<<" Customer used "<<usage<<"GB ";
cout<<" The amount due is $"<<totalCost<<" ";break;

case 3:
exit;

break;
default:
cout<<"Please select any valid option ";
}
}
return 0;
}

float calculate(char plan, float usage){
float totalCost = 0.0;
if(plan!='A' && plan!='B' && plan!='C' ){
cout<<" The plan is not there in the list ";
return 0.0;
}else{
if(plan == 'A'){
if(usage > 4.0){
totalCost = 39.99 + (10 * (usage-4.0));
return totalCost;
}else{
totalCost = 39.99;
return totalCost;
}
}else if(plan == 'B'){
if(usage > 8.0){
totalCost = 59.99 + (5* (usage-5.0));
return totalCost;
}else{
totalCost = 5.99;
return totalCost;
}
}else if(plan == 'C'){
totalCost = 69.99;
return totalCost;
}
}
}

Switch case used in the main method and validated the input plan. in the calculate method