Homework Assignment 1

The purposes of this assignment are two-fold. First we will learn how to write simple C programs. The second objective of this assignment is to become familiar the use of Makefiles for compiling programs. For an introduction to Makefiles, see Section 15.1 of the class notes.

Due : September 18, 1997.


Problem 1

For each program, hand in a copy of the program source code, and samples of the program input and output. Also hand in a copy of the makefile that compiles each of these programs.


P.S. -- Here is a a sample Makefile to get you started.

# ==========================================================
# Makefile for Computer Programs in Part 1 of Book             
#
# To compile all of the programs, type: make all
# To compile individual programs, type: make first
#                                       make area
#                                       make quad
#
# Written By: M. Austin                         January 1996
# ==========================================================

CFLAGS = -DDEBUG

.cc.o:	        
		g++ -c $(CFLAGS) -O  $<
.c.o:
		gcc -c -O $<

PROGRAM1  =  prog_first_program.o
PROGRAM2  =  prog_area.o
PROGRAM3  =  prog_quadratic.o
PROGRAM4  =  prog_rainfall.o

# Compile all C Programs.

all::first area quad rain

# Compile Individual C Programs.

first: $(PROGRAM1)
	gcc $(PROGRAM1) -o FIRST

area: $(PROGRAM2)
	gcc $(PROGRAM2) -lm -o AREA

quad: $(PROGRAM3)
	gcc $(PROGRAM3) -lm -o QUADRATIC

rain: $(PROGRAM4)
	gcc $(PROGRAM4) -lm -o RAINFALL

# Remove all object files and program output file.

clean:
	/bin/rm -f *.o
	/bin/rm -f output-*

Read the notes for an explanation for how things work!


Developed in September 1997 by Mark Austin
Last Modified September 10, 1997
Copyright © 1997, Mark Austin, Department of Civil Engineering, University of Maryland