class IntBag { private: int *data; // pointer to dynamically allocated array int capacity; // the size of this array int count; // number of values currently in the bag bool walkInProgress; int walkPosition; // position of last value returned // Copies the data from one bag to another bag. void copyFrom (const IntBag &otherBag); public: // Constructs an empty bag having the default capacity. IntBag (); // Constructs an empty bag having the specified capacity. // Throws a range_error exception if the capacity is unreasonable. IntBag (int capacity); // Copy constructor. IntBag (const IntBag &otherBag); // Destructor ~IntBag (); // Adds a value to the bag. returns true on success (space available) // and false on failure (bag full) bool add (int value); // Removes one occurrence of the specified value from the bag. Returns // true on success (value existed) and false on failure (value did not exist) bool remove (int value); // Returns the number of times that the specified value occurs in the bag. int countOccurrences (int value) const; // Returns the number of values in the bag. int size () const { return count; } // returns the capacity of a bag. int getCapacity () const { return capacity; } // These two methods make it possible to "walk through" the values in a // bag. The values in the bag may be returned in any order. There is no // guarantee that they will be returned in numerical order, in the order in // which they were entered, or any other particular order. "startWalk" may // be called at any time. If returns true on success (value obtained) and // false on failure (bag empty). "continueWalk" may only be called if // 1/. the bag has not been modified since a walk was // begun by calling startWalk AND // 2/. the last call to startWalk or ContinueWalk returned true // If these conditions are not met, "contiinueWalk" throws a "range_error" // exception. It returns true on success (value obtained) and false on // failure (no more values). bool startWalk (int &value); bool continueWalk (int &value); // Randomly picks and returns one of the values in the bag. // Throws a range_error exception if the bag is empty. int pickRandom () const; // Overloaded assignment operator. Throws an "overflow_error" is // the destination bag is not large enough to contain all of the // values in the source bag. IntBag& operator= (const IntBag &otherBag); };