Question
Write a computer program that defines the class Set (assume that the elements are integers). The class should contain methods to perform the operations listed
Write a computer program that defines the class Set (assume that the elements are integers). The class should contain methods to perform the operations listed below. Write a test program that tests your Set class. The test program will be a menu-like to test all the operations in class Set a) Different constructors to initialize the set (one is to set the elements from a one dimension array) b) union: find the union of the set with a given set. OUTPUT: a Set object. c) intersection: find the intersection of the set with a given set. OUTPUT: a Set object. d) difference: find the difference of the set and the given set (Set given Set). OUTPUT: a Set object. e) Cartesian product: find the Cartesian product (Set X given set). OUTPUT: prints out the product. f) Check whether the set is a subset of another set. OUTPUT: True or False. g) Find the powerset of the set. OUTPUT: prints out the powerset. h) isEmpty method that returns true if the set is empty (no elements). i) isElement method that takes an element and check if it is an element of the set. j) isEqual method that check if the set is equal to a given set. k) getCardinality method that returns the cardinality of the set. l) addElement method that adds element to the set. Make sure that you dont add an existing element. You will use isElement check before you try to add it. m) removeElement method to remove an element from the set. n) Clear method to remove all elements of the set. o) toArray that converts the object of the Set class to a one dimensional array. p) print method to print the elements of the set.
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