Monday, November 28, 2016

Programming Challenge 4.26 - Mobile Service Provider Mod

/* Mobile Service Provider Mod - 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.

   ----------------------------------------------------------------------------------------

   Rev 1: This program displays how much money Package A customers would save, if they
   purchased Package 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 will be printed.
  
   All calculations are based on the assumption, that a customer constantly makes calls
   totaling to a lower amount of minutes than is included in their respective package,
   to suggest to switch to a smaller package. This only applies to a switch from package
   C to B, and, in case, from B to A if this promises savings. */

#include "Utility.h"

int main()
{
    /* Constants for provided minutes for package A and B

       Rev 1: minutes calc is added for calculation purposes and initialized with a
       value of 1440 minutes equaling 24 hrs. */
    const int MINUTES_PACKAGE_A = 450,
              MINUTES_PACKAGE_B = 900,
              MINUTES_CALC = 1440;

    /* 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
    Rev 1: savings, totalSavings, and premium savings */
    double totalCost = 0,
        savings = 0,
        totalSavings = 0,
        premiumSavings = 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"
                << "The total call length in minutes was: \t" << totalCallLength
                << " minutes.\n\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;
        }

        /* Rev 1: Calculation of total savings (if any) a customer would save if he or she opted
        for PACKAGE B or PACKAGE C. If there are any savings to be made, additional
        output indicating the ideal package is displayed */
        if (totalCallLength >= MINUTES_PACKAGE_B && totalCallLength < MINUTES_CALC)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);

            cout << "\n\nIf you would opt for a subscription of PACKAGE B, you would be able\n"
                << "to make some real savings!\n\n"
                << "PACKAGE B would only cost: $" << BASE_COST_PACKAGE_B
                << " per month and includes " << MINUTES_PACKAGE_B << " minutes.\n"
                << "An additional cost of: $" << ADD_COST_PACKAGE_B << " per minute "
                << "would be charged if the total\n"
                << "amount of minutes is greater than the amount of minutes covered.\n\n"
                << "This month you would only have had to pay: $" << savings
                << " with PACKAGE B.\n"
                << "The total savings would have been as much as: $" << totalSavings << endl;
        }

        /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
        to opt for a subscription of PACKAGE C instead of B if this is a cost saving option */
        else if (totalCallLength > MINUTES_CALC)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);
            premiumSavings = (totalCost - BASE_COST_PACKAGE_C);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE C.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would have amounted to a saving of only: $" << totalSavings
                << "\n\nWith our premium package you would only have had to pay: $" << BASE_COST_PACKAGE_C
                << " only once!\n"

                << "The premium savings would amount to: $" << premiumSavings << "!\n\n";
        }

        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;
        }

        /* Rev 1: Calculation of total savings (if any) a customer would save if he or she opted
        for PACKAGE A or PACKAGE C. If there are any savings to be made, additional
        output indicating the ideal package is displayed */
        if (totalCallLength <= MINUTES_PACKAGE_A)
        {
            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_A;
            totalSavings = (BASE_COST_PACKAGE_B - savings);

            cout << "\n\nIf you would opt for a subscription of PACKAGE A, you would be able\n"
                << "to make some real savings!\n\n"
                << "PACKAGE A would only cost: $" << BASE_COST_PACKAGE_A
                << " per month and includes " << MINUTES_PACKAGE_A << " minutes.\n"
                << "An additional cost of: $" << ADD_COST_PACKAGE_A << " per minute "
                << "would be charged if the total\n"
                << "amount of minutes is greater than the amount of minutes covered.\n\n"
                << "This month you would only have had to pay: $" << savings
                << " with PACKAGE A.\n"
                << "The total savings would have been as much as: $" << totalSavings << endl;
        }

        /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
        to opt for a subscription of PACKAGE C instead of B if this is a cost saving option */
        else if (totalCallLength >= MINUTES_CALC)
        {

            numMinutesExtra = totalCallLength - (MINUTES_PACKAGE_B);
            savings = BASE_COST_PACKAGE_B + (numMinutesExtra * ADD_COST_PACKAGE_B);
            totalSavings = (totalCost - savings);
            premiumSavings = (totalCost - BASE_COST_PACKAGE_C);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE C.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would have amounted to a saving of only: $" << totalSavings
                << "\n\nWith our premium package you would only have had to pay: $" << BASE_COST_PACKAGE_C
                << " only once!\n"

                << "The premium savings would amount to: $" << premiumSavings << "!\n\n";
        }
        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;
        }

        if (totalCallLength < MINUTES_CALC || totalCallLength <= MINUTES_PACKAGE_B)
        {
            /* Rev 1: Calculating the savings and displaying the cost saved if a customer were
            to opt for a subscription of PACKAGE B if this is a cost saving option */
            savings = BASE_COST_PACKAGE_B;
            totalSavings = (BASE_COST_PACKAGE_C - savings);

            cout << "\n\nDear customer! Judging by the total length of your "
                << "phone calls of: " << totalCallLength << " minutes,\n"
                << "we would like to suggest you switch to a subscription of PACKAGE B.\n"
                << "\nThis month you would have had to pay as much as as: $" << savings
                << " with PACKAGE B.\n"
                << "Which would amount to a saving of: $" << totalSavings << 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;
}

No comments:

Post a Comment