Question: C++ Implement the ADT Dictionary using a hash table with separate chaining (an array of pointers). It will use the name as a search key
C++ Implement the ADT Dictionary using a hash table with separate chaining (an array of pointers). It will use the name as a search key and the age as the item in the class Entry. Have the hash table be small (and size as a prime number). Have it use a menu like so:
1 print hash table
2 retrieve hash item
3 delete item
4 read names from file
5 save names to file
6 - add item
0 quit
If you have the following names and ages of:
30 Greg Greed
18 Sally Smith
44 James Jones
59 Samantha Abernathy
27 George Ivy
The print hash table will print the slot numbers, names and ages, get an average age, and calculate alpha. It would look like (if it has a size of 11):
Slot #0, Samantha Abernathy 59
Slot #5, James Jones 44, Greg Greed 30
Slot #6, George Ivy 27
Slot #9, Sally Smith 18
Average age is 35.6
Alpha = 0.45
//ADT dictionary.@file Entry.h
#ifndef _ENTRY
#define _ENTRY
template
class Entry
{
private:
ItemType item;
KeyType searchKey;
protected:
void setKey(const KeyType& searchKey);
public:
Entry();
Entry(ItemType newEntry, KeyType searchKey);
ItemType getItem() const;
KeyType getKey() const;
void setItem(const ItemType& newEntry);
bool operator==(const Entry
bool operator>(const Entry
}; // end Entry
#include "Entry.cpp"
#endif
//ADT dictionary.@file Entry.cpp
#ifndef ENTRY_CPP
#define ENTRY_CPP
template
bool Entry
rightHandItem) const
{
return (searchKey == rightHandItem.getKey());
} // end operator==
template
bool Entry
rightHandItem) const
{
return (searchKey > rightHandItem.getKey());
}
template
Entry
{
item = 0;
searchKey = "";
}
template
Entry
{
item = newEntry;
searchKey = sKey;
}
template
ItemType Entry
{
return item;
}
template
KeyType Entry
{
return searchKey;
}
template
void Entry
{
item = newEntry;
}
template
void Entry
{
searchKey = sKey;
}
#endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
