C++ Programming Set Class (Problem One)
I need help with writing functions in C++. The C++ class I am in is going like way too fast and it's like the basic (not BASIC) class. First of all I would like to know what I am doing is correct. Like in noted in the rules I am not looking for you to write the whole program, well unless you want to.
Write the set.h file. There are guidelines for this file. For the sake of commonality, I am giving you the member functions and the private data. Make sure you stick to my names so that I can swam files in and out to test them.
- Your private data should include an array of doubles (size = 100) called setArray. Itshould also include one integer called size . These structures will be used to store the set data (the elements) and to keep track of the set size (respectively).
- Your public functions should include all of and only the following:
- set() //a constructor
- printSet //prints the object to the console
- setUnion //unions the object with another set
- setInteresection //intersects object with another set
- isEmpty //determines if the object is empty
- isElementOf //determines if an element is in a object
- addElement //adds element to the object
- deleteElement //removes an element from the object
- getSize //returns the current size of the object
- isEqual //determines if the object is equal to a set
now I'm thinking that it is...
Wait I don't have the answer with me but I will like in about half an hour. But if you want to help out please do.
Problem One (header file)
Hey this is what I have for the header file. I don't know if it is all correct. I can't use const because I don't know what it is (We haven't gone over it)
set(); //a constructor
void printSet(); //prints the object to the console
void setUnion(set); //unions the object with another set
void setIntersection(set); //interesects object with another set
bool isEmpty(); //determines if the object is empty
bool isElementOf(set); //determines if an element is in an object
void addElement(set); //adds element to the object
double deleteElement(set); //removes an element from the object
int getSize(); //returns the current size of the object
bool isEqual(set); //determines if the object is equal to a set
More information on Problem Two
Be sure to check for boundary cases, i.e. cases that may cause some problems. For instance, what happens when you try to add an element to a set that already has 100 elements in it? The cumputer will crash on you more than likely. To prevent this your <COLOR=red>addElement</COLOR> function should check to see if the set is full before adding it. If it is, it should probably print out an error message such as <COLOR=red>"Error: set is full. Element not added."</COLOR> The same sort of thing should happen is you try to remove an element that is not in a set. Be careful with the union function as well; it would be quite easy to exceed the maximum length.
The above paragraph is taken right from the worksheet.