In: Computer Science
Program Requirements:
An Internet service provider has three different
subscription
packages for its customers:
Package A: For $15 per month with 50 hours of access
provided.
Additional hours are $2.00 per hour over 50 hours.
Assume usage is recorded in one-hour increments,
Package B: For $20 per month with 100 hours of access
provided.
Additional hours are $1.50 per hour over 100 hours.
Package C: For $25 per month with 150 hours access is
provided.
Additional hours are $1.00 per hour over 150 hours
Write a program that calculates a customer’s monthly
charges.
Implement with the following functions for your solution.
getPackage
validPackage
getHours
validHours
calculatePkg_A
calculatePkg_B
calculatePkg_C
calculateCharges
showBill
----------------------------------------------
Demonstrate test cases as described in table:
----------------------------------------------
Test Case Package
Hours
1
A
50
2
a
51
3
B
100
4
b
101
5
C
149
6
c
151
7
e
720
8
c
722
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
#include <iostream>
#include <iomanip>
using namespace std;
char getPackage();
bool validPackage(char ch);
int getHours();
bool validHours(int hrs);
double calculatePkg_A(int hours);
double calculatePkg_B(int hours);
double calculatePkg_C(int hours);
void showBill(char pack,int hours,double cost);
int main() {
char pack;
int hours;
double cost=0;
pack=getPackage();
hours=getHours();
if(pack=='A' || pack=='a')
{
cost=calculatePkg_A(hours);
}
else if(pack=='B' || pack=='b')
{
cost=calculatePkg_B(hours);
}
if(pack=='C' || pack=='c')
{
cost=calculatePkg_C(hours);
}
showBill(pack,hours,cost);
return 0;
}
char getPackage()
{
char ch;
while(true)
{
cout<<"Enter package :";
cin>>ch;
if(validPackage(ch))
break;
}
return ch;
}
bool validPackage(char ch)
{
if(ch=='A' || ch=='a' || ch=='B' || ch=='b' || ch=='C'
|| ch=='c')
return true;
else
{
cout<<"** Invalid.Package
must be either A, B or C **"<<endl;
return false;
}
}
int getHours()
{
int hrs;
while(true)
{
cout<<"Enter hours :";
cin>>hrs;
if(validHours(hrs))
break;
}
return hrs;
}
bool validHours(int hrs)
{
if(hrs<=0)
{
cout<<"** Invalid.Must be
> 0 **"<<endl;
return false;
}
else
{
return true;
}
}
double calculatePkg_A(int hours)
{
double cost=0;
if(hours<=50)
{
cost=15;
}
else
{
cost=15+2*(hours-50);
}
return cost;
}
double calculatePkg_B(int hours)
{
double cost=0;
if(hours<=100)
{
cost=20;
}
else
{
cost=20+1.5*(hours-100);
}
return cost;
}
double calculatePkg_C(int hours)
{
double cost=0;
if(hours<=150)
{
cost=25;
}
else
{
cost=25+1*(hours-150);
}
return cost;
}
void showBill(char pack,int hours,double cost)
{
//setting the precision to two decimal places
std::cout << std::setprecision(2) <<
std::fixed;
cout<<"Cost
:$"<<cost<<endl;
}
_________________________
Output:
_______________________
________________________
_______________________
________________________
________________________
_______________Could you plz rate me well.Thank
You