Question: C++ Programming Assignments: most of the code needed is posted below I just need help with certain hashing functions! thanks!! 1.0 Overview In this programming

C++ Programming Assignments: most of the code needed is posted below I just need help with certain hashing functions! thanks!!

1.0 Overview

In this programming assignment you will have the opportunity to study the effects of different hash functions on the efficiency of inserting data into a hash table.
2.0 Requirements
The student shall define, develop, document, prototype, test, and modify as required the software system.
2.1 Functional Requirements
2.1.1 The software shall include three functions each of which implements a different hash function. Hash functions may be those studied in class or adaptations of those functions.
2.1.2 The software shall include three functions each of which implements a different double hash function. One and only one of these double hash functions must be for linear probing, i.e. returns an increment value of 1.
2.1.3 Each hash function shall be tested using each of the double hash functions as a means of collision resolution. This means a total of nine tests. A list of 50 4-letter keys, each with some associated data will be provided for the testing.
2.1.4 In addition to the regular documentation a written report on the results will also be prepared. This consist of printouts of diagrams of the results of the hash tests and a count of the number of collisions in each test. Sample code can be found in the "Hints" section for producing a diagram.
3.0 Deliverables

These products shall be delivered to the instructor electronically via e-mail as specified below. 3.1 Sprint Report -- The student shall provide filled out Sprint Report form for instructor approval NLT (Not Later Than) Monday, July 31. 3.2 Program source files -- The student shall provide fully tested electronic copies of the .cpp and .h files. These files must be submitted to the instructor via e-mail. The files shall be delivered NLT Monday, July 31. 3.3 Hash Results Report -- The student shall provide an electronic report on the results of the hash tests. (See instructions below.) This can be in plain .txt or .doc format.

Our professor gives us most of the code and says we need to fill in certain functions: any help is much appreciated!

Here are code snippets our professor gives us:

Program Outline

The following is a brief pseudocode outline of how the program should be organized.
 for each of three hash functions for each of three double hash (probe increment) functions Initialize the table to empty Open the data file containing keys and associated data. for each key/data set read from the data file Call HashInsert(key, data, hashNum, dHashNum). The return value from this function should be a count of the number of collisions encountered for this key. This should be added to a running total. HashInsert should call one of the Hash functions and set the probe increment to the return value from one of the functions. This will result in the following 9 tests: 1. Hash_01 using probe increment from DoubleHash_01 2. Hash_01 using probe increment from DoubleHash_02 3. Hash_01 using probe increment from DoubleHash_03 4. Hash_02 using probe increment from DoubleHash_01 5. Hash_02 using probe increment from DoubleHash_02 6. Hash_02 using probe increment from DoubleHash_03 7. Hash_03 using probe increment from DoubleHash_01 8. Hash_03 using probe increment from DoubleHash_02 9. Hash_03 using probe increment from DoubleHash_03 Insert key and data into table Close data file Print the results of the run (total number of collisions and diagram of the table). end loop for each double hash end loop for each hash 
Note: Much of the program design is being given to you for this programming assignment. The reason for this is that the primary purpose of this assignment is to explore different hash functions and collision resolution techniques. It is not just a programming activity.

Sample code

Use the following code snippets in main() to read data from the text file, insert it into the table, count the number of collisions, and print the results. You may place all of the hash functions and double hash functions in a C++ class but that is not required. Code Snippets are just that, pieces of code. You cannot just copy all of the code below, paste it into your program and expect it to work.

#include  #include  #include  #include  #include  #include  #define TABLESIZE 100 #define KEYSIZE 4 #define EMPTYKEY "----" #define DATAFILE "P4DATA.TXT" // Define the structure for use in the hash table struct HashStruct { char key[5]; int data; }; //============================================================================== /* --- Snippet 1: Partial list of variables defined in main() --- */ int i, hashNum, dHashNum, count; ifstream *inFile; HashStruct T[100]; // Hash table srray of 100 data structures char line[64];// Array to hold lines read from file char key[5]; // Array to hold 4-character keys int data; // Integer data //============================================================================== /* --- Snippet 2: The following code can be used to perform the 9 tests. Use hashNum to increment a loop for each of 3 hash functions and dHashNum to increment a nested loop for each of 3 double hash functions. --- */ // For each of three hash functions for(hashNum = 0; hashNum open(filename, ifstream::in); // Open data file for this test if(!inFile->is_open()) { cout getline(line, 64, ' '); sscanf(line, "%s %d", key, &data); count += HashInsert(T, key, data, hashNum, dHashNum); // Note: The HashInsert() function uses the indices of hashNum and // dHashNum to know which hash function and double hash function to call // in this test. } infile->close(); /* Close the text file */ delete infile; } } //============================================================================== /* --- Snippet 3: This code shows how to create a diagram of the results of a single test using one hash function and one double hash function. The resulting diagram looks similar to the sample below with '|' representing a slot where a key hashed or double hashed to and '-' representing an empty slot: ||-||||---|||-|-||||||||-----||-|-||---||||--|-|||...etc. --- */ cout  You must add the code to insert key and data  //  into the table at index hashIndex at this point and then //  return the collision count 

This is the sample data file:

Select all of the text below and paste it into a text file. Save the file as an MS DOS text file under the name of P4DATA.TXT

AARD 1 ABAN 2 ABAS 3 ABAT 4 ABAX 5 ABEC 6 ABER 7 ABIL 8 ABOD 9 ABON 10 EARD 11 EBAN 12 EBAS 13 EBAT 14 EBAX 15 EBEC 16 EBER 17 EBIL 18 EBOD 19 EBON 20 IARD 21 IBAN 22 IBAS 23 IBAT 24 IBAX 25 IBEC 26 IBER 27 IBIL 28 IBOD 29 IBON 30 OARD 31 OBAN 32 OBAS 33 OBAT 34 OBAX 35 OBEC 36 OBER 37 OBIL 38 OBOD 39 OBON 40 UARD 41 UBAN 42 UBAS 43 UBAT 44 UBAX 45 UBEC 46 UBER 47 UBIL 48 UBOD 49 UBON 50 

For each of three hash functions For each of three double hash functions Initialize table to empty Open data file Call Hashinsert)HashInsertO Return collision count? Call hash function to calculate table index. Set probe inc double hash function. Print results Insert into table and count collisions

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!