Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create class IntegerSet. Each IntegerSet object can hold integers in the range 0-100. The set is represented by an array of bools. Array element i
Create class IntegerSet. Each IntegerSet object can hold integers in the range 0-100. The set is represented by an array of bools. Array element i is true if integer i is in the set. Array element aljl is false if integer j is not in the set. The parameterless constructor initializes the array to the "empty set"(i.e., a set whose array representation contains all false values) Provide the following methods: a) Method Union creates a third set that is the set-theoretic union of two existing sets (i.e., an element of the third set's array is set to true if that element is true in either or both of the existing sets- otherwise, the element of the third set is set to false b) Method Intersection creates a third set which is the set-theoretic intersection of two existing sets (i.e., an element of the third set's array is set to false if that element is false in either or both of the existing sets-otherwise, the element of the third set is set to true) c) Method InsertElement inserts a new integer k into a set (by setting a [k] to true) d) Method DeleteElement deletes integer m (by setting alm] to false). e) Method ToString returns a string containing a set as a list of numbers separated by spaces. Include only those elements that are present in the set. Useto represent an empty set. f) Method IsEqualTo determines whether two sets are equal. g) Method InputSet Test your class IntegerSet by using the main method below: // initialize two sets Console.WriteLine( 'Input Set A" ); IntegerSet set1InputSet) Console.WriteLine "nInput Set B") IntegerSet set2-InputSet); IntegerSet unionset1.Union( set2 IntegerSet intersection= set 1. Intersection ( set2 ); // prepare output Console.WriteLine( "nSet A contains elements:" Console.WriteLine( set1.ToString) Console.WriteLine "nSet B contains elements:"; Console.WriteLine( set2.ToString) Console.WriteLine( "nUnion of Set A and Set B contains elements:" Console.WriteLine( union. ToString)) Console.WriteLine "nIntersection of Set A and Set B contains elements:"; Console.WriteLine( intersection.ToString); // test whether two sets are equal if set1.IsEqualTo( set2)) Console.WriteLine "nSet A is equal to set B") else Console.WriteLine( "nSet A is not equal to set B" /1 test insert and delete Console.WriteLine "nInserting 77 into set A." ); set1.InsertElement( 77); Console.WriteLine( "InSet A now contains elements:" ); Console.WriteLine( set1.ToString) Console.WriteLine "nDeleting 77 from set A."): set1.DeleteElement 77; Console.WriteLine "nSet A now contains elements:"; Console.WriteLine set1.ToString)) // test constructor intI intArray 25, 67, 2, 9, 99, 105, 45, -5, 100, 1 1; IntegerSet set3new IntegerSet intArray); Console.WriteLine "nNew Set contains elements:"; Console.WriteLine set3. ToStringO); ) // end Main
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