CS 60, Fall 2009
Assignment 4

This project incorporates several exercises from the Nagler text [shown in brackets below]. You should read that text through chapter 7 to learn the required techniques. To the extent that instructions here differ from the text, these instructions take precedence.

Copies of all necessary files are also in ~cs60/hw4/, along with executable versions of all test programs and a Makefile for part 4. Here are exact results for parts 1, 2 and 4 (results for part 3 will vary depending on user input).

Due: Wednesday, November 18, 9:00 pm
Worth: 100 homework points

  1. [See Nagler exercise 4.1, p. 58] Complete swapper.cpp by writing the following parts:
    1. Forward declarations for both swap functions, swapByPointer and swapByReference.
    2. Complete definitions of both swap functions.
    Do not change main. Use it as is to test your functions.
  2. [See Nagler exercise 4.2, p. 59] Complete finder.cpp by writing the (a) forward declaration and (b) definition for the find function used by main. Do not change main.
  3. [See Nagler exercise 5.3, pp. 70-71] Complete array.cpp by writing the (a) forward declarations and (b) definitions for the four functions described in the text, with just one exception: Do not change main. Be sure the output exactly matches the output of the executable program, ~cs60/hw4/executables/array. That program expects the user to repeatedly enter row and column values to standard input, and end the input with a ctrl-D.
  4. [See Nagler exercise 7.8, pp. 161-162] Complete both header files and both implementations for the classes, Int and Complex, described in the exercise.
    1. int.h - interface for class Int. The public interface must include default, converting, and copy constructors; a destructor; and an accessor for the integer value. Also declare the non-member function to add two Ints.
    2. int.cpp - implement all functions declared in int.h. Test your implementation at this time, but do not turn in any test programs that you write.
    3. complex.h - interface for class Complex. The public interface must include default, converting, complete (2-argument), and copy constructors; a destructor; accessors for each Int value; and a display function. Declare the non-member function to add two Complexes.
    4. complex.cpp - implement all of the functions declared in complex.h.
    Use testcomplex.cpp to test your implementation. Results must match our solution's results (see link at top of this page).
  5. There are seven files to turn in. We suggest you use the following procedure to remember all of them. Late projects may not be accepted.

Updated 11/3/09 by C. Michael Costanzo