CSE 109 Programming Assignment #2 Due: 9 PM Thursday 28 February 2008 [Late collections 9 PM Saturday 8 March, Sunday 9 March] This assignment is an exercise in writing a class, in using pointers, and in implementing a hash table that uses linked lists to handle collisions. Your class should implement the hash table by declaring the following instance variable as part of the class: Link **table; where the class Link is similar (or identical) to the one I developed in class. In /proj/csc109/p2 you will find the file p2.cc which is a program that tests out the implementation of the class HashTable and (its associated class, class Link). Below the program is a comment that lists the output that I obtained when I did this assignment. Your implementation of HashTable should produce similar output. The program in p2.cc requires the implementation of the following methods (member functions) in the in class HashTable. (Note that I indicate methods with (), but this is not meant to suggest how the function should be parameterized.) 1. The default constructor and constructor taking an int argument for the size of the table. The size (default or otherwise) must be prime, else the contructor causes the program to crash. 2. The copy constructor. 3. The destructor, ~HashTable() 4. The [] operator gives access to the data in the table with the given key, provided the entry is in the table. If the key is not in the table, the key is first added to the table. Then access is given to the data in the table with the given key. 5. The []const operator gives access to the data with the given key in the table, provided the entry is in the table, otherwise it crashes the program. 6. inTable() returns true if and only if the given key is in the table. 7. += adds an entry in the table, provided no entry in the table already has the same key. If there is an entry with the same key, it crashes the program (duplicate key). 8. << displays the contents of the table (in haphazard order). Start this assignment by creating the subdirectory p2 in your subdirectory cse109.081 and copying the file /proj/csc109/p2/p2.cc into the file cse109.081/p2/p2.cc. Create a Makefile for creating p2. DO NOT CHANGE THE CODE OF p2.cc AT ALL. I REPEAT, DO NOT CHANGE THE PROGRAM CODE IN ANY WAY OTHER THAN TO ADD THE USUAL (IMPORTANT) DOCUMENTATION (name, assignment, program and class purposes, etc.,) ELSE LOSE AT LEAST 20 PTS. I will test your classes HashTable and Link by using the command "make clean" to discard all .o files (where you should implement "clean" in your Makefile), by replacing your p2.cc with the the file /proj/csc109/p2/p2.cc, by using your Makefile to compile p2.cc (and compile the code for your classes), and then by running the resulting executable file p2. IT IS IMPORTANT THAT YOU COMPILE ALL YOUR .cc FILES WITH THE -Werror -Wall OPTIONS (E.G.,g++ -c -Werror -Wall p2.cc). When you are ready to submit your work, create the file "DONE" by executing the command "touch DONE". Notes: 1. All your files should have good documentation. Each file should have identifying information at the top, e.g., your name, the course, the assignment number. Each class declaration should be documented with comments at the top which explain the class and its purpose. The role of each data member should be explained. Each member function should be explained (e.g., by stating pre- and post-conditions and by stating the overall algorithm). Hard to understand sections of code should be explained. 2. In /proj/csc109/p2 I have provided the files hash.h and hash.cc. The file hash.h has the declaration of a "wrapper class" for ints that computes a hash code for a given int, and hash.cc provides the definitions. Given an int k, Hash(k).hash() (creates an instance of Hash and calls the method hash() which) returns a hash code corresponding to the value of k. Your class HashTable should use class Hash in computing the hash codes for the keys to be entered into the hash table. 3. You should have separate .h files and .cc files for p2.cc and for the classes Link, Hash (see note 2 above), and HashTable. IN THE SYLLABUS READ THE STATEMENT ABOUT UNFAIR COLLABORATION AND AVOID UNFAIR COLLABORATION