/* Mobile Service Provider - A mobile phone service has three different subscription
packages for its customers:
* Package A: For $39.99 per month 450 minutes are provided. Additional minutes are
$0.45 per minute.
* Package B: For $59.99 per month 900 minutes are provided. Additional minutes are
$0.40 per minute.
* Package C: For $69.99 per month unlimited minutes provided.
This program calculates a customer's monthly bill. It asks which package the
customer has purchased and how many minutes were used. It then displays the
total amount due. */
#include "Utility.h"
int main()
{
/* Constants for provided minutes for package A and B */
const int MINUTES_PACKAGE_A = 450,
MINUTES_PACKAGE_B = 900;
/* Constants for base cost for packages A, B, and C */
const double BASE_COST_PACKAGE_A = 39.99,
BASE_COST_PACKAGE_B = 59.99,
BASE_COST_PACKAGE_C = 69.99;
/* Constants for additional cost per minute for package A and B */
const double ADD_COST_PACKAGE_A = 0.45,
ADD_COST_PACKAGE_B = 0.40;
/* Constant for maximum number of minutes for input valdiation purposes */
const int MAX_NUM_MINUTES = 59;
/* Constants for subscription package menu choices */
const int PACKAGE_A = 1,
PACKAGE_B = 2,
PACKAGE_C = 3,
QUIT = 4;
/* Hold menu choice for switch case statement */
int choice = 0;
/* Hold base cost and total cost for calculations */
double totalCost = 0;
/* Hold number of hours, number of minutes, number of minutes extra, and
total call length */
int numHours = 0,
numMinutes = 0,
numMinutesExtra = 0,
totalCallLength = 0;
/* Display menu */
cout << "\t\tMobile Service Provider - Phone Bill Calculator\n\n"
<< "Welcome to your personal service area. Here you can calculate the\n"
<< "total cost of your telephone bill, based on your subscription\n"
<< "package. To do so, please select your package from the menu.\n\n"
<< "1. PACKAGE A\n"
<< "2. PACKAGE B\n"
<< "3. PACKAGE C\n"
<< "4. QUIT\n\n"
<< "Please enter your choice: ";
cin >> choice;
/* Switch case statements */
switch (choice)
{
case 1:
/* Display the customers menu choice and information about his or her
subscription package */
cout << "\nThe package you subscribed is: PACKAGE A.\n"
<< "This package costs: $" << BASE_COST_PACKAGE_A
<< " per month and includes " << MINUTES_PACKAGE_A << " minutes.\n"
<< "An additional cost of: $" << ADD_COST_PACKAGE_A << " per minute\n"
<< "will be charged if the total amount of minutes is greater than the\n"
<< "amount of minutes covered by your subscribed package.\n";
/* Ask the customer for total length of phone calls in hours and minutes */
cout << "\nPlease enter the total amount of time in hours: ";
cin >> numHours;
cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
cin >> numMinutes;
/* Calculations - adding the number of hours and minutes to determine
the total length of calls in minutes for further calculations */
numHours *= 60;
totalCallLength = (numHours + numMinutes);
/* Input validation */
if (numMinutes < 0 || numMinutes > 59)
{
cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
}
/* Determine whether the total call length is above or below 450 minutes,
calculate and display the total cost */
else if (totalCallLength <= MINUTES_PACKAGE_A)
{
/* Display information and total cost of the phone bill */
cout << "\nThe total length of your calls this month was: "
<< (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
<< "You didn't use up the total amount of minutes covered by your subscription\n"
<< "package of: " << MINUTES_PACKAGE_A << " minutes this month.\n"
<< "The total number of minutes of calls is: "
<< totalCallLength << " minutes.\n\n"
<< "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_A << endl;
}
else if (totalCallLength > MINUTES_PACKAGE_A)
{
/* Calculating the total call length and cost of calls plus extra */
numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_A);
totalCost = BASE_COST_PACKAGE_A + (numMinutesExtra * ADD_COST_PACKAGE_A);
/* Display information about minutes used, extra minutes not included in
the subscribed package, and total cost of the phone bill */
cout << "\nThe total length of your calls this month was: "
<< (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
<< "You used up an additional amount of " << numMinutesExtra
<< " minutes extra not covered by\n"
<< "your subscription package which only includes "
<< MINUTES_PACKAGE_A << " minutes.\n"
<< "Additional fees of: $" << ADD_COST_PACKAGE_A
<< " per minute will be charged.\n\n"
<< "Base cost: $" << BASE_COST_PACKAGE_A
<< "\nPlus: $ " << ADD_COST_PACKAGE_A << " extra.\n\n"
<< "The total cost of your phone bill is: \t$" << totalCost << endl;
}
break;
case 2:
/* Display the customers menu choice and information about his or her
subscription package */
cout << "\nThe package you subscribed is: PACKAGE B.\n"
<< "This package costs: $ " << BASE_COST_PACKAGE_B
<< " per month and includes " << MINUTES_PACKAGE_B << " minutes.\n"
<< "An additional cost of: $" << ADD_COST_PACKAGE_B << " per minute\n"
<< "will be charged if the total amount of minutes is greater than the\n"
<< "amount of minutes covered by your subscribed package.\n";
/* Ask the customer for total length of phone calls in hours and minutes */
cout << "\nPlease enter the total amount of time in hours: ";
cin >> numHours;
cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
cin >> numMinutes;
/* Calculations */
numHours *= 60;
totalCallLength = (numHours + numMinutes);
/* Input validation */
if (numMinutes < 0 || numMinutes > 59)
{
cout << "You entered an invalid amount of minutes. Please use 0 to 59 only.\n";
}
/* Determine whether the total call length is above or below 900 minutes, calculate
and display the cost */
else if (totalCallLength <= MINUTES_PACKAGE_B)
{
/* Display information and total cost of the phone bill */
cout << "\nThe total length of your calls this month was: "
<< (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
<< "You didn't use up the total amount of minutes covered by your subscription\n"
<< "package of: " << MINUTES_PACKAGE_B << " minutes this month\n"
<< "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
<< "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_B << endl;
}
else if (totalCallLength > MINUTES_PACKAGE_B)
{
/* Calculating the total call length and cost of calls plus extra */
numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
totalCost = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
/* Display information about minutes used, extra minutes not included in
the subscribed package, and total cost of the phone bill */
cout << "\nThe total length of your calls this month was: "
<< (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
<< "You used up an additional amount of: " << numMinutesExtra
<< " minutes extra not covered by\n"
<< "your subscription package which only includes "
<< MINUTES_PACKAGE_B << " minutes.\n"
<< "Additional fees of $" << ADD_COST_PACKAGE_B
<< " per minute will be charged.\n\n"
<< "Base cost: $" << BASE_COST_PACKAGE_B
<< "\nPlus: $ " << ADD_COST_PACKAGE_B << " extra.\n\n"
<< "The total cost of your phone bill is: \t$" << totalCost << endl;
}
break;
case 3:
/* Display the customers menu choice and information about his or her
subscription package */
cout << "\nThe package you subscribed is: PACKAGE C.\n"
<< "This package costs: $ " << BASE_COST_PACKAGE_C
<< " which includes an unlimited amount of minutes.\n"
<< "No additional costs will be charged.\n";
/* Ask the customer for total length of phone calls in hours and minutes */
cout << "\nPlease enter the total amount of time in hours: ";
cin >> numHours;
cout << "And the total amount of time in minutes (min. 0 and max. 59 minutes): ";
cin >> numMinutes;
/* Calculations */
numHours *= 60;
totalCallLength = (numHours + numMinutes);
/* Input validation */
if (numMinutes < 0 || numMinutes > 59)
{
cout << "\nYou entered an invalid amount of minutes. Please use 0 to 59 only.\n";
}
/* Determine whether the total call length and display the cost */
else
{
/* Display information and total cost of the phone bill */
cout << "\nThe total length of your calls this month was: "
<< (numHours / 60) << " hours and " << numMinutes << " minutes.\n"
<< "You have an unlimited amount of minutes covered by your subscription.\n"
<< "The total number of minutes of calls is: " << totalCallLength << " minutes.\n\n"
<< "The total cost of your phone bill is: $" << BASE_COST_PACKAGE_C << endl;
}
break;
case 4:
/* Displaying a quit message */
cout << "\nYou decided to quit the program. Thank you for your patronage!\n";
break;
default:
/* If the menu choice is invalid and error message is displayed */
cout << "\nDear customer, you entered an invalid menu choice. Please choose 1 through 3, or\n"
<< "4 to quit this program. Thanks for your understanding.\n";
break;
}
pauseSystem();
return 0;
}
Sunday, November 27, 2016
Programming Challenge 4.25 - Mobile Service Provider
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment