Question: Create a class IntegerSet for which each object can hold integers in the range 0 through 100. A set is represented internally as an array

Create a 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 elements a[i] is 1 if integer I is in the set.

Provide two constructors for the class.

  • One constructor does not have any parameters. 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 unionOfsets member 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 in each of the existing sets).
  • An insertElement member function inserts a new integer k into a set (be 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).

Separate your class definition from implementation. Your class definition must be stored in a file called IntegerSet.h. Your class implementation must be stored in a file called IntegerSet.cpp. Provide a driver program (hw2.cpp) to test capabilities of your IntegerSet class. A sample output is provided below. The output is REQUIRED to look like this. Make sure to run your program with various inputs to make sure it works in ALL appropriate circumstances.

Sample Output (with input)

$ ./hw2.out 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 What element would you like to insert into set A?:77 Set A is now: { 6 34 45 76 77 } Deleting 77 from set A... Set A is now: { 6 34 45 76 } Now creating a set of specific values and testing the bounds limits. Creating array of size 10: {25, 67, 2, 9, 99, 105, 45, -5, 100, 1} Invalid insert of 105 attempted! Invalid insert of -5 attempted! Set C is: { 1 2 9 25 45 67 99 100 } 

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