Question: I need help completing the following code for a project im working on please can someone help this is due on tuesday morning and I

I need help completing the following code for a project im working on please can someone help this is due on tuesday morning and I cant figure it out. I have included the instructions and have also included what of the program i have done.

Hashing is a technique used to store and/or access elements in a list(array)witha relatively constant amountof time O(1). A hash function is a function whichmaps a large range of key values into a smallerrange of physical addresses.Your assignment in this project is to build hash tables to store the following data object, in which account_numberis an integer, nameis a string, and balanceis a double.

Program 1.

1. Hash Table: Your hash table must be dynamically allocated. The constructor for your hash table should be able to accept an integer (n?2) as a parameter and creates a hash table such that the size of the table is equal to the next prime number (N) which is greater than (n).

2. Hash Function: A hash function is used to produce a semi-unique address for a given key to be stored in the hash table. In this project, account_number and name are used together as a composite key.

? Hash code map (keyinteger): account_number + summation of the ASCII values of each character in string name. To cast a char C to an int j, you can use: int j = (int) C;

? Compression map (integer[0, N-1]): i = integer % N ( i is the index of the hash table the account will be hashed into)

3. Collision Resolution: Despite our best effort in selecting a good hash function, often multiple keys could hash into the same hash table location. In such cases, we must be able to deal with the collision. For the purpose of this assignment, you are required to use chaining collision resolution method with unsorted linked list.

4. Your program should contain at least two classes: account class, which is the node in the linked list, and hashtable class, which is an array of pointers to account.

5. The constructor of your hashtable class should take one parameter n and create a table of size N, as described before. The signature of the constructor is:

hashtable(int n);

6. The structure of your hash table should look like this

I need help completing the following code for a project im working

7. Your hashtable class should also support the following operations

? Insert an account: map an account to the table (array) index and then insert the account to the head of the unsorted linkedlist. The signature of this method is:

void insert(int account_number, string name, double balance);

? Remove an account: map an account to the table (array) index and then perform sequence search by account_number and delete the found account. You should de-allocate space for the removed account. The signature of this method is:

void remove(int account_number, string name);

? Search an account: map an account to the table (array) index and then perform sequence search by account_number. It should return a pointer to the found account. If the account could not be found, return NULL. The signature of this method is:

account * search(int account_number, string name);

8. Test your program to make sure it is implemented correctly.

Here is the Program

#include

#include

using namespace std;

int getPrime(int);

int hash_code_map(int act, string name);

class node

{

public:

int account_number;

string name;

double balance;

node * next;

public:

node(int v, string n, double b);

};

node::node(int v, string n, double b)

{

this->account_number = v;

this->name = n;

this->balance = b;

this->next = NULL;

}

class hashtable

{

public:

node ** array;

int size;

public:

hashtable(int n);

void insert(int act, string n, double b);

void remove(int act, string name);

node * search(int act, string name);

};

hashtable::hashtable(int n)

{

// your code goes here

// (1) determine the array size;

// (2) allocate space for array

// (3) set each cell in the array point to NULL

}

void hashtable::insert(int act, string n, double b)

{

// your code goes here

// create a node and insert it to the hashtable

}

void hashtable::remove(int act, string n)

{

// your code goes here

// find the node and delete it.

// do nothing if it can not be found

}

node * hashtable::search(int act, string name)

{

// your code goes here

// find the node and return it (the pointer).

// retun NULL if it can not be found

}

int getPrime(int n)

{

// your code goes here

// return the smallest prime number that is greater than n

// suppose n>=2

}

int hash_code_map(int act, string name)

{

// your code goes here

// map(convert) account number (act) and name into an integer

// act + summation of the ASCII values of each character in the

string

}

int main()

{

hashtable ht(100);

ht.insert(2002, "Janet Smith", 100.99);

ht.insert(1001, "Alex Bush", 99.88);

ht.insert(3003, "John Rosa", 5.55);

node * n;

n = ht.search(1001, "Alex Bush");

if (n!=NULL) cout balance

else cout

ht.remove(1001, "Alex Bush");

n = ht.search(1001, "Alex Bush");

if (n!=NULL) cout balance

else cout

return 1;

}

/*

// if your hashtable is corrected implemented,

// you should see the following result:

the balalnc of account 1001 is 99.88

could not find account 1001

*/

The structure of your hash table should look like this. 0 NULL NULL 2 NULL 3 N-1 NUL

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!