Program #1

Write a program to calculate and print out cellular phone bills for one month, and write a test plan to test the program.

The rates will vary depending on the calling plan of the customer:

Fixed rate plan (code F),
per Minute charge plan (code M),
Home customer plan (code H),
home Plus customer plan (code P), or
Business customer plan (code B).

The rates are as follows:

  • Code F: A flat $150.00 fee for unlimited minutes (not available to businesses)
  • Code M: A charge of $5, plus 21 cents a minute
  • Code H: $40 for the first 600 minutes used, plus 19 cents for each additional minute.
  • Code P: $64 for the first 1000 minutes used, plus 17 cents for each additional minute
  • Code B: $150 for up to 2,000 minutes; $210 for up to 3,000 minutes, and $240 if over 3,000 minutes

No other codes should be accepted. Remember to define constants for all fixed values. Use double precision floating point variables for all dollar & cents figures.

The program should first explain the program to the user.

Then prompt for a 5-digit customer account number (no leading zeros allowed) and error check that the value entered is valid. Re-prompt until a valid value is entered. This input should be read and error checked from within the main function.

Next call display a menu of plan codes, along with descriptions of each, to the user. Prompt for the plan code and error check that the user entered a valid plan code (accepted in upper or lowercase). Re-prompt until a valid value is entered.

If necessary (all plans except plan F), also prompt for the number of minutes used and error check that the number entered is not negative (i.e. must be at least 0). Minutes used will always be whole numbers. Re-prompt until a valid value is entered.

Calculate the bill total and display the results.

The output should display: the customer account number, the plan chosen in words, the number of minutes used (unless the plan chosen was F), and the total amount of the bill. Display neatly with descriptive text.

After displaying the results, ask the user whether to execute the program again, and do so, as long as the user wishes to continue.

At a minimum, the program must implement three separate functions (in addition to main), as described on the next page:

  • One function to read and validate the plan choice, and if necessary, to read and validate the number of minutes used. Both the plan choice and the number of minutes used will be passed back to main via reference parameters.
  • One function to calculate the amount of the bill and return the bill amount. Pass in any necessary data as input parameters.
  • One function to display the bill output. Pass in any necessary data as input parameters.

Use of global variables is NOT allowed. The functions must use parameters to pass required data to each function. Remember to pass all input only parameters by value, and pass all output parameters by reference.

Testing

As part of your submission for this week, you must write a test plan for this program (program 1). First list the rationale for creating your test cases. Then create each test case. Your test cases should include all INPUTs you used for the test and what OUTPUT you expected. Submit your test plan as an MS Word document or an MS Excel spreadsheet.

Program #2

Write a program to compare the return from a yearly compounded interest calculation (i.e. figured and added to the balance annually) to interest that is compounded monthly, weekly, or daily.

The program should:

  • Use double precision floating point variables, where floating point variables are used.
  • Let the user choose from a menu which comparison to make (compounded monthly, weekly, or daily). A fourth menu choice, exit the program, should be included on the menu.
  • Ask the user for a beginning balance, an annual interest rate, and a term in years.
    • Error check each of the above items, one at a time, as they are entered. All of them must be at least 1. Additionally, annual interest cannot be more than 50%, and the term should not be more than 100 years. For each item, re-prompt the user until a valid value is entered. Error messages should tell the user what values are valid.
  • Display the total return computed with annual compounding versus interest compounded monthly or weekly or daily, formatted as shown in the Sample Run.
    • The total compounded returns must be calculated using nested loops, NOT banking interest formulas. You will compute the interest and add it to the balance each time you loop.
    • Calculate annual interest by adding annual interest to the running balance every year.
    • Calculate monthly interest by adding monthly interest (use 1/12th of the annual interest rate) to the running balance every month for 12 months per year.
    • Calculate weekly interest by adding weekly interest (use 1/52nd of the annual interest rate) to the running balance every week for 52 weeks per year.
    • Calculate daily interest by adding daily interest (use 1/365th of the annual interest rate) to the running balance every day for 365 days per year.
  • Loop back to the menu, and continue until the user chooses EXIT from the menu.
    • The program should ONLY exit when the user chooses EXIT from the menu.
    • Do NOT ask the user if s/he wishes to run the program again – just redisplay the menu each time until EXIT is chosen.

In addition to main, your program must contain a minimum of four additional functions with parameters and/or return values. You should try to use functions to reduce code duplication, when the code is similar in multiple places.

HINT: When you consider how to break this program into functions, think about how program 1 was divided up:

  • At least one function to read input
  • At least one function to do calculations
  • At least one function to display output

Use of global variables is NOT allowed. The functions should use parameters to pass required data to each function. Remember to pass all input parameters by VALUE, and pass all output parameters by REFERENCE.

Display dollar figures to 2 decimal places and the interest rate to 3 decimal places.

Sample Run

This program demonstrates the benefits of compounding interest.
Compare Annual Compounding to:
M - Monthly Compounding
W - Weekly Compounding
D - Daily Compounding
E - Exit Program
Enter choice from Menu above: w
Enter your beginning balance: 5555.55
Enter an annual interest rate: 5.5
Enter a term in whole years: 5
------------------------------------------------
RESULTS
------------------------------------------------
Beginning Balance: 5555.55
Return after 5 years at 5.500% interest annually:
Return Ending Balance
Compounded Yearly: $ 1705.33 $ 7260.88
Compounded Weekly: $ 1757.44 $ 7312.99
------------------------------------------------
Press any key to continue . . .

When the user presses a key to continue, the program will loop and re-display the menu. The program will exit when the user chooses EXIT from the menu.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.