0% found this document useful (0 votes)
12 views10 pages

Mobile Data Plan Cost Calculator

The document outlines a C++ program created by Zara Humayun for calculating monthly bills for mobile data plans (A, B, or C) and potential savings from switching packages. It includes user input validation for package selection and gigabyte usage, along with error handling for invalid entries. Additionally, the document provides a user guide explaining the program's purpose, assumptions, and limitations.

Uploaded by

zara287h
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views10 pages

Mobile Data Plan Cost Calculator

The document outlines a C++ program created by Zara Humayun for calculating monthly bills for mobile data plans (A, B, or C) and potential savings from switching packages. It includes user input validation for package selection and gigabyte usage, along with error handling for invalid entries. Additionally, the document provides a user guide explaining the program's purpose, assumptions, and limitations.

Uploaded by

zara287h
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

CPSC S25, Assignment #1

Zara Humayun
100487827
Instructor: Catherine Maydan
Source Code:
// FILE: [Link]
// PROGRAMMER: Zara
// INFO 1112 Section: 25
// PURPOSE: This program calculates the monthly bill for a customer's
// mobile data plan (A, B, or C). It also shows how much
// the customer could save by switching to another package.

#include <iostream> // for cin and cout


#include <iomanip> // for formatting decimal numbers
#include <cctype> // for toupper function
using namespace std; // for standard C++ names

int main()
{
// Declare variables to store package type and data used
char package; // the customer's chosen package (A, B, or C)
double gigabytes; // the number of gigabytes used in a month
double costA, costB, costC; // stores the total cost for each package
double total; // the total amount due for the chosen package

// Set output formatting for currency (2 decimal places)


cout << fixed << showpoint << setprecision(2);

// Ask the user for their package choice


cout << "Enter your package (A, B, or C): ";
cin >> package;

// Check if the user entered a valid package letter


if (package != 'A' && package != 'a' &&
package != 'B' && package != 'b' &&
package != 'C' && package != 'c')
{
cout << "Invalid package selection. Please enter A, B, or C.\n";
system("pause"); // holds the screen so user can read the message
return 0; // exit the program early if input is invalid
}

// Ask the user how many gigabytes they used


cout << "Enter the number of gigabytes used: ";
cin >> gigabytes;

// Check if the input was a number (not a letter)


if ([Link]())
{
cout << "Invalid entry: please enter a number value.\n";
system("pause");
return 0;
}

// Validate the data usage input (must be positive)


if (gigabytes < 0)
{
cout << "Invalid data usage. Please enter a non-negative value.\n";
system("pause");
return 0;
}

// Convert the package letter to uppercase for easy comparison


package = toupper(package);

// Check if Package A or B has less than the minimum base data


if (package == 'A' && gigabytes < 4)
{
cout << "Invalid entry: At least 4 GB must be used.\n";
system("pause");
return 0;
}
else if (package == 'B' && gigabytes < 8)
{
cout << "Invalid entry: At least 8 GB must be used.\n";
system("pause");
return 0;
}

// ----------------------------------------------------
// Calculate total cost for each package
// ----------------------------------------------------

// Package A: $39.99 includes 4 GB, extra $10 per additional GB


if (gigabytes > 4)
{
costA = 39.99 + (gigabytes - 4) * 10;
}
else
{
costA = 39.99;
}

// Package B: $59.99 includes 8 GB, extra $5 per additional GB


if (gigabytes > 8)
{
costB = 59.99 + (gigabytes - 8) * 5;
}
else
{
costB = 59.99;
}

// Package C: $69.99 flat rate for unlimited data


costC = 69.99;

// ----------------------------------------------------
// Display results for each package and possible savings
// ----------------------------------------------------

if (package == 'A')
{
total = costA; // total cost for Package A
cout << "\nYou selected Package A.\n";
cout << "Your total amount due: $" << total << endl;

// Compare Package A with B and C to show possible savings


if (costB < costA)
{
cout << "You could save $" << costA - costB
<< " by switching to Package B.\n";
}
if (costC < costA)
{
cout << "You could save $" << costA - costC
<< " by switching to Package C.\n";
}
}
else if (package == 'B')
{
total = costB; // total cost for Package B
cout << "\nYou selected Package B.\n";
cout << "Your total amount due: $" << total << endl;

// Compare Package B with A and C


if (costA < costB)
{
cout << "You could save $" << costB - costA
<< " by switching to Package A.\n";
}
if (costC < costB)
{
cout << "You could save $" << costB - costC
<< " by switching to Package C.\n";
}
}
else if (package == 'C')
{
total = costC; // total cost for Package C
cout << "\nYou selected Package C.\n";
cout << "Your total amount due: $" << total << endl;

// Compare Package C with A and B


if (costA < costC)
{
cout << "You could save $" << costC - costA
<< " by switching to Package A.\n";
}
if (costB < costC)
{
cout << "You could save $" << costC - costB
<< " by switching to Package B.\n";
}
}

// Print final message


cout << "--------------------------------------------\n";
cout << "Thank you for using the Data Plan Calculator!\n\n";
cout << "Written by: Zara INFO 1112 Section: 25\n";

system("pause"); // pause the program so the window stays open


return 0;
}

(Comments added within the code)

Test Runs:

1)

Test run for Plan A – Valid entries and savings

2)

Test run for Plan B – Valid entries and savings

3)
Test run for Plan C - Valid entries

4)

Invalid entry – Not a Plan option.

5)

Invalid entry – gigabytes entered is not a number value.

6)

Invalid entry – At least four gigabytes must be used for Plan A

7)
Invalid entry – At least eight gigabytes must be used for Plan B.

The following page will display the “User Guide”.

User Guide
Purpose:

This program helps mobile phone customers find out how much their monthly data plan will cost
and whether they could save money by switching to another plan.

It’s made for regular users who just want to see which package (A, B, or C) gives them the best
deal based on how many gigabytes they use each month.

The program will calculate the total amount due for your current plan and display how much
money you could save with a different one if it allows you to save more money. If another Plan
will not save you more money, it will not be displayed.

Sample Session:

Assumptions/Limitations:

1. If an invalid input is entered (like a letter instead of a number, or an invalid package letter
option), the program will show an error message and must be run again.
2. The data usage entered should be a numeric value in gigabytes (GB). Letters or symbols
will cause an invalid entry message.
3. For Packages A and B, the minimum data entered must meet the base amount of the plan
(4 GB for A, 8 GB for B). If less is entered, the program will display an error and stop.
4. Prices are fixed and do not include tax or special discounts.

Hierarchy Chart

Common questions

Powered by AI

The program suggests switching plans when an alternative offers a lower cost than the current usage. For example, if a user on Package A uses more than 8 GB, switching to Package B or C could be cheaper due to lower per-GB costs after the base threshold and unlimited data benefits, respectively .

The program calculates and displays potential savings by comparing the user's current plan cost with other options. It shows the specific amount that could be saved if switching leads to financial benefits. This feature empowers users by making potential cost advantages explicit, facilitating informed decision-making when choosing or switching data plans .

Invalid inputs trigger error messages and program termination, ensuring data integrity but requiring users to restart the program. This approach maintains accuracy but may impact usability for users unfamiliar with correct input formats. Thus, while it ensures correct data processing, it can frustrate users and increase the learning curve .

The program is designed to calculate the monthly bill for a customer's mobile data plan and provide possible savings by switching to another plan. This benefits customers by allowing them to identify the most cost-effective data plan based on their current usage, potentially saving money if a cheaper option is available .

For package selection, the program checks if the entered package letter is either 'A', 'B', or 'C' and considers case variations. For data usage, it ensures the input is numeric and checks that it meets the minimum requirements: at least 4 GB for Package A and 8 GB for Package B. Invalid entries result in an error message and program termination .

Package A is $39.99 for 4 GB, with $10 per extra GB. Package B is $59.99 for 8 GB, with $5 per extra GB. Package C is $69.99 for unlimited data. Users with low data usage (around 4 GB) may find Package A cost-efficient, while those with moderate usage may save by using Package B. Heavy users could benefit from the fixed cost of Package C. The strategy implies a tiered pricing model encouraging users to select plans based on predictable usage patterns .

The program checks if the data usage entry is a numeric value and requires a minimum base usage of 4 GB for Package A and 8 GB for Package B. Ensuring only valid entries prevents calculation errors and helps maintain accurate billing and savings information, thus importance lies in preventing financial inaccuracies .

Improvements might include adding a graphical interface for easier navigation, incorporating tax and discount calculations, implementing an interactive tutorial for first-time users, and adding real-time updates if plan prices change. Enhancing error messages with suggestions for corrections could also improve user experience .

Requiring a minimum data usage for Plans A and B ensures that users choose appropriate plans based on actual consumption, discouraging under-usage plans that could lead to lost revenue. This strategy might optimize network resource allocation and predictability in revenue streams, benefiting the service provider .

Incorporating taxes would increase the total cost, necessitating an additional calculation step before displaying the final amount. Discounts could require conditional logic to determine eligibility and apply reductions accordingly. Both would add complexity but could provide a more accurate representation of the user's actual financial obligations .

You might also like