Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Develop a program that calculates the cost of a data plan for a smartphone. The

ID: 3789345 • Letter: D

Question

Develop a program that calculates the cost of a data plan for a smartphone. The cost of the service is determined by two factors, the number of megabytes used and the package selected. The packages are structured so that package 'A' is the least expensive if you plan on using less than 200 MB, however if you use more than 200 MB you are charged significantly more for each additional megabyte. If you select package 'C' you pay a flat rate for unlimited data. Package 'B' is somewhere in between. Details of the packages structure is listed below.

The program will require some validity checking:

The user is required to enter a character to represent the package chosen. If a character other than ('A', 'a', 'B', 'b','C', and 'c') is entered the program provides a message and re-prompts them for a new package selection. The program will continue to re-prompt the user until a valid package is chosen. Assume the user will only enter a single character; there is no need to error check for entries of multiple characters.

The user is required to enter the number of megabytes used; it must be between 0 and 10,000 inclusive. If a value outside that range is entered the program provides a message and re-prompts the user for new entry. Assume the user will only enter integers, there is no need to error check for letters or decimal values.

The package details are as follows:

Package

Base Price

Additional Fees

A

$15

$.06 for each MB after 200 MB.

B

$25

$.02 for each MB after 2,000 MB ( approx. 2 GB).

C

$50

Unlimited data.

The program will inform the user if it would be less expensive to upgrade. (plan A to B or C, etc.) and display the cost saving. The factor for upgrades is as follows:

Package

Decision point

Cost savings

A

> $25

cost of A     cost of B.

A

> $50

cost of A    cost of C.

B

> $50

cost of B    cost of C

You may use a switch statement to display the cost of the package and the cost of upgrading.

Package

Base Price

Additional Fees

A

$15

$.06 for each MB after 200 MB.

B

$25

$.02 for each MB after 2,000 MB ( approx. 2 GB).

C

$50

Unlimited data.

Explanation / Answer

#include <iostream>
using namespace std;

int main(){
char package;
int mb;
do{
cout << "Enter the package: ";
cin >> package;
if(package != 'A' && package != 'a' && package != 'B' && package != 'b' && package != 'C' && package != 'c') cout << "Invalid entry ";
}while(package != 'A' && package != 'a' && package != 'B' && package != 'b' && package != 'C' && package != 'c');

do{
cout << "Enter the number of megabytes used: ";
cin >> mb;
if(mb < 0 || mb > 10000) cout << "The value should be between 0 and 10000 ";
}while(mb < 0 || mb > 10000);

double totalCost = 0, totalCostA, totalCostB = 0, totalCostC = 0;
totalCostA = 15 + (mb - 200) * 0.06;
totalCostB = 25 + (mb - 2000) * 0.02;
totalCostC = 50;
switch(package){
case 'A':
case 'a':
totalCost = totalCostA;
break;
case 'B':
case 'b':
totalCost = totalCostB;
break;
case 'C':
case 'c':
totalCost = totalCostC;
break;
}
cout << "Total cost paid by you: $" << totalCost << " ";
if(totalCost > totalCostC){
cout << "You should upgrade to package C which would save you $" << (totalCost - totalCostC) << " ";
}
else if(totalCost > totalCostB){
cout << "You should upgrade to package B which would save you $" << (totalCost - totalCostB) << " ";
}
}