Question: Here is the definition for the array based Bag class: template class ArrayBag : public Baglnterface { private: static const int DEFAULT_CAPACITY =6; ItemType items[DEFAULT_CAPACITY];

 Here is the definition for the array based Bag class: template

class ArrayBag : public Baglnterface \{ private: static const int DEFAULT_CAPACITY =6;

ItemType items[DEFAULT_CAPACITY]; // Array of bag items int itemCount; // Current count

of bag items int maxltems; // Max capacity of the bag //

Returns seither the index of the element in the array items that

// contains the given target or 1, if the array does not

Here is the definition for the array based Bag class: template class ArrayBag : public Baglnterface \{ private: static const int DEFAULT_CAPACITY =6; ItemType items[DEFAULT_CAPACITY]; // Array of bag items int itemCount; // Current count of bag items int maxltems; // Max capacity of the bag // Returns seither the index of the element in the array items that // contains the given target or 1, if the array does not contain // the target. int getIndexOf(const ItemType\& target) const; public: public: ArrayBag(); int getCurrentSize() const; bool isEmpty() const; bool add(const ItemType\& newEntry); bool remove(const ItemType\& anEntry); void clear(); bool contains(const ItemType\& anEntry) const; int getFrequencyOf(const ItemType \& anEntry) const; vector toVector() const; \}; // end ArrayBag Question 5 (10 points) Consider writing a client function (non-member function) that creates and returns a new ADT Bag object that contains all items from a given Bag object without duplicated items. The function is not allowed to modify the given Bag object. Which of the following implementations for this function is correct? a) Template void bagCopy(Bag>& aBag ) lupilcatea items. ine runction is not allowea to moary tne given bag object. vvnicn of the following implementations for this function is correct? a) Template b) Template d) Template b) Iemplate BagbagCopy(constBag&aBag) {intsize=aBag.getCurrentSize(); ItemType ItemsCopy[size]; ItemsCopy[0]=Items[0]; boolduplicated;for(inti=1;i class ArrayBag : public Baglnterface \{ private: static const int DEFAULT_CAPACITY =6; ItemType items[DEFAULT_CAPACITY]; // Array of bag items int itemCount; // Current count of bag items int maxltems; // Max capacity of the bag // Returns seither the index of the element in the array items that // contains the given target or 1, if the array does not contain // the target. int getIndexOf(const ItemType\& target) const; public: public: ArrayBag(); int getCurrentSize() const; bool isEmpty() const; bool add(const ItemType\& newEntry); bool remove(const ItemType\& anEntry); void clear(); bool contains(const ItemType\& anEntry) const; int getFrequencyOf(const ItemType \& anEntry) const; vector toVector() const; \}; // end ArrayBag Question 5 (10 points) Consider writing a client function (non-member function) that creates and returns a new ADT Bag object that contains all items from a given Bag object without duplicated items. The function is not allowed to modify the given Bag object. Which of the following implementations for this function is correct? a) Template void bagCopy(Bag>& aBag ) lupilcatea items. ine runction is not allowea to moary tne given bag object. vvnicn of the following implementations for this function is correct? a) Template b) Template d) Template b) Iemplate BagbagCopy(constBag&aBag) {intsize=aBag.getCurrentSize(); ItemType ItemsCopy[size]; ItemsCopy[0]=Items[0]; boolduplicated;for(inti=1;i

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!