Question
C++ Create class IntegerSet for which each object can hold integers in the range 0 through 100. A set is represented internally as an array
C++
Create class IntegerSet for which each object can hold integers in the range 0 through 100. A set is represented internally as an array of ones and zeros. Array element a[ i ] is 1 if integer i is in the set. Array element a[ j ] is 0 if integer j is not in the set. Provide two constructors for the class.
One constructor does not have any parameter. This constructor initializes a set to the so-called empty-set, i.e., a set whose array representation contains all zeros.
An additional constructor that receives an array of integers and the size of that array and uses the array to initialize a set object. Provide member functions for the common set operations.
A unionOfsetsmember function creates a third set that is the set-theoretic union of two existing sets (i.e. an element of the third arrays is set to 1 if that element is 1 in either or both of the existing sets, and an element of the third sets array is set to 0 if that element is 0 in each of the existing sets).
An intersectionOfSets member function which creates a third set which is the set-theoretic intersection of two existing sets (i.e. an element of the third sets array is set to 0 if that element is 0 in either or both of the existing sets, and an element of the third sets array is set to 1 if that element is 1 in each of the existing sets).
An insertElement member function inserts a new integer k into a set (by setting a[k] to 1).
A deleteElement member function that deletes integer m (by setting a[m] to 0).
A printSet member function prints a set as a list of numbers separated by spaces. Print only those elements that are present in the set (i.e. their position in the array has a value of 1). Print
for an empty set.
An isEqualTo member function that determines whether two sets are equal.
An emptySet member function that sets all elements of set to 0.
An inputSet member function that reads value from user into the set.
A validEntry member function that determines a valid entry to the set (i.e. in the range 0 through 100)
This is what I have so far:
Header File:
#include
const int RANGE = 101;
class IntergerSet() { public: IntergerSet(); //empty constructor that takes in no param IntergerSet(int array[], int size); //constructor that takes in array and size
IntergerSet intersectionOfSets(IntegerSet sc2); IntergerSet unionOfSets(IntegerSet sc2); void insertElement(int element); void deleteElement(int element); void printSet(); //prints the set int isEqualTo(IntegerSet sc2); //function determines whether two sets are equal void emptySet(); //function that sets all elemnets to 0 void inputSet(); //function to take in input void validEntry(); //validates the entry private: int num[RANGE]; //array of 100 elements }; _____________________________________________
implementation file:
#include
IntegerSet::IntegerSet() //creates empty set { for (int i =0;i IntegerSet::IntegerSet(int array[],int size) //inintalize the set using array[] and size { for(int i=0;i void IntegerSet::insertElement(int element) { if (element } void IntegerSet::deleteElement(int element) { if (element } void IntegerSet::printSet() { for(int i=0;i IntergerSet IntegerSet::intersectionOfSets(IntegerSet sc2) { IntegerSet sc3; for (int i=0;i IntegerSet IntegerSet::unionOfSets(IntegerSet sc2) { IntegerSet sc3; for (int i=0;i ____________________________________ driver file #include int main() { int rand_set1[RANGE]; int rand_set2[RANGE]; int random; srand(unsigned(time(NULL))); for (int i=0;i } THANK YOU FOR THE HELP!!!!!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started