course.wilkes.edu/CS125Labs
Welcome to the site for CS 125 labs!

 

Lab 3a: Instructor's Notes

Prev | Next | Lab 3a

Since chapter 3 in the text is fairly long, we have provided two lab exercises for it: 3a and 3b. In exercise 3a, students build a separately compiled library of metric conversion functions (simple, but useful). In exercise 3b, students learn to build more complicated functions that require selective and repetitive behavior. We have our students do both exercises, 3a one week and 3b the next.

Using a user-defined, separately compiled library with a program changes translation to a multi-step process:

  1. each source file is compiled to create an object file (ending in .o).
  2. The object files are then linked to create a binary executable program.
To coordinate separate compilation, UNIX systems provide the make utility. To use this utility, a programmer prepares a special file called a Makefile (beginning with capital-M by convention, not necessity). The Makefile consists of a series of pairs lines of the form:
   TargetFile: ComponentFile1 ComponentFile2 ... ComponentFileN
           Command
where Command is a UNIX command that makes TargetFile from the N ComponentFiles. Command must be preceded by a TAB and followed by a RETURN (or ENTER).

To illustrate, our binary executable program driver is made by linking the object files driver.o and Metric.o, and so the first pair in the Makefile is roughly as follows:

   driver: driver.o Metric.o
           g++ driver.o Metric.o -o driver
Similarly, driver.o is made by compiling driver.cpp</TT, which includes (and thus depends upon) Metric.h, and so the second pair in the Makefile is:
   driver.o: driver.cpp Metric.h
           g++ -c driver.cpp
The -c switch tells g++ to just compile driver.cpp and create an object file, instead of compiling and linking to create a binary executable (the default action). A similar rule specifies the making of Metric.o.

We provide a Makefile. that can be accessed from the exercise. The sections of the exercise starting with Lab 3a: Functions & Libraries teach the students about Makefile structure and how to complete it.

We also provide "starter" files in the exercise for each of the other components in the project: driver.cpp, metric.h, metric.cpp, and metric.doc. If you wish to avoid network contention and traffic, save all of these files ahead of time in a 3a subdirectory of your course directory, and instruct your students to copy them from there. (Note: Our browser replaced the TAB character before each g++ with spaces. If yours does the same, you will need to delete those spaces and replace them with a TAB.)

Prev | Next | Lab 3a

 
  Home

Help

Lab 0

Lab 1

Lab 2

Lab 3a

Lab 3b

Lab 4

Lab 5

Lab 6

Lab 7

Lab 8

Lab 9

Lab 10

Lab 11

Lab 12

Lab 13



Membership

Login




Last update: Tuesday, August 22, 2000 at 4:12:48 PM.
visitors to this page.