Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

This is what I have so far:

Header File:

#include using namespace std;

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 #include IntergerSet.h using namespace std;

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 #include IntergerSet.h using namespace std;

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

Enter set A: Enter an element (-1 to end): 45 Enter an element (-1 to end): 76 Enter an element (-1 to end): 34 Enter an element (-1 to end): 6 Enter an element (-1 to end): -1 Entry complete Enter set B Enter an element (-1 to end): 34 Enter an element (-1 to end): 8 Enter an element (-1 to end): 93 Enter an element (-1 to end): 45 Enter an element (1 to end): -1 Entry complete Union of A and B is: 6 8 34 45 76 93) Intersection of A and B is: 34 45) Set A is not equal to set B Inserting 77 into set A.. Set A is now (6 34 45 76 77) Deleting 77 from set A... Set A is now 6 34 45 76) Create an array of size 10: 125, 67,2,9,99, 105, 45, -5,100, 1 and use it to initialize a set C Invalid insert of 105 attempted! Invalid insert of -5 attempted! Set C is: (1 29 25 45 67 99 100 )

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+ Have they changed the way employers view IP?

Answered: 1 week ago