CSC 270
Homework 5 in C++

Assigned Oct 20, due Nov 3

    Warm-up exercise

  1. Type in the code examples on pp. 37-45 of the Weiss book. For anything that doesn't compile, make sure you understand why. For anything that produces unexpected results, make sure you understand why.

    Type in a bunch of the code examples on pp. 53-83. Again, make sure you understand why things don't compile or don't work.

  2. Programming

    For the following programming problems, be sure your classes have exactly the interface I specify; I'll be testing them by linking them together with my own main function, and if they don't match up, it'll be extra work for me, which makes me cranky just at the time that I'm grading your homework :-)

    Every class should have a static test function which runs a bunch of test cases on the other functions and reports whether they all produced the expected results. You'll presumably test these things by writing a main function that calls the various test functions.

    Follow the usual C++ conventions with regard to header files, getter names, etc. Conveniently enough, Eclipse will do a lot of this for you automatically.

    Keep efficiency and memory safety in mind. For example, if you're returning a large object, decide whether to return a pointer, return a whole object, or return a const reference. Make sure accessor functions are marked as such, so the compiler can optimize them and they can be called on const objects. Watch out for memory leaks and dangling pointers/references. And so on.

  3. Define a class Date with integer fields for day-of-month, month, and year. Write the following member functions:

    Some other things to try for extra credit:
  4. Define a class RunnerLog to represent an entry in a runner's log book. It should have fields for the date of the run (a Date), how many miles (double), how many hours (double), and a free-form comment field (string). Write the following member functions:

  5. Define a class LogBook which implements a linked list of RunnerLog objects, using a null pointer internally to indicate the end of the list (although users of the LogBook class should never see a null pointer). Write the following member functions:

    For entries, totalMiles, reverse, the destructor, and the overridden operators, you can reasonably write the function either with a loop or recursively. You should know how to do both, so make sure at least two are written with a loop, and at least two are written using recursion instead.


Last modified: 
Stephen Bloch / bloch@adelphi.edu