CS 222/420   Winter 1999,  Instructor:  Jeffrey Horn

HOMEWORK 4:  POINTERS and OPERATOR OVERLOADING
 
Handed out/Assigned: Friday, March 12, 1999
Due: Wednesday, March 31, 1999

STEPS:

This assignment has three tasks:
 
  1.    Modify your the code for HW3, Binary Search, so that only pointers to individuals are used.  For example, the array of individuals in SortedArray should become an array of pointers to individuals instead.  Also, all methods of SortedArray and Individual classes should take pointers to individuals as arguments (as appropriate!) and never an individual.  The motivation for these changes is that Individual is becoming a much more complex and larger class, thus we wish to avoid making copies of an individual at any point.
  2.    Put correct "include guards" compiler directives in all of your code files.
  3.    Overload the "==" , "!=", "<", ">",  "<= and ">=" operators for the class Individual, and use them.  These are in place of "Individual::equal" and "Individual::greater", etc.  NOTE:  For the overloaded operators, do NOT make these take pointers as arguments.   Instead, let them take individuals as arguments, just as the methods "equal" and "greaterThan" USED TO (you are changing THOSE to take pointers to individuals, in this assignment).  The reason for NOT taking pointers for "==" and ">=" etc., is an aesthetic one:  we generally like to see the same data type on both sides of an "==" sign.
WHAT TO HAND IN:  Hand-in the code, both hardcopy and sending me the ascii text file by email to jhorn@nmu.edu.  And DO comment!  (I always find it easier to go back and add comments later, but whatever works for you.  See my style of commenting.  At the very least, comment modules such as classes, methods, and functions, that you write or modify.)

PURPOSE:  Learn the use of pointers in C++!  (including the advantages and disadvantages, and when to use them)  Also, overloading operators, and when to do that!  Also, learn to use "include guards" on files.

 SPECIFICS:  Same as in HW3.

EXAMPLES: