class IntBag { /* Marking Notes: - no half marks. - deduct one mark from total if any of the 3 methods is not well commented in the header file. - deduct one mark from total if the methods are not well commented in the implementation file. Constructor (3 marks): - 1 mark for quitting properly (all three of the following required): - logic must be correct - IntBag **must** be properly initialized before quitting - i.e. count=0; walkInProgress=false; either directly or by using default constructor - message format must be correct: "IntBag::IntBag some reasonable message" - 2 marks for setting up the IntBag properly: - 1 mark for count and walkInProgress - 1 mark for data Method Returning an IntBag (5 marks): - 1 mark for signature: - method must be "const" - 1 mark for declarations / initializations - 2 marks for loop - must use startWalk/continueWalk and add or remove - i.e. if "data" is used directly: 0/2 for this part - 1 mark for returning the IntBag created Overloading Operator (2 marks): - 1 mark for signature: - signature *must* be exactly correct, i.e. 2 consts and 1 & - 1 mark for logic: - logic *must* be exactly correct - instead of comparing counts directly, student can also use method size() */ private: enum { MAXVALUES = 10 }; int data [MAXVALUES]; int count; // number of values currently in the bag bool walkInProgress; int walkPosition; // position of last value returned public: // constructs an empty bag. // for really trivial constructors and methods, the complete // implementation is often placed directly in the class definition. IntBag () { count = 0; walkInProgress = false; } // constructs a bag having "value" copies of "value". // Quits if value is negative or higher than MAXVALUES. IntBag (int value); // returns an IntBag with at most two copies of every different element // of the bag. If an element occurs once in the bag, it will occur once // in the result. If it occurs twice or more in the bag, it will occur // exactly twice in the result. IntBag maxTwice() const; // bag is less than other bag if it has fewer elements bool operator<(const IntBag &otherBag) const; // 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; } // 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, "continueWalk" quits. // 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. // quits if the bag is empty. int pickRandom () const; };