Complete and test the HashedDictionary class started in the text.
It's fine if you want to put each class all into one file, instead of splitting them into header file and implementation file.
Step 1
First complete the "Entry" class. The text provides the header file. It just consists of constructors, mutators, and accessors. You need to write the implementation. You can delete the == and > operator overloads.
Step 2
Next complete the "HashedEntry" class. The text provides the header file. Once again, you'll need to write the implementation, and once again, it's just constructors, accessors, and mutators.
Step 3
Next write the HashedDictionary class. The HashedDictionary class must be derived from the DictionaryInterface class given in the text, except that you should delete the "traverser()" function. The data members are given to you in the text, as are the add() function and the remove() function. You may want to add a display() member function to your HashedDictionary class for testing purposes.
Regarding repeated search keys, we will leave the behavior undefined. In other words, don't even think about what should happen if repeated search keys are encountered.
For the getHashIndex() function, you are required to use the technique described at the top of page 549 in the text. (To be specific, you'll use Horner's rule, and you'll modulus by the tableSize after each parenthesized expression in Horner's rule.) I would suggest that you just use something very simple for the getHashIndex() function at first. For example, you could simply add the ASCII codes of each character in the searchKey. Then write your client program to make sure everything is working. Then you'll just need to rewrite the getHashIndex() function to use the required technique.
To keep things simple, we will fudge things a little for the getHashIndex() function. Normally this function would be provided by the client. We will instead include this function in the HashedDictionary class, and we will simply assume (for this function only) that the search key is always a string. The word "string" won't occur anywhere in your HashedDictionary code, but you'll treat the search key as if it is a string, using expressions such as searchKey[i]. Here is my function header for the getHashIndex() function:
template int HashedDictionary::getHashIndex(const KeyType& searchKey) const
Step 4
Write a client program to test your class. The program should read a file containing information about famous people (name, age, zip code, etc.) and store the data in a HashedDictionary object. It should then test all of the member functions of the HashedDictionary class. This could get long, but don't worry about decomposing. You can just have a really long main() function.
I've provided the start of the client program, as well as the data file (famous.txt). You'll need to add code to main() to test the remaining member functions.
Each FamousPerson will have the following data fields:
- a (non-unique) ID number, stored as a string
- an income tax status, stored as a single char (m for married, s for single, h for head of household)
- last name (the search key), stored as a string
- first name, stored as a string
- age, stored as an int
- street, stored as a string
- zip code, stored as a string
Assume that all strings are single words (no spaces)
Here are the files you'll need:
I'm not requiring you to implement the big-3 in this assignment.
Note that the words "throw (something)" in the prototype and function header are no longer allowed in C++. You should delete them wherever you see them. (In the files I've provided above, I have deleted them for you.)