600.120 Intermediate Programming
Spring 2010 -- Assignment 7
Due 4/22 by 2:45pm
65 points total

This problem is an exercise in operator overloading, and further development of template classes. Begin your work early!

Specifications:

The Problem:

A context index is defined as an ordered index of significant items from a collection, each displayed within a subset called their context. Each context must extend far enough to contain a certain number of significant items on either side of the indexed item, if possible. Typically, the entries in the index are aligned so that the significant items each entry is built around are in the same column, and somehow highlighted (with <> in the examples below).

For example, given the following collection of integers, let's decide that "significant" means >=100. If we require two significant items in the left and right contexts of each index entry, the resulting index is as follows.

Integer collection:  23 405 203 39 4059 20 39 581 3049 293 4 581 222 3940

Context index:
           23 405 <203> 39 4059 20 39 581
        293 4 581 <222> 3940
         581 3049 <293> 4 581 222
               23 <405> 203 39 4059
203 39 4059 20 39 <581> 3049 293
       3049 293 4 <581> 222 3940
   4059 20 39 581 <3049> 293 4 581
          581 222 <3940>
       405 203 39 <4059> 20 39 581 3049

Note that 405, 203, 222, and 3940 appear as entries even though they do not have 2 significant entries in a context to the left and right. Notice that 581 appears twice, each with a different context, ordered with the first context before the second.

As another example, suppose we define a word to be "significant" if it has at least 4 characters. We can define our own string class called Word that would redefine the comparison operators to mean that a string is >= "aaaa" if it has at least 4 characters and follows "aaaa" alphabetically, regardless of letter case (upper or lower). In this Word class, a shorter string is always less than a longer string, regardless of alphabetical ordering. For example, "zZ" < "Aaa". We can create a context index for text using this type of comparison, similar to the context index for integers above. Here is an example, for 3 significant items on either side of the entry, using * to highlight the central entry item:

Text to process: the quick RED fox jumped OVer the lazY brown dog

Resulting context index:

quick red fox jumped over the *lazy* brown dog
     the quick red fox jumped *over* the lazy brown dog
         jumped over the lazy *brown* dog
                          the *quick* red fox jumped over the lazy
            the quick red fox *jumped* over the lazy brown

The purpose of this assignment is twofold. The primary purpose is to design and implement a context index template class for creating context index objects that could be used with various data types, assuming that necessary operators have been overloaded. Each object should have only the necessary data in it, carefully encapsulated and protected [6 pts]. Your context index class must support this public interface:

The second purpose of this assignment is to create a new data type which can be used as a base type for creating a context index of playing cards. This Card class must define comparisons based first on face values, breaking ties with suits. The suit ordering from least to greatest is Diamonds, Clubs, Hearts, Spades (note this is not alphabetical). The face values are compared based on their numerical equivalents. If a collection of cards were sorted based on this comparison, then all the 2s would appear first, in the suit order given above, and so on, with the Aces appearing last (face value 14).

Minimally, you must overload this set of operators for the Card class so that it can be used as the base type for a context index: {<<, >>, =, ==, <, <=}. You may build upon the Card(S) structs that are posted in the code directory, or create your own class from scratch. It is up to you to decide how to represent cards for input and output purposes (see creating an input test file below). It can range from very terse (for example, 7D) to very verbose (7 of Diamonds).

Create a plain text file with a sequence of cards that can be used to test your context index class above. Make the file to correspond to how you overload the input operator for your Card class.

Test your classes with the following simple driver program: p7.cpp. You may add to this for more robust testing.