Question
Create a class, named IntSet, that implements a set that will store integer values in the range of 0 through 1000, inclusive. (We are using
Create a class, named IntSet, that implements a set that will store integer values in the range of 0 through 1000, inclusive. (We are using a static const for this upper bound, so that the value can be modified, and your program re-compiled, to work with an alternate value.) If you don't remember the basics of sets and set operations, you may find theset entry at Wikipediahelpful. The required member functions are described belowdo not modify them without consulting with me first.
You must use the code from the provided class definition and main function. Do not modify the provided code, except where indicated or to add comments, without consulting me and getting permission via email. Don't forget to add all the proper array and parameter checking. If you modify the main function or testing purposes while you are developing your program (this is recomended), return it to the provided code before you submit your assignment. Note that when I test your IntegerSet class, I may use another test routine. Make sure that your IntegerSet class conforms exactly to the specification.
Your default constructor must allow between zero and five elements to be inserted into the set initally.
Your member functions insertElement and deleteElement should work by adding (or removing) the specified element to the set. If insertion or deletion is attempted on an element that is out of range, do nothing.
The toString member function should return a string containing standard set notation (comma seperated list inside curley braces)
example sets: {1, 2, 4, 6, 34, 58} {1} {}
The member function equals should have an integer set as its parameter and return type bool. It should determine if two sets have exactly the same members.
The member function hasElement should have return type bool and determine if the parameter is an element of the set. (Illegal element values should also return false.)
The intersection and union functions should be called intersectionOf and unionOf. Both should take two integer set as their parametes and perform the requested operation setting the contents of the set on which the function was invoked to be exactly the result.
// s1 becomes the union of s2 and s3, NOT the union of s1, s2, and s3 // s2 and s3 are unmodified s1.unionOf(s2, s3);
The function getMax returns the largest value that could be in the set (not that largest value that is in the set.)
class IntSet{ public: IntSet(int =-1,int =-1, int =-1, int =-1, int =-1); void insertElement(int); void deleteElement(int); std::string toString() const; void unionOf(IntSet &, IntSet &); void intersectionOf(IntSet &, IntSet &); bool equals(IntSet) const; bool hasElement(int) const; int static getMax(){ return MAXSETVAL; } private: static const int MAXSETVAL=1000; bool data[MAXSETVAL+1]; }; // NOTE: this main function test routine must be used for your final submission // this is not an exhaustive test, so you'll still need to do your own testing! main(){ IntSet is1,is2(1,2,5),is3; cout << "CS19 Program #4 Integer Set Class"<
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