Question

Write a C++ program that uses: .selection constructs (if, if else, and switch) .multiway branches .looping...

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).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>

using namespace std;

int main() {

char consumerPlan;

int megaBytes;

float cost;

float platCost;

float extendCost;

float basicCost;

  

cout<<"\nSelect your consumer plan (B/P/E):";

cin>>consumerPlan;

while(consumerPlan != 'E' || consumerPlan != 'e' || consumerPlan != 'P' || consumerPlan != 'p' || consumerPlan != 'B' || consumerPlan != 'b')

{

cout<<"\n\n\nYou have enetered wrong values.\nSelect your consumer plan again (B/P/E):";

cin>>consumerPlan;

}

cout<<"\n\nEnter the megabytes you used (0-100000):";

cin>>megaBytes;

while(megaBytes < 0 || megaBytes > 100000){

cout<<"\n\n\nYou have enetered wrong values.\nEnter the megabytes you used (0-100000):";

cin>>megaBytes;

}

  

if(consumerPlan == 'B'){

cost = (megaBytes/5000) * 0.02;

platCost = 120;

extendCost = (megaBytes/10000) * 0.1;

cout<<"\n\nTotal cost of the MB consumed is "<<cost<<"$\nIf you have used the Extended Plan the cost would have been "<<extendCost<<"$\n\nAnd if you would have used platinum plan the cost would have been"<<platCost ;

}

else if(consumerPlan == 'P'){

cost = (megaBytes/10000) * 0.1;

platCost = 120;

basicCost = (megaBytes/5000) * 0.02;

cout<<"\n\nTotal cost of the MB consumed is "<<cost<<"$\nIf you have used the Basic Plan the cost would have been "<<basicCost<<"$\n\nAnd if you would have used platinum plan the cost would have been"<<platCost ;

}

else{

cost = 120;

basicCost = (megaBytes/5000) * 0.02;

extendCost = (megaBytes/10000) * 0.1;

cout<<"\n\nTotal cost of the MB consumed is "<<cost<<"$\nIf you have used the Basic Plan the cost would have been "<<basicCost<<"$\n\nAnd if you would have used Extended plan the cost would have been"<<extendCost ;

}

  

// your code goes here

return 0;

}

Add a comment
Know the answer?
Add Answer to:
Write a C++ program that uses: .selection constructs (if, if else, and switch) .multiway branches .looping...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a...

    In this program, you will be using C++ programming constructs, such as functions. main.cpp Write a program that asks the user to enter an integer value. Your program will then display that integer back to the user. Your program should include a function called getInteger that requests an integer value from the user and returns that value back to the caller. Your main () function will call the function getInteger and will then display the value returned by that function....

  • Write a program in c++ for An electric company came out with a residential rate schedule...

    Write a program in c++ for An electric company came out with a residential rate schedule in your state. You are asked to write a program that will compute the customer’s electric bill. Program will prompt month number and Kilowatt hour used. Sample Input Screen:             Enter the month (1 - 12)                      :             Kilowatt hours used                             : The electric bill is computed using the following method: There is a flat service charge of $15.31...

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

  • Question 2 Use a switch statement to write the following program: Using C++ The program prompts...

    Question 2 Use a switch statement to write the following program: Using C++ The program prompts the user for a letter grade (of type char). The list of valid letter grades is: A B C D E F The program should consider both lower and upper case The program will then display the following messages: For grade ‘A’: display “Excellent” For grade ‘B’: display “Good” For Grade ‘C’: display “Average” For grade ‘D’ or ‘E’: display “Below Average” For Grade...

  • Inventory Program (C++) Write a program that uses a structure to store the following inventory data...

    Inventory Program (C++) Write a program that uses a structure to store the following inventory data in a file: - Item Description -Quantity on Hand -Wholesale cost -Retail cost -Date Added to Inventory The program should have a menu that allows the user to perform the following tasks: -Add new records to file -Display any record in the file -Change any record in the file Input Validation: The program should not accept quantities, or wholesale or retail costs, less than...

  • please write in C++ Write a program that uses a structure to store the following inventory...

    please write in C++ Write a program that uses a structure to store the following inventory data in a file: The data can be either read from a text file or the keyboard Item name (string) Quantity on hand(int) Wholesale cost(double) Retail Cost(double) The program should have a menu that allows the user to perform the following tasks: Add new records to the file Display any record in the file User will provide the name of the item or the...

  • Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

    Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static variables. Ensure integer variables input are within a range that will not cause integer overflow. Uses proper design techniques including reading UML Class Diagrams Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class...

  • C# vitual studio 2019 need flowchart and code – If/Else and Switch Statements For this project...

    C# vitual studio 2019 need flowchart and code – If/Else and Switch Statements For this project you will be calculating car maintenance based on the area the user wishes to have maintenance perform. Complete with If/ese or the Switch Statement 1. Show menu for tires, oil, state inspection, and wash 2. Tires a. $100 per tire b. User tells you how many tires c. Show out their cost 3. Oil a. Synthetic $75 b. Regular $45 c. Show out their...

  • In C language using printf and scanf statements: Write a program to display a histogram based...

    In C language using printf and scanf statements: Write a program to display a histogram based on a number entered by the user. A histogram is a graphical representation of a number (in our case, using the asterisk character). On the same line after displaying the histogram, display the number. The entire program will repeat until the user enters zero or a negative number. Before the program ends, display "Bye...". The program will ask the user to enter a non-zero...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT