bool add(int anInt) // Pre: contains(anInt) ? size() <= MAX_SIZE : size() < MAX_SIZE // Post: If contains(anInt) returns false, anInt has been // added to the invoking IntSet as a new element and // true is returned, otherwise the invoking IntSet is // unchanged and false is returned. // bool remove(int anInt) // Pre: (none) // Post: If contains(anInt) returns true, anInt has been // removed from the invoking IntSet and true is // returned, otherwise the invoking IntSet is unchanged // and false is returned. bool add(int anInt); bool remove(int anInt); bool IntSet::add(int anInt) { if(used <= data[MAX_SIZE]) // check if the array is not full { return contains(used); //if not full then return to data } return false; } bool IntSet::remove(int anInt) { cout << "remove() is not implemented yet..." << endl; return false; // dummy value
bool add(int anInt)
// Pre: contains(anInt) ? size() <= MAX_SIZE : size() < MAX_SIZE
// Post: If contains(anInt) returns false, anInt has been
// added to the invoking IntSet as a new element and
// true is returned, otherwise the invoking IntSet is
// unchanged and false is returned.
// bool remove(int anInt)
// Pre: (none)
// Post: If contains(anInt) returns true, anInt has been
// removed from the invoking IntSet and true is
// returned, otherwise the invoking IntSet is unchanged
// and false is returned.
bool add(int anInt);
bool remove(int anInt);
bool IntSet::add(int anInt)
{
if(used <= data[MAX_SIZE]) // check if the array is not full
{
return contains(used); //if not full then return to data
}
return false;
}
bool IntSet::remove(int anInt)
{
cout << "remove() is not implemented yet..." << endl;
return false; // dummy value returned
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps