Topical Information

The purpose of this project is to test your ability to use templates, operator overloading, and libraries effectively in class design.

Program Information

In mathematics a mapping is a function that takes items from one set and transforms it into an item from a second set. Most of the time these items are numbers and the sets are R, C, I, etc. But in higher mathematics they can end up being weirder things...

Anyway, computer scientists find that this concept of the map is really useful in modeling real-world situations. What is a program, after all, but a map from inputs to outputs?

What we normally do is create two parallel arrays and have items from each set in aligned positions in each of the two arrays. The main operations are create a new mapping (two new items are entered into the arrays which are to be associated together) and retrieve one value of an associated pair given the other (normally this look-up is only done in one direction; you don't have to provide the ability to search either array and retrieve the other ones value).

Since we apply maps in many different situations, it is useful to have a templated map so that the original and ending items can be of any type we choose (short, double, String, Date, char*, Point*, etc.).

You, of course, are to create such a class. You can use a pair of static arrays for your mapping, but they must be templated so that the programmer can map different types of information.

Since your map is static, you'll also provide a full method (in addition to your insertion and lookup methods).

Finally, maps aren't typically read in, but are often printed out. Normal format is:

   { (item, item), (item, item), ... }

Show how useful your template map class is by creating maps:
short integersdoubles
String class objects (static) Point class objects
characters pointers to Point class objects (each allocated on the heap)

-- all in one test application. (Maybe a templated function would help relieve your test application tedium, too?! See the template set test application for help.)

Thought Provoking Questions

  1. What operators might you overload for the map operations: enter pair, lookup second value of pair, map full?

This assignment is (Level 3).


Add (Level 2) to allow the programmer to remove an associated pair from the map.

Add (Level 2) to make your map dynamically grow as the programmer adds new items. Use a block allocation scheme to reduce memory fragmentation. (If you've done the previous option you must shrink as well -- I'll throw in another (Level 1) for this since you must make sure the reduced size is a block size multiple.)

Add (Level 1) to overload operator~ to reverse the mapping order. (So if it currently maps characters to pointers to Points (Point*), it would now map Point*'s to characters.) This operator should NOT alter the calling object, but create a second object which performs the reverse mapping.

Add (Level 1.5) to provide six mutable members for print formatting. When printing a map, it is typical to print it as:

   { (item, item), (item, item), ... }
But some programs might want it to instead look like:
   { (item --> item), (item --> item), ... }
Or they might want to change the {, the }, the (, the ), or even the comma that separates each mapped pair! You'll need at least mutators for each of these items. Use these members in your output method (operator?).