I really need assistance with creating a C++ hash table program for generating a hash from a string.
Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function).
Requirements:
Please use only #include<iostream>, #include<string>, and #include<fstream>.
Below is the program which solves your question completely. Since you haven't provided any words.txt I have taken a file which contains of 30 words and solved using that but this works for any size. To change the size, just to the program and on the top you will see a line like "#define SIZE 30". There remove 30 and keep the size whatever you want.
INPUT:

CODE:
############################
#include<iostream>
#include<fstream>
using namespace std;
#define SIZE 30
long hashArray[SIZE];
long getHash(string s)
{
long h=0, temp;
for(int i=0;i<s.size();i++)
{
temp = s[i];
h = (h*10+temp)%SIZE;
}
return h;
}
int main()
{
ifstream in_file("words.txt");
string s;
long collisions=0, h;
while(in_file>>s)
{
h = getHash(s);
hashArray[h]++;
if(hashArray[h]>1) collisions++;
}
cout<<"Total size of hash array: "<<SIZE;
cout<<"\n\nNumber of collisions: "<<collisions;
cout<<"\n\nPercentage of collisions:
"<<(double)(collisions*100)/SIZE<<"\n\n";
//exporting to csv file
ofstream out_file("hashresults.csv");
for(long i=0;i<SIZE;i++)
{
out_file<<i<<','<<hashArray[i]<<'\n';
}
}
##############################
OUTPUT:

I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash funct...
I really need assistance with creating a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...
Please complete the following task: Create a C++ hash table program for generating a hash from a string. Create a hash function then test and evaluate the results. The set of strings are from a "words.txt" file (there are 45,402 words in the file, no repeating words. Map the words to 45,402 buckets using a hash function). Requirements: Create an array of 45,402 integers and initialize each to zero. These will be used to store how many times each index...
IN JAVA USING ECLIPSE The objective of this assignment is to create your own hash table class to hold employees and their ID numbers. You'll create an employee class to hold each person's key (id number) and value (name). Flow of the main program: Create an instance of your hash table class in your main method. Read in the Employees.txt file and store the names and ID numbers into Employee objects and store those in your hash table using the...
Java using data structures The objective is to create your own Hash Table class to hold a list of employees and their ID numbers. I've provided the TableEntry class which will be each data object in the hash table. The list of employees will be provided as a .txt file and must be read with the code. please create a .txt file called Employees.txt with the info provided so that the java code can read it in. Employees.txt: (No WhiteSpace...
This should be in Java Create a simple hash table You should use an array for the hash table, start with a size of 5 and when you get to 80% capacity double the size of your array each time. You should create a class to hold the data, which will be a key, value pair You should use an integer for you key, and a String for your value. For this lab assignment, we will keep it simple Use...
Write a spell checker that stores a set of words, W, in a hash table and implements a function, spellCheck(s), which performs a spell check on the string s with respect to the set of words, W. If s is in W, then the call to spellCheck(s) returns an iterable collection that contains only s, because it is assumed to be spelled correctly in this case. Otherwise, if s is not in W, then the call to spellCheck(s) returns a...
0. Introduction. This involves designing a perfect hash function for a small set of strings. It demonstrates that if the set of possible keys is small, then a perfect hash function need not be hard to design, or hard to understand. 1. Theory. A hash table is an array that associates keys with values. A hash function takes a key as its argument, and returns an index in the array. The object that appears at the index is the key’s...
Question 39 Language C++
Question 39 15 pts Implement a program that finds the shortest string in a dynamically allocated array of strings. The program first asks the user for the number of names needed. Afterwards, the user is prompted to enter each name. The program then passes the array to a function. The function returns the index of the shortest element. The program then prints out the shortest element and the index where it is stored in the array....
PROGRAM DESCRIPTION Implement a hash table class. Your hash table should resolve collisions by chaining and use the multiplication method to generate hash keys. You may use your own linked list code from a previous assignment or you can use a standard sequence container. Partial definitions for the hash table class and a generic data class are provided (C++ and Java versions). You may use them as a starting point if you wish. If you choose to design your own...
LINUX C programming Please make sure the output is correct Please do read data from file, the example below is just a example Third: Hash table (20 points) In this part, you will implement a hash table containing integers. The hash table has 10,000 buckets. An important part of a hash table is collision resolution. In this assignment, we want you to use chaining with a linked list to handle a collision. This means that if there is a collision...