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

Create class IntegerSet for which each object can hold integers in the range 0 t

ID: 441888 • Letter: C

Question

Create class IntegerSet for which each object can hold integers in the range 0 through 100 inclusive. A set is represented internally as an array of booleans. Array element a[ i ] is true if integer i is in the set. Array element a[ j ] is false if integer j is not in the set. The default constructor initializes a set to the so-called "empty set", i.e. a set whose array contains false for all integers. Provide an additional constructor that receives an array of integers and uses the array to initialize a set object. Provide appropriate setter and getter methods for all members storing the state of the class (i.e. the boolean array that represents the set).

Explanation / Answer

please rate - thanks

public class IntegerSet

{boolean []set=new boolean[101];


public IntegerSet(int a[])

{int i;

for(i=0;i<101;i++)

{set[i]=false;

}

for(i=0;i<101;i++)

set[a[i]]=true;

}

public IntegerSet()

{int i;

for(i=0;i<101;i++);

set[i]=false;

}

public void setSet(int a[])

{int i;

for(i=0;i<101;i++)

{set[i]=false;

}

for(i=0;i<101;i++)

set[a[i]]=true;

}

public boolean[] getSet()

{return set;

}

}

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