Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Help: I need help making the IntegerSet.cpp file and the IntegerSet.h file to ru

ID: 3837357 • Letter: H

Question

Help:
I need help making the IntegerSet.cpp file and the IntegerSet.h file to run with IntegerSetDriver.cpp file. Here are my directions:
This class shall provide member/friend functions including operator overloading for the common set operations. Provide a union operation (operator +) that creates a third set which is the set-theoretic union of two existing sets (i.e., an element is in the third set if it is in the first or second set). Provide an intersection operation (operator *) that creates a third set which is the set-theoretic intersection of two existing sets (i.e., an element is in the third set if it is in both sets). Provide an elements member function that returns the number of elements and an array of elements via a parameter. Provide an isElem member function that returns true if an element is in the set and returns false otherwise. Provide an insert member function that inserts a new integer k into a set (by setting a[k] to true). Provide a remove member function that removes integer m (by setting a[m] to false). Overload operator >> as a friend function to input a set of elements (input one element at a time on a line until -1 is entered). Overload operator << as a friend function to print a set as a list of numbers separated by one space and enclosed by {}. Print only those elements that are present in the set (i.e., their position in the array has a value of 1 or true; for example, {1 5 10}). Print {} for an empty set. Provide both subset (<=) and superset (>=) operations by overloading the two operators <= and >= (set 1 is a subset of set 2 if all elements in set 1 are also in set 2 and set 2 would be a superset of s1).
And here is my code:

IntegerSet.h:

#define INTEGERSET_H

#include <iostream>
#include <string>

using namespace std;

class IntegerSet
{
   private:
       bool array[255];
  
   public:
       IntegerSet();
       IntegerSet(int m);
       IntegerSet(const int arr[], int n);
       int elements (int arr[]) const;
       bool isElem(int m) const;
       IntegerSet &insert(int m); //allow cascading calls
       IntegerSet &remove(int m);
       IntegerSet operator+(IntegerSet& s);
       IntegerSet operator*(IntegerSet& s);
       bool operator<=(IntegerSet s);
       bool operator>=(IntegerSet s);
      
       friend ostream &operator<<(ostream &out, IntegerSet s);
       friend istream &operator>>(istream &in, IntegerSet s);
};
#endif

IntegerSet.cpp

#include <iostream>
#include <string>
#include "IntegerSet.h"

using namespace std;

IntegerSet::IntegerSet()
{
   array[255] = false;
}

IntegerSet::IntegerSet(int m)
{
  
   if(m>255)
   {
       array[m] = false;
   }
   else
   {
       array[m] = true;
   }
}

IntegerSet::IntegerSet(const int arr[], int n)
{
   for(int i =0; i<256; i++)
   {
       array[i] = false;
   }
   for (int i = 0; i<n; i++)
   {
       int val = array[i];
       array[val] = true;
   }
}

int IntegerSet::elements (int arr[]) const
{
   for(int i = 0; i<256; i++)
   return arr[i];
}

bool IntegerSet::isElem(int m) const
{
   for(int i = 0; i<=m; i++)
   if(m>255)
   {
       return false;
   }
   else
   {
       return true;
   }
}

IntegerSet& IntegerSet::insert(int m)
{
   this->array[m] = true;
   return *this;
}

IntegerSet& IntegerSet::remove(int m)
{
   this->array[m] = false;
   return *this;
}

IntegerSet IntegerSet::operator+(IntegerSet& s)
{
   IntegerSet r;
   for(int i = 0; i<256; i++)
   {
       if(this->array[i] == true || s.array[i] == true)
       {
           r.array[i] = true;
       }
   }
   return r;
}

IntegerSet IntegerSet::operator*(IntegerSet& s)
{
   IntegerSet r;
   for(int i = 0; i<256; i++)
   {
       if(this->array[i] == true && s.array[i] == true)
       {
           r.array[i] = true;
       }
   }
   return r;
}

bool IntegerSet::operator<=(const IntegerSet s)
{
   for(int i = 0; i<256; i++)
   {
       if(this->array[i] == true && s.array[i] !=true)
       {
           return false;
       }
       else
       {
           return true;
       }
   }
  
}

bool IntegerSet::operator>=(IntegerSet s)
{
   for(int i = 0; i<256; i++)
   {
       if(s.array[i] == true && this->array[i] !=true)
       {
           return false;
       }
       else
       {
           return true;
       }
   }
  
}

ostream &operator<<(ostream &out, IntegerSet s)
{
   for(int i = 0; i<256; i++)
   {
       if(s.array[i] == true)
       {
           out<<i<<" ";
       }
       else
       {
           cout<<endl;
       }
   }
   return out;
}

istream &operator>>(istream &in, IntegerSet s)
{
   int n = 0;
   while(n==1)
   {
       in>>n;
       if(n!=-1)
       {
           s.array[n] = true;
       }
       else
       {
           break;
       }
   }
   return in;
}

IntegerSetDriver.cpp

#include <iostream>
#include <string>
#include "IntegerSet.h"

using namespace std;

void print1(IntegerSet s);               // pass by value
void print2(IntegerSet &s);               // pass by reference
void print3(const IntegerSet &s);       // pass by reference with const

int main()
{
   int arr1[6] = {5, 2, 20, 4, 13, 256};
   int arr2[256];            // can hold up to 256 elements
   int count;
   IntegerSet s1;          // {}
   IntegerSet s2(2);       // {2}
   IntegerSet s3(arr1, 6); // {2 4 5 13 20}, 256 was ignored
   IntegerSet s4 = s1;     // {}
   IntegerSet s5 = s2;     // {2}

   cout << "TC1: s1 should be empty ";
   cout << "s1: " << s1 << endl;   // s1: {}

   cout << "TC2: s3 should have 2, 4, 5, 13, and 20 ";
   s3.remove(500);           // ignore since it is not a valid element
   cout << "remove an illegal element (500) so ignore completely ";
   cout << "s3: " << s3 << endl;   // s3: {2 4 5 13 20}

   cout << "TC3: s5 should have 2 ";
   cout << "s5: " << s5 << endl;   // s5: {2}

   s2.insert(7);           // s2 is now {2 7}
   cout << "TC4: insert 7 into s2 so s2 should have 2 and 7 ";
   cout << "s2: " << s2 << endl;   // s2: {2 7}

   s4 = s2 * s3;           // s4 is now {2}, s2 and s3 are still the same
   cout << "TC5: intersection of s2 and s3 should be 2 ";
   cout << "s4: " << s4 << endl;   // s4: {2}

   cout << "TC6: input 5 300 255 so s5 should have 5 and 255 ";
   cout << "Enter values for a set (-1 to stop): ";
   cin >> s5;              // enter: 5 300 255 -1
                            // s5 is now {5, 255}, 300 was ignore
   cout << "s5: " << s5 << endl;   // s5: {5 255}

   cout << "TC7: cascading calls ";
   s3.remove(7).remove(2); // s3 is now {4 5 13 20}
                           // 2 was removed and 7 is not in the set
   s3.insert(99).insert(5);// s3 is now {4 5 13 20 99}
                           // 99 was inserted and 5 is already in the set

   cout << "removed 2 and inserted 99 so s3 should have 4, 5, 13, 20, and 99 ";
   cout << "s3: " << s3 << endl;   // s3: {4 5 13 20 99}

   cout << "TC8: getting the count (5) and elements for s3 (4 5 13 20 99) ";
   count = s3.elements(arr2);
   cout << "count: " << count << endl;
   cout << "Element(s): ";
   for (int i = 0; i < count; i++)
        cout << arr2[i] << " ";
   cout << endl;

   cout << "TC9: s4 should not be a subset of s3 ";
   if (s4 <= s3)           // s4 is not a subset of s3
       cout << "s4 is a subset of s3 ";
   else
       cout << "s4 is not a subset of s3 ";

   cout << "TC10: assign s3 to s4 ";
   s4 = s3;               // s4: {4 5 13 20 99}
   cout << "s4 now is a subset of s3 ";
   if (s4 <= s3)           // s4 is now a subset of s3
       cout << "s4 is a subset of s3 ";
   else
       cout << "s4 is not a subset of s3 ";

   cout << "TC11: passing object and 0 should not be in s3 ";
   print1(s3);
   print2(s3);
   print3(s3);

   // Create more objects and test cases below

   return 0;
}

void print1(IntegerSet s)
{
   if (s.isElem(0))
        cout << "print1 (pass by value): 0 is in the set." << endl;
   else
        cout << "print1 (pass by value): 0 is not in the set." << endl;
}

void print2(IntegerSet &s)
{
   if (s.isElem(0))
        cout << "print2 (pass by reference): 0 is in the set." << endl;
   else
        cout << "print2 (pass by reference): 0 is not in the set." << endl;
}

void print3(const IntegerSet &s)
{
   if (s.isElem(0))
        cout << "print3 (pass by reference with const): 0 is in the set." << endl;
   else
        cout << "print3 (pass by reference with const): 0 is not in the set." << endl;
}

Explanation / Answer

#include&lt;iostream&gt;
#include&lt;cstdio&gt;
#include&lt;sstream&gt;
#include&lt;algorithm&gt;
#define pow2(n) (1 &lt;&lt; (n))
using namespace std;

/*
* Node Declaration
*/
struct avl_node
*root;

/*
* category Declaration
*/
class avlTree

};

/*
* Main Contains Menu
*/
int main()
gamma hydroxybutyrate_height = max (l_height, r_height);
h = max_height + 1;
}
return h;
}

/*
* Height distinction
*/
int avlTree::diff(avl_node *temp)
come b_factor;
}

/*
* Right- Right Rotation
*/
avl_node *avlTree::rr_rotation(avl_node *parent)
worker = parent-&gt;right;
parent-&gt;right = temp-&gt;left;
temp-&gt;left = parent;
come back temp;
}
/*
* Left- Left Rotation
*/
avl_node *avlTree::ll_rotation(avl_node *parent)
worker = parent-&gt;left;
parent-&gt;left = temp-&gt;right;
temp-&gt;right = parent;
come back temp;
}

/*
* Left - Right Rotation
*/
avl_node *avlTree::lr_rotation(avl_node *parent)
worker = parent-&gt;left;
parent-&gt;left = rr_rotation (temp);
come back ll_rotation (parent);
}

/*
* Right- Left Rotation
*/
avl_node *avlTree::rl_rotation(avl_node *parent)
worker = parent-&gt;right;
parent-&gt;right = ll_rotation (temp);
come back rr_rotation (parent);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote