Question
Modify the PROGRAM 4 so that it also satisfies the following two additional Requirements: REQUIREMENT 1: When validating user input for hours used, account for
Modify the PROGRAM 4 so that it also satisfies the following two additional Requirements:
REQUIREMENT 1: When validating user input for hours used, account for the month and year the charges are being computed for.
REQUIREMENT 2: Display how much money Package A customers would save if they purchased packages B or C, and how much money Package B customers would save if they purchased Package C. If there would be no savings, no message should be printed.
Demonstrate test cases described in table: Test /Case Package/ Hours / Month / Year 1 /A /49 /11 /2019 2 /a / 720/ 09/ 2019 3 /A/ 730/ 06 / 2019 4 /a/ 99/ 04 / 2019 5 /B/ 100/ 12/ 2019 6 /b/ 744/ 10/ 2019 7 /B/ 745 /08 / 2019 8/ c/ 672 /02 / 2019 9 /C/ 673/ 02 / 2019 10 /c/ 696/ 02/ 2020 11 /C/ 697/ 02/ 2020 Clearly identify the results of each test case.
//program 4 #include #include
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 **"< 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 **"< 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 :$"< }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started