Answered step by step
Verified Expert Solution
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 belowI already did all of the other questions just fine, its just this last question Im struggling withIf 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 :
By using the hashT class provided hashTh 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 HASHTH
#define HASHTH
Author: DS 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 insertint hashIndex, const elemType& rec;
void searchint& hashIndex, const elemType& rec, bool& found const;
bool isItemAtEqualint hashIndex, const elemType& rec const;
void retrieveint hashIndex, elemType& rec const;
void removeint hashIndex, const elemType& rec;
void print const;
hashTint size ;
~hashT;
private:
elemType HTable;
int indexStatusList;
int length; fff
int HTSize;
;
template
void hashT::insertint hashIndex, const elemType& rec
int pCount;
int inc;
pCount ;
inc ;
while indexStatusListhashIndex
&& HTablehashIndex rec && pCount HTSize
pCount;
hashIndex hashIndex inc HTSize;
inc inc ;
if indexStatusListhashIndex
HTablehashIndex rec;
indexStatusListhashIndex;
length;
else if HTablehashIndex 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::searchint& hashIndex, const elemType& rec,
bool& found const
int inc ;
while indexStatusListhashIndex
indexStatusListhashIndex
&& HTablehashIndex rec
hashIndex hashIndex inc HTSize;
inc inc ;
found HTablehashIndex rec;
end search
template
bool hashT::isItemAtEqualint hashIndex,
const elemType& rec const
return HTablehashIndex rec;
template
void hashT::retrieveint hashIndex, elemType& rec const
if indexStatusListhashIndex
rec HTablehashIndex;
else
std::cerr "Error: no item stored at position
hashIndex
;
template
void hashT::removeint hashIndex, const elemType& rec
if indexStatusListhashIndex && HTablehashIndex rec
indexStatusListhashIndex;
else
bool found false;
searchhashIndex rec, found;
if found
indexStatusListhashIndex;
else
std::cerr "Error: rec not found in hash table.
;
template
void hashT::print const
for int i ; i HTSize; i
if indexStatusListi
std::cout i : HTablei
;
template
hashT::hashTint size : HTSizesize
HTable new elemTypeHTSize;
indexStatusList new intHTSize;
length ;
template
hashT::~hashT
delete HTable;
delete indexStatusList;
#endif HASHTH
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started