CIS 4930 Section 0939

Object-Oriented Programming

Programming Project 1

Project Name Asst1

Description written by J.N. Wilson.

Refer to the word count program discussed in class. A modified version of this program has been placed in the directory ~jnw/OOCourse. Minor (but important) changes such as addition of copy constructors and assignment were made to the version given in class. You are to make the rest of the modifications specified below.

Modify the program so that WordCountTable is an abstract base class that has a public print member function (printing the contents of the table).

Modify the WordCountTable class constructors as follows

  1. Make the default (no argument) constructor private. (This means that it cannot be employed within a program.)
  2. Create a constructor requiring a single integer argument (the maximum number of words to be stored in the table). This will require you to change the declaration of the EntryArray member of the WordCountTable class.
Modify operator<< on WordCountTable objects to employ the print member function and not to be a friend of WordCountTable. Add the following two derived classes of WordCountTable: Note that there are two fundamental ways to achieve the right behavior in the SortedWordCountTable class. One may have an insertion method that maintains a sorted array of the words in the table or one may sort the elements when asking for them to be printed. A variety of variations on these themes are possible.

No matter what mechanism is chosen, some of the member functions of the WordCountTable class will need to be virtual. Others may not need to be virtual. Try to avoid derived class duplication of structure or behavior provided by the base class.

Change the main program so that it accepts a single command line argument, a single character, which is either g or s to indicate that the WordCountTable to be employed is either a generic or a sorted table, respectively. Have it assign a WordCountTable pointer variable a new reference to either a GenericWordCountTable or SortedWordCountTable depending on the value of the command line argument.

The rest of the main program should behave as in the provided version. It will, of course, employ a WordCountTable pointer variable rather than a WordCountTable variable.

Make sure not to include extraneous code or bogus debugging output in your program. This is unprofessional. Provide internal documentation sufficient to allow you to pick up the code in 6 months and figure out what you did.


This document is copyright 1995Joseph N. Wilson.
$Id: p1.html,v 1.1 1995/02/02 20:57:51 jnw Exp jnw $