C Programming and Makefiles
Due: 11:00pm, Monday, September 9, 2024
Get the Assignment Code
Login to your university Unix account and copy the assignment code to a location under your home directory:
cp -r /export/home/public/schwesin/csc328/assignments/project1 LOCATION
where LOCATION
is a directory of your choosing.
CPSC 135 Project Description
In shopping for a new house, you must consider several factors. In this problem the initial cost of the house, estimated annual fuel costs, and annual tax rate are available. Write a program that will determine the total cost after a five-year period for each set of house data below. You should be able to inspect your program output to determine the “best buy”. Your program must run through three houses for comparison, each time it is run (do not run it three times for three houses).
To calculate the house cost, add the fuel cost for five years to the initial cost, then add the taxes for five years. Taxes for one year are computed by multiplying the tax rate by the initial cost.
Write and call a function for each of the following tasks:
Display instructions to the user
Compute and return the tax amount for one year
Compute and return the fuel cost for a five-year period
Compute and return the total house cost given the initial cost, the five-year fuel cost, and the annual tax amount
Print the output
The input, entered by the user, consists of the initial cost of the house, the annual fuel cost, and the annual tax rate (as a percentage). The output should be the initial house cost, annual fuel cost, annual tax amount (not the rate), and the total cost for that house. The output should be displayed in a nice, comparative form.
Use the following data when you hand in the program:
Initial House Cost Annual Fuel Cost Tax Rate
$167,000 $2300 0.025
$162,000 $2500 0.033
$175,000 $1850 0.020
Specifications
The name of the compiled program must be
p1
.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-c <double>
(required) the house cost-f <double>
(required) the fuel cost-t <double>
(required) the tax rate-y <integer>
(optional) number of years; the default value is 5.
For example, the first test input above would be executed as:
./p1 -c 167000 -f 2300 -t 0.025
The project must be separated into four files:
main.c
the main functionparse.c
the command line parsing functionalityutility.c
the function definitions listed in the above descriptionMakefile
the makefile to build the project
The
Makefile
criteria is as follows:- the default target should build the
p1
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
atof
function to convert a C string into floating point number and theatoi
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
TBD
Grading Criteria
- Correct implementation of the specification