UMBC CMSC 202, Computer Science II, Fall 1999

Project 4: Inheritance and Polymorphism

Due: December 9, 1999

See Also Project Notes, Questions and Answers


Objectives

The objectives of this project are to:


Background

In this project you will write a C++ class to implement a set of key/value pairs, often referred to as a map or associative array. In particular, you will "map" integers (the keys) to strings (the values). Since you've already built a class that maintains a set of integers, we will derive the new class (Map) from the existing class Set. We will demonstrate dynamic binding (polymorphism) by including virtual functions and by processing an array of base class pointers.


Tasks

  1. Begin with Set.H and Set.C from Project 3. In Set.H:

  2. In Set.C:

  3. Test these changes.

  4. Write the derived class Map. Begin with this Map.H. Add a header comment and a comment for each member function. You may add additional data or function members in the private section, but do not change the public section. Implement the member functions in a file called Map.C. Test the new class. Here is a sample test program and output.

  5. In Set.H, revise the declarations for Display() and the destructor so that these functions are virtual. Test these changes with a test program that creates and displays some sets and maps, using an array of Set pointers. You may want to insert some temporary print statements into the destructors in Set.C and Map.C to prove that they are getting called. Here is a sample test program and output.

  6. After you are confident that your classes are working properly, test them with a more robust test program. Here is a sample test program.

  7. For this project, you should submit a makefile and four source files named as follows:

    Your makefile should be set up to make an executable named Proj4 using source file Proj4.C. Do not submit your own Proj4.C. Your project will be tested using an undisclosed test program similar (but not identical) to the sample shown in the previous step.


Extra Credit

Extra credit points will be added to the total points for the four projects.


Last Modified: 23 Nov 1999 17:04:14 EST by Alan Baumgarten, abaumg1@cs.umbc.edu

Back up to Fall 1999 CMSC 202 Section Homepage