Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi guys, I want to get a c++ code for this. can someone solve the code? Topics Hash Table Hashing Algorithm Hash Index Description Write

Hi guys, I want to get a c++ code for this. can someone solve the code?

Topics

Hash Table

Hashing Algorithm

Hash Index

Description

Write a program that provides for searching students by their ids using hash table. The program will first input students one by one from a file (insert.txt) and insert them into hash table. Then it will input students one by one from a text file (search.txt) and perform searches for them in the hash table. It will keep a record of searches when required and display the summary results.

Implementation

Class StudentHT

Create a class StudentHT that provides for the following struct definitions, instance variables and methods.

struct RecType contains student id, first name, and last name.

struct NodeType contains student id, first name, last name, and a pointer to NodeType

hashPtr an instance variable pointing to hash table array of pointers

a constructor to input hash table size

void insert (RecType item)

will insert an item in the hash table.

item search (RecType item)

Will search an item in hash table and will return it. If not found will return an item containing -1 for id.

void startStatistics ();

void endStatistics ();

void displayStatistics();

Main Method

Provide main method that will create the hash table object and call its methods.

Hashing Algorithm

Calculate the hash index from student id as below:

hash index = (student id) % (total entries in hash table)

Statistics

Provide the following statistics

Total number if ids searched

Total number of nodes searched

Average number of nodes search per id searched

Testing

Use the data in file Add.txt for inserting in the table

Use the data in file Search.txt for doing searches in the hash table.

#include "StudentHT.h" StudentHT::StudentHT(int tblSize) { hashTblPtr = new NodePtr [tblSize]; hashTblSize = tblSize; } StudentHT::~StudentHT(void) { } void StudentHT::insert (RecType item){ } RecType StudentHT::search (RecType item){ } void StudentHT::startStatistics (){ } void StudentHT::endStatistics (){ } void StudentHT::displayStatistics(){ } void main(){ //create hash table object //input student ids from insert.txt //make up their first and last name //first name for id 1 is first1 //last name for id 1 is last1 //insert them one by one in hash table //call startStatistics //input student ids from search.txt //search them in the hash table //call endStatistics //display statistics }

here's the sample code

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

Have ground rules been established for the team?

Answered: 1 week ago

Question

What is the difference between Needs and GAP Analyses?

Answered: 1 week ago

Question

What are ERP suites? Are HCMSs part of ERPs?

Answered: 1 week ago