// SetDataStructure.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "SetT.h" using namespace std; int main() { // You should create your own test driver that...

1 answer below »
See sets PDF


// SetDataStructure.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "SetT.h" using namespace std; int main() { // You should create your own test driver that takes input files and generates output files. // The input/output should demonstrate functionality of the SetT ADT // (The input below is NOT sufficient for full testing) SetT a; SetT b; b.Add(7); b.Add(9); a.Add(1); a.Add(1); a.Add(2); a.Add(3); a.Add(4); a.Add(5); a + 6; a + b; a - b; return 0; } #pragma once #include #include #include #include using namespace std; template class SetT { public: SetT(); SetT(int numBucks); ~SetT(); void Add(T elem); void Remove(T elem); bool Contains(T elem); void Union(SetT otherSet); void Difference(SetT otherSet); void Intersection(SetT otherSet); void Filter(bool fnc(T elem)); // Extra Credit void Traverse(void visit(T& elem)); int Size() { return numElems }; SetT operator+(T elem); // Add SetT operator+(SetT& other); // Union SetT operator*(SetT& other); // Intersection SetT operator-(T elem); // Remove SetT operator-(SetT& other); // Difference private: forward_list** buckets;// An array of forward_list's (ie, each index is a forward_list pointer) int numBuckets; int getHashIndex(const T& elem); int numElems; // Any other private functions and variables you need }; template int SetT::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 SetT::SetT() { // Create an array of forward_lists and initially set each bucket to null buckets = new forward_list*[100]; for (int i = 0; i < 100;="" i++)="" {="" buckets[i]="nullptr;" }="" numbuckets="100;" }=""> SetT::~SetT() { } template void SetT::Add(T elem) { // Add elem to the set if it doesn't already contain it // Get the bucket index and check to see if the bucket // contains elements. If the bucket has never had elements, // then initialize the forward_list of that bucket. Add the // element to the bucket. } template void SetT::Remove(T elem) { } template bool SetT::Contains(T elem) { return false; } template void SetT::Union(SetT otherSet) { } template void SetT::Difference(SetT otherSet) { } template void SetT::Intersection(SetT otherSet) { } template void SetT::Filter(bool fnc(T elem)) { } template SetT::SetT(int numBucks) { } template inline SetT SetT::operator+(T elem) { this->Add(elem); return result; } template inline SetT SetT::operator+(SetT & other) { return SetT(); // Don't keep... just keeps compiler happy } template inline SetT SetT::operator*(SetT & other) { return SetT();// Don't keep... just keeps compiler happy } template inline SetT SetT::operator-(T elem) { return SetT(); // Don't keep... just keeps compiler happy } template inline SetT SetT::operator-(SetT & other) { return SetT(); // Don't keep... just keeps compiler happy }
Answered Same DayNov 18, 2021

Answer To: // SetDataStructure.cpp : Defines the entry point for the console application. // #include...

Aditi answered on Nov 20 2021
151 Votes
SetDataStructure.cpp
SetDataStructure.cpp
// SetDataStructure.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "S
etT.h"
using namespace std;
int main()
{
    // You should create your own test driver that takes input files and generates output files.
    // The input/output should demonstrate functionality of the SetT ADT
    // (The input below is NOT sufficient for full testing)
    SetT a;
    SetT b;

    b.Add(7);
    b.Add(9);
    a.Add(1);
    a.Add(1);
    a.Add(2);
    a.Add(3);
    a.Add(4);
    a.Add(5);
    a + 6;
    a.Union(b);
    a + b;
    a - b;
    return 0;
}
SetT.h
#pragma once
#include
#include
#include
#include
using namespace std;
template
class SetT
{
public:
    SetT();
    SetT(int numBucks);
    ~SetT();
    void Add(T elem);
    void Remove(T elem);
    bool Contains(T elem);
    void Union(SetT otherSet);
    void Difference(SetT otherSet);
    void Intersection(SetT otherSet);
    void Filter(bool fnc(T elem)); // Extra Credit
    void Traverse(void visit(T& elem));
    int Size() { return numElems; };
    SetT operator+(T elem);         // Add
    SetT operator+(SetT& other); // Union
    SetT operator*(SetT& other); // Intersection
    SetT operator-(T elem);         // Remove
    SetT operator-(SetT& other); // Difference
private:
    forward_list** buckets;    // An array of forward_list's (ie, each index is a forward_list pointer)
    int numBuckets;
    int getHashIndex(const T& elem);
    int numElems;
    // Any other private functions...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here