C++ Please upload files and mark them, do main and the rest Please comment so I can add Entry.h, entry.cpp, HashedEntry.
Posted: Fri May 20, 2022 3:35 pm
C++
Please upload files and mark them, do main and the rest
Please comment so I can add Entry.h, entry.cpp,
HashedEntry.cpp and HashedDictionary.cpp in the comment as it can't
fit here.Thank you
Implement the ADT Dictionary in Chapter 18 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
main.cpp
//do main
HashedEntry.h
#ifndef _HASHED_ENTRY
#define _HASHED_ENTRY
#include "Entry.h"
template<class KeyType,
class ItemType>
class HashedEntry : public
Entry
{
private:
HashedEntry* nextPtr;
public:
HashedEntry();
HashedEntry(ItemType newEntry, KeyType
searchKey);
HashedEntry(ItemType newEntry, KeyType
searchKey,
HashedEntry* nextEntryPtr);
void setNext(HashedEntry*
nextEntryPtr);
HashedEntry* getNext() const;
}; // end HashedEntry
#include "HashedEntry.cpp"#endif
__________________________
HashedDictionary.h
#ifndef _HASHED_DICTIONARY
#define _HASHED_DICTIONARY
#include "DictionaryInterface.h"
#include "HashedEntry.h"
//#include "NotFoundException.h"
const int TABLE_SIZE = 11;
template <class KeyType,
class ItemType>
class HashedDictionary :
public DictionaryInterface
{
private:
// Binary search tree of dictionary entries
HashedEntry *hashTable[TABLE_SIZE];
//void traversalHelper(Entry& theEntry);
int getHashIndex(const
KeyType&);
public:
HashedDictionary();
//HashedDictionary(const HashedDictionary&
dict);
virtual ~HashedDictionary();
// The declarations of the public methods appear
here and are the
// same as given in Listing 18-3 for the class
ArrayDictionary.
bool isEmpty()
const;
int getNumberOfItems()
const;
bool add(const KeyType&
searchKey, const ItemType& newItem);
bool remove(const
KeyType& searchKey);
void clear();
ItemType getItem(const
KeyType& searchKey) const; // throw
(NotFoundException);
bool
contains(const KeyType& searchKey)
const;
/** Traverses the items in this dictionary in
sorted search-key order
and calls a given client function once for each item. */
void
traverse(void visit(ItemType&))
const;
}; // end HashedDictionary
#include "HashedDictionary.cpp"
#endif
DictionaryInterface.h
#ifndef _DICTIONARY_INTERFACE
#define _DICTIONARY_INTERFACE
//#include "NotFoundException.h"
template<class KeyType,
class ItemType>
class DictionaryInterface
{
public:
/** Sees whether this dictionary is empty.
@return True if the dictionary is empty;
otherwise returns false. */
virtual bool
isEmpty() const = 0;
/** Gets the number of items in this
dictionary.
@return The number of items in the dictionary.
*/
virtual int
getNumberOfItems() const = 0;
/** Inserts an item into this dictionary according
to the item’s search key.
@pre The search key of the new item differs
from all search
keys presently in the dictionary.
@post If the insertion is successful, newItem
is in its
proper position within the dictionary.
@param searchKey The search key associated with
the item to be inserted.
@param newItem The item to add to the
dictionary.
@return True if item was successfully added, or
false if not. */
virtual bool
add(const KeyType& searchKey,
const ItemType& newItem) = 0;
/** Removes an item with the given search key from
this dictionary.
@post If the item whose search key equals
searchKey existed in the dictionary,
the item was removed.
@param searchKey The search key of the item to
be removed.
@return True if the item was successfully
removed, or false if not. */
virtual bool
remove(const KeyType& searchKey) = 0;
/** Removes all entries from this dictionary.
*/
virtual void
clear() = 0;
/** Retrieves an item with a given search key from
a dictionary.
@post If the retrieval is successful, the item
is returned.
@param searchKey The search key of the item to
be retrieved.
@return The item associated with the search
key.
@throw NotFoundException if the item does not
exist. */
virtual ItemType
getItem(const KeyType& searchKey)
const /*throw (NotFoundException)*/ = 0;
/** Sees whether this dictionary contains an item
with a given
search key.
@post The dictionary is unchanged.
@param searchKey The search key of the item to
be retrieved.
@return True if an item with the given search
key exists in the dictionary. */
virtual bool
contains(const KeyType& searchKey)
const = 0;
/** Traverses this dictionary and calls a given
client function once for each item.
@post The given function’s action occurs once
for each item in the
dictionary and possibly alters the item.
@param visit A client function. */
virtual void
traverse(void visit(ItemType&))
const = 0;
}; // end DictionaryInterface
#endif
Please upload files and mark them, do main and the rest
Please comment so I can add Entry.h, entry.cpp,
HashedEntry.cpp and HashedDictionary.cpp in the comment as it can't
fit here.Thank you
Implement the ADT Dictionary in Chapter 18 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
main.cpp
//do main
HashedEntry.h
#ifndef _HASHED_ENTRY
#define _HASHED_ENTRY
#include "Entry.h"
template<class KeyType,
class ItemType>
class HashedEntry : public
Entry
{
private:
HashedEntry* nextPtr;
public:
HashedEntry();
HashedEntry(ItemType newEntry, KeyType
searchKey);
HashedEntry(ItemType newEntry, KeyType
searchKey,
HashedEntry* nextEntryPtr);
void setNext(HashedEntry*
nextEntryPtr);
HashedEntry* getNext() const;
}; // end HashedEntry
#include "HashedEntry.cpp"#endif
__________________________
HashedDictionary.h
#ifndef _HASHED_DICTIONARY
#define _HASHED_DICTIONARY
#include "DictionaryInterface.h"
#include "HashedEntry.h"
//#include "NotFoundException.h"
const int TABLE_SIZE = 11;
template <class KeyType,
class ItemType>
class HashedDictionary :
public DictionaryInterface
{
private:
// Binary search tree of dictionary entries
HashedEntry *hashTable[TABLE_SIZE];
//void traversalHelper(Entry& theEntry);
int getHashIndex(const
KeyType&);
public:
HashedDictionary();
//HashedDictionary(const HashedDictionary&
dict);
virtual ~HashedDictionary();
// The declarations of the public methods appear
here and are the
// same as given in Listing 18-3 for the class
ArrayDictionary.
bool isEmpty()
const;
int getNumberOfItems()
const;
bool add(const KeyType&
searchKey, const ItemType& newItem);
bool remove(const
KeyType& searchKey);
void clear();
ItemType getItem(const
KeyType& searchKey) const; // throw
(NotFoundException);
bool
contains(const KeyType& searchKey)
const;
/** Traverses the items in this dictionary in
sorted search-key order
and calls a given client function once for each item. */
void
traverse(void visit(ItemType&))
const;
}; // end HashedDictionary
#include "HashedDictionary.cpp"
#endif
DictionaryInterface.h
#ifndef _DICTIONARY_INTERFACE
#define _DICTIONARY_INTERFACE
//#include "NotFoundException.h"
template<class KeyType,
class ItemType>
class DictionaryInterface
{
public:
/** Sees whether this dictionary is empty.
@return True if the dictionary is empty;
otherwise returns false. */
virtual bool
isEmpty() const = 0;
/** Gets the number of items in this
dictionary.
@return The number of items in the dictionary.
*/
virtual int
getNumberOfItems() const = 0;
/** Inserts an item into this dictionary according
to the item’s search key.
@pre The search key of the new item differs
from all search
keys presently in the dictionary.
@post If the insertion is successful, newItem
is in its
proper position within the dictionary.
@param searchKey The search key associated with
the item to be inserted.
@param newItem The item to add to the
dictionary.
@return True if item was successfully added, or
false if not. */
virtual bool
add(const KeyType& searchKey,
const ItemType& newItem) = 0;
/** Removes an item with the given search key from
this dictionary.
@post If the item whose search key equals
searchKey existed in the dictionary,
the item was removed.
@param searchKey The search key of the item to
be removed.
@return True if the item was successfully
removed, or false if not. */
virtual bool
remove(const KeyType& searchKey) = 0;
/** Removes all entries from this dictionary.
*/
virtual void
clear() = 0;
/** Retrieves an item with a given search key from
a dictionary.
@post If the retrieval is successful, the item
is returned.
@param searchKey The search key of the item to
be retrieved.
@return The item associated with the search
key.
@throw NotFoundException if the item does not
exist. */
virtual ItemType
getItem(const KeyType& searchKey)
const /*throw (NotFoundException)*/ = 0;
/** Sees whether this dictionary contains an item
with a given
search key.
@post The dictionary is unchanged.
@param searchKey The search key of the item to
be retrieved.
@return True if an item with the given search
key exists in the dictionary. */
virtual bool
contains(const KeyType& searchKey)
const = 0;
/** Traverses this dictionary and calls a given
client function once for each item.
@post The given function’s action occurs once
for each item in the
dictionary and possibly alters the item.
@param visit A client function. */
virtual void
traverse(void visit(ItemType&))
const = 0;
}; // end DictionaryInterface
#endif