CSC 326 Assignment 2
Due in class 6 October 1999
This assignment is an extension of exercise 4.10, page 146. You are to design and implement an efficient facility for indexing arrays by character strings instead of integers. These are sometimes called associative arrays. The implementation should be in C++.
1. The array size is not known in advance.
2. The array index strings are not known in advance.
3. Different arrays may hold data of different types (e.g. provide a template class)
4. Your design and implementation should be efficient.
The strategy is to define a template class called "assoc" which overloads the "[]" operator. To do this, you need to declare and define a member function "operator[]" with one parameter of type string. Use the Standard Template Library to get this datatype (string is actually an instantiation of template class basic_string). This member function must return a reference to the datatype of the data stored in the array.
Here is a non-template example: int& operator[](string); // data holds integers
By structuring your solution in this way, you can perform any operation on array members which is allowed by the array data type. The meat of this assignment is developing an efficient method for storing values to and retrieving them from the array.
To turn in:
1. A design document, preferably in Word, describing your solution.
2. C++ source code which implements it. Class definition in file assoc.h, member function definitions in file assoc.cpp.
Submit both the Word document and your source code to your eccentric upload folder for csc326 (I'll have these in place by the due date).
[Assignments | CSC 326 | Peter Sanderson | Computer Science | SMSU ]
Last reviewed: 20 September 1999
Peter Sanderson ( PeteSanderson@mail.smsu.edu )