Question: #ifndef SET _ TYPE #define SET _ TYPE #include #include #include #include using namespace std; class IteratorOutOfBounds { public: string Msg ( ) { return

#ifndef SET_TYPE
#define SET_TYPE
#include
#include
#include
#include
using namespace std;
class IteratorOutOfBounds {
public:
string Msg(){
return "Iterator is out of bounds. Nothing left to iterate over.";
}
};
const int DEFAULT_BUCKETS =10;
const double DEFAULT_LOAD_FACTOR =1.0;
template
class SetType
{
public:
// Constructors
SetType();
explicit SetType(int numBucks);
SetType(SetType& other);
~SetType();
void Add(T elem);
void Remove(T elem);
bool Contains(T elem);
void MakeEmpty();
int Size() const {
return numElems;
}
double LoadFactor() const;
void SetMaxLoad(double max);
void Rehash(int newNumBuckets);
SetType operator+(T elem); // Add
SetType operator-(T elem); // Remove
SetType operator+(SetType& otherSet); // Union
SetType operator-(SetType& otherSet); // Difference
SetType operator*(SetType& otherSet); // Intersection
SetType& operator=(SetType const& otherSet); // Assignment (does deep copy)
void ResetIterator(); // Reset iterator
T GetNextItem();
private:
forward_list* buckets; // An array of forward_list's
//(each index is a forward_list)
int numBuckets; // total number of buckets
int GetHashIndex(const T& key); // Gets the hash index given the elem
int numElems; // total number of elements
double maxLoad; // load factor of the Set
// This function is used by the
// copy constructor and the assignment operator.
void copySet(const SetType& otherSet);
// Iterator variables
int currBucket; // What bucket is the iterator on?
int iterCount; // What element are we on?
mutable typename forward_list::iterator bucketIter; // The iterator of the current bucket
// Any other private functions and variables you want/need
};
#include "SetType.cpp"
#endif
Settype.cpp
#include
#include
#include "SetType.h"
using namespace std;
template
SetType::SetType(){
// Create an array of forward_lists and initially set to an empty forward_list
buckets = new forward_list[DEFAULT_BUCKETS];
numBuckets = DEFAULT_BUCKETS;
numElems =0;
maxLoad = DEFAULT_LOAD_FACTOR;
currBucket =0;
iterCount =0;
}
// Constructor that takes a number of buckets
template
SetType::SetType(int numBucks){
numBuckets = numBucks;
buckets = new forward_list[numBuckets]; // Allocate new array of buckets
numElems =0; // No elements in the new set initially
maxLoad = DEFAULT_LOAD_FACTOR; // Default load factor
currBucket =0; // Reset iterator
iterCount =0;
}
template
SetType::SetType(SetType &otherSet){
copySet(otherSet);
}
template
SetType::~SetType(){
delete [] buckets;
}
template
SetType SetType::operator+(T elem){
SetType result;
// Your code here
return result;
}
template
SetType SetType::operator-(T elem){
SetType result;
// Your code here
return result;
}
template
SetType SetType::operator+(SetType& otherSet){
SetType result;
// Your code here
return result;
}
template
SetType SetType::operator*(SetType& otherSet){
SetType result;
// Your code here
return result;
}
template
SetType SetType::operator-(SetType& otherSet){
SetType result;
// Your code here
return result;
}
template
T SetType::GetNextItem(){
// Returns the current item and then move to the next item
T item;
// Your code here
return item;
}
template
int SetType::GetHashIndex(const T& key){
// This is done... No touching!
unordered_map mapper;
typename unordered_map::hasher hashFunction = mapper.hash_function();
return static_cast(hashFunction(key)% numBuckets);
}
template
void SetType::SetMaxLoad(double max){
// This function is done
if (max <0.1)
maxLoad =0.1;
else
maxLoad = max;
}
template
SetType& SetType::operator=(SetType const &other){
// Your code here
return *this;
}
template
void SetType::Rehash(int newNumBuckets){
SetType rehashedSet(newNumBuckets);
// Your code here
*this = rehashedSet;
}
can you help me implement this based on the header above?

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 Programming Questions!