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& rightHandItem) const;

bool operator>(const Entry& rightHandItem) const;

}; // end Entry

#include "Entry.cpp"

#endif

//ADT dictionary.@file Entry.cpp

#ifndef ENTRY_CPP

#define ENTRY_CPP

template

bool Entry::operator==(const Entry&

rightHandItem) const

{

return (searchKey == rightHandItem.getKey());

} // end operator==

template

bool Entry::operator>(const Entry&

rightHandItem) const

{

return (searchKey > rightHandItem.getKey());

}

template

Entry::Entry()

{

item = 0;

searchKey = "";

}

template

Entry::Entry(ItemType newEntry, KeyType sKey)

{

item = newEntry;

searchKey = sKey;

}

template

ItemType Entry::getItem() const

{

return item;

}

template

KeyType Entry::getKey() const

{

return searchKey;

}

template

void Entry::setItem(const ItemType& newEntry)

{

item = newEntry;

}

template

void Entry::setKey(const KeyType& sKey)

{

searchKey = sKey;

}

#endif

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!