Program #1

Write a program that will calculate and print out bills for the city water company, and write a test plan to test the program.

The water rates vary, depending on whether the bill is for home use (code H), commercial use (code C), or industrial use (code I).

No other codes should be accepted. Remember to define constants for all fixed values.

The water rates are computed as follows:

  • Code H: A $15 flat fee, plus 0.0005 of a dollar per gallon used
  • Code C: $1,000 for the first 4 million gallons used, and 0.00025 for each additional gallon used.
  • Code I: $1,000 for usage up to 4 million gallons; $2,000 if usage is over 4 million gallons but does not exceed 10 million gallons; and $3,000 if usage is over 10 million gallons.

The program input will be the four-digit user account number, the type code, and if necessary, the number of gallons used.

The program should first explain the program to the user.

Then prompt for a 4-digit user account number (no leading zeros allowed) and error check that the value entered is valid (integer value that must be in the range of 1000 to 9999). Re-prompt until a valid value is entered. This input should be read and error checked from within the main function.

Then call a user-defined function that will:

  • Display a menu of use codes, along with a category for each (Home User, Commercial User, Industrial User), to the user. Prompt for the use code and error check that the user entered a valid use code (accepted in upper or lowercase). Re-prompt until a valid value is entered.
  • Prompt for the number of gallons used and error check that the number entered is not negative (i.e. must be at least 0). Re-prompt until a valid value is entered.
  • Pass back both a valid use code and a number of gallons used via reference parameters.

Then call a user-defined function that will:

  • Calculate the bill total

Then call a user-defined function that will:

  • Display the results.

The output should display: the plan chosen in words (not the calculation method), the number of gallons used, 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.

So at a minimum, the program should implement three separate functions (in addition to main), as described below:

  • One function should read the use code and gallons used input from the user and pass the data read for both back to main via reference parameters.
  • One function should calculate the amount of the bill and pass back the total. Pass in any necessary data as input parameters.
  • One function should 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.

As part of your submission for this week, you must write a test plan for this program (program 1). 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.

NOTE: No sample inputs or sample outputs will be given for program #1 this week, to allow you to develop your own tests for your test plan.

Program #2

Write a modular program to convert 7-letter words to the corresponding telephone numbers that they represent. The letter to digit conversion will be as follows:

ABC = 2 DEF = 3 GHI = 4 JKL = 5
MNO = 6 PRS = 7 TUV = 8 WXY = 9

The letters entered can be either upper or lowercase. No digit corresponds to Q or Z, so those letters cannot be used in the phone number. Non-alphabetic characters cannot be used either. If a character is invalid, the program should also display an error message saying specifically what the error was. (NOTE: Before you discover an error, you may have already displayed some numbers. That is okay.)

First prompt the user for a 7-letter word. The program should read and process the characters one at a time. As you read each character, call functions to check that the character entered is valid, and if it is valid, to display the equivalent digit (Note: Be sure to display a dash at the correct location in the phone number, format: xxx-xxxx).

The program should also count the characters as you read them, through the end of the line or until an error is discovered. STOP processing the line as SOON as you discover an error (remember to read past all remaining characters before you loop to process the next word).

If the program IS able to convert all of the letters of the word correctly, check the length and display an error if the user's word is too long or too short saying so and that the phone number displayed is NOT valid.

Continue to prompt for words and convert them, until the user indicates s/he is done (your choice how).

This program should include at least two additional user-defined functions with parameters (not including main()).

Sample Run (after program description to user):

Enter word to convert (or # to exit): Flowers

Phone number is: 356-9377

Enter word to convert (or # to exit): BBB

Phone number is: 222
ERROR – phone number is too short!

Enter word to convert (or # to exit): ALLQUIT

Phone number is: 255
ERROR – Q is not allowed

Enter word to convert (or # to exit): XXXXXXXX

Phone number is: 999-99999
Error – phone number is too long!

Enter word to convert (or # to exit): #

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

Remember to pass all input only parameters by value, and pass output parameters by reference when appropriate.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only 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 fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.