C Programming and Makefiles
Due: 5:00am, Wednesday, September 3, 2025
Computer Science I Project Description
Write a program that will calculate and print out bills for the city water company. The water rates vary, depending on whether the bill is for home use, commercial use, or industrial use. A code of h means home use, a code of c means commercial user, and a code of i means industrial use. Any other code should be treated as an error. The water rates are computed as follows:
Code h:
- $10.00 for the first 100 gallons
- $0.05 each for 101 through 200 gallons
- $0.02 each for 201 or more gallons
Code c:
- $500.00 for the first 1000 gallons
- $0.08 each for 1001 through 2500 gallons
- $0.06 each for 2501 or more gallons
Code i:
- $1500.00 for the first 5000 gallons
- $0.07 each for 5001 or more gallons
Your program should accept an account number, the code, and the gallons of water. Your program should echo the input data and print the amount due from the user.
The program MUST utilize functions and MUST contain at least one if statement and at least one switch statement.
Specifications
The name of the compiled program must be
p0
.The input to the program must be in the form of command line arguments as follows:
-h
(by itself with no other arguments) print the usage instructions-a <integer>
(required) the account number-c <char>
(required) the code; valid codes are: ‘h’, ‘c’, and ‘i’.-g <integer>
(required) the number of gallons
Note that the command line arguments must be able to be entered in any arbitrary order,
The project must be separated into at least two separate files.
The
Makefile
criteria is as follows:- the default target should build the
p0
executable - file dependencies must be handled correctly
- must have a target named
clean
that removes object files and the compiled executable
- the default target should build the
Implementation Notes
The
getopt
function is useful for implementing command line parsing. The details can be read on the man page by executing the commandman -S 3 getopt
For this project, you can use the
atoi
function to convert a C string into an integer. These functions do no error checking on the input, so you are not expected to perform complete input validation.
Turning in the Assignment
For this assignment, you must turn in a zip file of a directory named
project0
containing the appropriate files.
Submit the zip file to the appropriate folder on D2L.