Programming Assignment #3

 

CS163: Data Structures

 

 

 

 

Problem Statement:

Hash tables are very useful in situations where an individual wants to quickly find their data by the “value” or “search key”.  You could think of them as similar to an array, except the client program uses a “key” instead of an “index” to get to the data. The key is then mapped through the hash function which turns it into an index!

 

You have decided to write a table abstract data type, using a hash table/function with chaining (for collision resolution), to support your local fast food joint (such as Taco Bell). The clerk can enter in the order (taco supreme) and the hash function will map it to an index and quickly the clerk will find out what the price is! So your search key is the product being ordered (from the menu) and the result will be the price and calorie content of that item.

 

Abstract Data Type:

Write a C++ program that implements and uses a table abstract data type to store, search, and remove menu items.

 

What does retrieve need to do? It needs to supply back to the calling routine information about the item that matches. Retrieve, since it is an ADT operation, should not correspond with the user (i.e., it should not prompt, echo, input, or output data).

 

Evaluate the performance of storing and retrieving items from this table. Monitor the number of collisions that occur for a given set of data that you select. Make sure your hash table is small enough that collisions actually do occur, even without vast quantities of data so that you can get an understanding of how chaining works. Try different table sizes, and evaluate the performance (i.e., the length of the chains!).

 

Implement the abstract data type using a separate header file (.h) and implementation file (.cpp). Only include header files when absolutely necessary. Never include .cpp files!

 

 

Syntax Requirements:

1) Use iostream.h for all I/O; do not use stdio.h

2) Implement the table ADT as a class; provide a constructor and a destructor.

3) Make sure to protect the data members so that the main() program does not have direct access.

4) Your main() should allow the user to interactively insert, delete, or retrieve items from the table. ***THE MAIN PROGRAM SHOULD NOT BE AWARE THAT HASHING IS BEING DONE! ***

 

 

What to Turn in:

• INSTEAD of using shar for this program – please zip, tar or attach the files!!!!

 

REMINDERS: Every program must have a comment at the beginning with your first and last name, the class (CS163) and section, the name of the file, and the assignment number. This is essential!