C++: Ghp#7

Submitted by: Submitted by

Views: 11

Words: 252

Pages: 2

Category: Science and Technology

Date Submitted: 09/29/2015 06:52 PM

Report This Essay

Write a C++ program that:

(1) defines and implements a hash class that constructs a 23 element array (may be implemented using a vector, a deque, or a list, if you prefer), storing strings, using the following hash function: (ascii(first_letter) + ascii (last_letter))%23

So, for example, the word "rocky" would be

ascii('r') = 114 + ascii ('y') = 121 = 235%23 = 5

Note: there is no "ascii" function, rather the value of 'r' is simply 114.

In this example, an attempt would be made to store "rocky" in position 5. In the event of a collision, the word would be stored in the first available location, so if there is a collision in location 5, an attempt would be made to store the word in location 6. If there is a collision in location 6, try location 7 and so on.

(2) the driver program should:

a. query the user for fifteen words and store them using the hash technique described above.

b. print out the contents of each position of the array (or vector, deque, or whatever you used), showing vacant as well as filled positions. Remember, only 15 of the 23 positions will be filled.

c. repeatedly query the user for a target word, hash the word, check for its inclusion in the list of stored words, and report the result. Continue doing this task until the user signals to stop (establish a sentinel condition).

A solution that does not involve defining and using a hash class is not acceptable.