CS 2005, B Term 1999
Techniques of Programming
Lab 1 (Nov. 3)

Instructions

The objective of this lab session is for you to implement a test program for a C++ class that represents points in a plane. This experience will provide practice in the syntax of C++ classes and their access methods, and it should prove to be helpful in completing HW1.

  1. Sign in with the TA. You should both print your name and sign the sheet.
  2. Listen to the TA's mini-lecture.
  3. Do the problems listed below. Feel free to ask the TA questions about the problems. Don't worry if you can't finish all of the problems before the lab session is over. You can finish afterwards. However, actively working on the lab assignment during the lab session is required.


Problems

  1. Log onto your CCC Unix account and change the directory to /cs/cs2005/samples/lab1/. Copies of both the specification file newpoint.h and a separate implementation file newpoint.cxx for the Point class are available in that directory.
    1. Copy the above files to one of your own personal directories.
    2. Compile the implementation file newpoint.cxx by typing
      g++ -Wall -c newpoint.cxx
      at the Unix prompt. This produces an object file newpoint.o but does not produce an executable file. You may type man g++ at the Unix prompt for information about compiler options and details.

  2. Write your own test program pointtest.cxx that allows the user to manipulate objects of the Point class through the public member functions and non-member functions provided in newpoint.h. Your program should provide a menu of options including, at least, an option to create a Point object with given coordinates, an option to shift a Point object by given displacements, and an option to rotate a Point object by 90 degrees. An executable file for a minimal sample test program is available in /cs/cs2005/samples/lab1/goodpointtest. You should run the sample test program to see how your own test program should behave. Also see section 3.3 of the textbook and the Lab0 files in /cs/cs2005/samples/lab0/ for examples of test program source code for different classes.

  3. Compile your test program pointtest.cxx by typing
    g++ -Wall -o pointtest pointtest.cxx newpoint.o -lm
    at the Unix prompt. This compiles the test program, links the Point class implementation to it, and produces an executable file named pointtest.

  4. Run the executable file pointtest. Try it out using different options. Compare with the sample test program provided in /cs/cs2005/samples/lab1/goodpointtest. Debug your program as needed.

  5. In order to streamline the compilation and linking process, write a Makefile for your Lab1 project. This file should contain the required compiler/linker commands as described above, as well as a description of the relevant dependencies between the various files involved. Typing make at the Unix prompt causes the commands contained in the makefile to be carried out (you may want to remove some of the object and executable files before trying this). Refer to /cs/cs2005/samples/lab0/ for an example of a Makefile. See the CS2005 homepage for links to further information about Makefiles.

  6. Use any remaining time to work on HW1. Studying the Lab1 files provided in /cs/cs2005/samples/lab1/ may be helpful for this purpose.