Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this question. I've been spending hours figuring out how to make a cpp file that works with the provided hashT.h file

I need help with this question. I've been spending hours figuring out how to make a cpp file that works with the provided hashT.h file and answers the question for this assignment below(I already did all of the other questions just fine, its just this last question I'm struggling with).If the hashT file actually needs a fix, fixing that file too is also appreciated!
The sample output that should be a result from a working cpp and hashT file should be in the image.
Question 4:
By using the hashT class provided (hashT.h ), which uses quadratic probing to resolve collision, create a hash table to keep track of student IDs and names.
Write a C++ code to;
(a) Ask the user to enter IDs and names of five students to be added to the hash table.
(b) Calculate the hash index from the student ID using the folding method.
(c) Add the information to the hash table.
(d) Ask the user to enter the student information to be deleted from the hash table.
(e) Remove the information from the hash table.
(f) Print the information.
Submit the cpp file, and copy and paste the screenshot of the output here.
Here's the content of the in hashT.h file:
#ifndef HASH_T_H
#define HASH_T_H
//****************************************************************
// Author: D.S. Malik
//
// This class specifies the members to implement a hash table as
// an ADT. It uses quadratic probing to resolve collisions.
//****************************************************************
#include
template
class hashT
{
public:
void insert(int hashIndex, const elemType& rec);
void search(int& hashIndex, const elemType& rec, bool& found) const;
bool isItemAtEqual(int hashIndex, const elemType& rec) const;
void retrieve(int hashIndex, elemType& rec) const;
void remove(int hashIndex, const elemType& rec);
void print() const;
hashT(int size =101);
1.
~hashT();
private:
elemType* HTable;
int* indexStatusList;
int length; fff
int HTSize;
};
template
void hashT::insert(int hashIndex, const elemType& rec)
{
int pCount;
int inc;
pCount =0;
inc =1;
while (indexStatusList[hashIndex]==1
&& HTable[hashIndex]!= rec && pCount HTSize /2)
{
pCount++;
hashIndex =(hashIndex + inc)% HTSize;
inc = inc +2;
}
if (indexStatusList[hashIndex]!=1)
{
HTable[hashIndex]= rec;
indexStatusList[hashIndex]=1;
length++;
}
else if (HTable[hashIndex]== rec)
std::cerr "Error: No duplicates are allowed.
";
else
std::cerr "Error: The table is full. "
"Unable to resolve the collision.
";
}//end insert
template
void hashT::search(int& hashIndex, const elemType& rec,
bool& found) const
{
int inc =1;
while ((indexStatusList[hashIndex]==1||
indexStatusList[hashIndex]==-1)
&& HTable[hashIndex]!= rec)
{
hashIndex =(hashIndex + inc)% HTSize;
inc = inc +2;
}
found = HTable[hashIndex]== rec;
}//end search
template
bool hashT::isItemAtEqual(int hashIndex,
const elemType& rec) const
{
return HTable[hashIndex]== rec;
}
template
void hashT::retrieve(int hashIndex, elemType& rec) const
{
if (indexStatusList[hashIndex]==1)
rec = HTable[hashIndex];
else
std::cerr "Error: no item stored at position "
hashIndex ".
";
}
template
void hashT::remove(int hashIndex, const elemType& rec)
{
if (indexStatusList[hashIndex]==1 && HTable[hashIndex]== rec)
indexStatusList[hashIndex]=-1;
else {
bool found = false;
search(hashIndex, rec, found);
if (found)
indexStatusList[hashIndex]=-1;
else
std::cerr "Error: " rec " not found in hash table.
";
}
}
template
void hashT::print() const
{
for (int i =0; i HTSize; ++i)
if (indexStatusList[i]==1)
std::cout i ": " HTable[i]'
';
}
template
hashT::hashT(int size) : HTSize(size)
{
HTable = new elemType[HTSize];
indexStatusList = new int[HTSize];
length =0;
}
template
hashT::~hashT()
{
delete[] HTable;
delete[] indexStatusList;
}
#endif //HASH_T_H
image text in transcribed

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_2

Step: 3

blur-text-image_3

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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions