Question: Write a C++ program that uses: .selection constructs (if, if else, and switch) .multiway branches .looping constructs (do and while loops) .Boolean expressions, bool and
Write a C++ program that uses:
.selection constructs (if, if else, and switch)
.multiway branches
.looping constructs (do and while loops) .Boolean expressions, bool and char types.
1. Develop a program that calculates charges for an Internet provider. The cost is determined by the amount of data used and the consumer plan. Package B (basic) is the most affordable if you plan on using < 20GB (20,000MB), however, if you consume more than 20GB (20,000MB) you are charged for each additional megabyte. If the customer has plan P (platinum) they a flat rate for unlimited data, although the flat rate is of course a higher price than the other plans. Plan E (enhanced) is between the two in terms of flat fee and number of MB included. Plan details are listed below.
2. The program will require some validity checking:
The user must enter a character corresponding to the chosen plan. If any character other than ('B', 'b', 'E', 'e','P', or 'p') is input then the program display an appropriate message and will prompt the user for a new plan selection. The program will continue to prompt the user until a valid plan is selected. You may assume that the user will only enter a single character. The user must input the number of megabytes used; it must be between 0 and 100,000 (inclusive). If a value outside of this range is input then the program provides an appropriate message and will request a new entry. You may assume that the user will only enter integer numbers.
The plan details are as follows:
Plan
Base Price
Additional Fees
B (basic)
$35
$.02 for each MB after 5 GB/5,000 MB.
E (enhanced)
$75
$.01 for each MB after 10 GB/10,000 MB
P (platinum)
$120
Unlimited data.
The program will let the user know if he/she would save money by upgrading. (plan B to E, P to B, etc.) and will display the potential savings of switching. The factor for upgrades is as follows:
Package
Decision point
Cost savings
B
> $75
cost of B cost of E.
B
> $120
cost of B cost of P.
E
> $120
cost of E cost of P
***Note that there may also be circumstances in which E and P would save money by downgrading (example = platinum customer using 1,000 MB). I leave this to you to work out.***
You may use a switch statement to display the plan cost and potential savings/cost of upgrading.
ImplementationNotes:
You should use both switch and the if... else constructs in this program. The switch construct is ideal when you are checking a single variable against a number of different discrete values (char, int). Strings and doubles are not discrete and will not work with the switch statement. if statements can be used when you have a relational operation such as equality or less than or greater than comparison, etc. Be careful when using a long chain of if... else constructs because it can become confusing. It is always good practice to develop programs in small functional steps, testing as you go (incremental development. Here is a possible strategy for this assignment:
Write the code that prompts the user to enter a plan and data in MBs. Display this information back to the user (no calculation necessary). Add the calculation to to show what it will cost depending on which plan is chosen and the amount of data. No validation or comparison needed yet. Add code that will test which plan is selected and compare costs, then display a message to the user informing how much the upgrade/downgrade will save them. Add the validation/error handling (looping).
SampleRuns:
Run1:
Which plan does the customer use (B, E, or P)? B How many MB did the customer use last month? 4000 The charges are: $35.00
Run 2:
Which plan does the customer use (B, E, or P)? B How many MB did the customer use last month? 7500 The charges are: $85.00 By switching to plan E you would save $10.00
*********************************************************** Run 3:
Which plan does the customer use (B, E, or P)? E How many MB did the customer use last month? 15000 The charges are: $125.00 By switching to plan P you would save $5.00 **********************************************************
Run4:
Which plan does the customer use (E, B, or P)? f Enter only E, B, or P for the plan.
Which plan does the customer use (E, B, or P)? 5 Enter only E, B, or P for the plan.
Which plan does the customer use (E, B, or P)? E How many MB did the customer use last month? -12 Enter a number from 0 through 10000 for MB used.
How many MB did the customer use last month? 900000 Enter a number from 0 through 100000 for MB used.
How many MB did the customer use last month? 5 The charges are $35
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
