Question: C++ Modify the PROGRAM 4 so that it also satisfies the following two additional Requirements: REQUIREMENT 1: When validating user input for hours used, account

C++

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.

// this is program 4

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 customers monthly charges.

Input Validation: 1) Be sure the user only selects package A, B, or C; or a, b, or c. 2) The user cannot use more than 720 hrs in a month. (We will assume a 30-day month for this probkem).

Demonstrate test cases described in table: Test Case Package Hours 1 A 50 2 a 51 3 B 100 4 b 101 5 C 149 6 c 251 7 e 720 8 c 722

the code for question 4 is bellow:

// C++ program to calculate the monthly bill for the Internet usage given the package name and usage hours #include #include #include using namespace std;

// Function prototypes char getPackage(); bool validPackage(char package); int getHours(); bool validHours(int hours); double calculatePkg_A(int hours); double calculatePkg_B(int hours); double calculatePkg_C(int hours); double calculateCharges(char package, int hours); void showBill(char package, int hours, double billAmount);

int main() {

char package; int hours; double cost;

package = getPackage(); // get the package selected by the user hours = getHours(); // get the number of hours used if(validPackage(package) && validHours(hours)) { cost = calculateCharges(package,hours); // calculate the bill amount showBill(package,hours,cost); // display the bill }else cout<<"Invalid package or number of hours."<

return 0; }

// function to input and return the selected package by the user char getPackage() { char package; cout<<"Enter the package : "; cin>>package;

return package; }

// function to validate package bool validPackage(char package) { if(tolower(package) == 'a' || tolower(package) == 'b' || tolower(package) == 'c') return true; return false; }

// function to input and return the number of hours used int getHours() { int hours; cout<<"Enter number of hours used : "; cin>>hours;

return hours; }

// function to validate the hours used bool validHours(int hours) { // Assuming each month has maximum of 30 days if(hours < 0 || hours > 720) return false; return true; }

// function to calculate and return the cost for package A double calculatePkg_A(int hours) { double cost = 15; if(hours > 50) { cost += (hours - 50)*2.0; }

return cost; }

// function to calculate and return the cost for package B double calculatePkg_B(int hours) { double cost = 20; if(hours > 100) { cost += (hours-100)*1.50; }

return cost; }

// function to calculate and return the cost for package C double calculatePkg_C(int hours) { double cost = 25;

if(hours > 150) { cost += (hours-150)*1.0; }

return cost; }

// function to calculate and return the bill amount for selected package and number of hours { double cost;

if(tolower(package) == 'a') cost = calculatePkg_A(hours); else if(tolower(package) == 'b') cost = calculatePkg_B(hours); else cost = calculatePkg_C(hours);

return cost; }

// function to display the bill void showBill(char package, int hours, double billAmount) { cout<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!