Question: 2 e 2 : 4 3 : 7 8 A question about the ADT Bag Here is the definition for the array based Bag class:

2
e 2:
4
3:
7
8
A question about the ADT Bag
Here is the definition for the array based Bag class:
template
class ArrayBag: public BagInterface
private:
static const int DEFAULT_ CAPACITY =6;
ItemType items[DEFAULT_CAPACITY]: I/ Array of bag items int itemCount;
// Current count of bag items
int maxltems;
// Max capacity of the bag
// Returns either 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:
ArrayBag();
int getCurrentSizel) 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<|temType > 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< ItemType>& aBag)
int size = aBag. getCurrentSizel);
for(int i=0; i1))
aBag.remove(items[i]);
}
return aBag;
b)
Template
Bag< ItemType> bagCopy(const Bag< ItemType>& aBag)
vector< ItemType> items = aBag.toVector);
Bag< ItemType> newBag;
int size = items.size);
for(int i=0; i
void bagCopy(Bag aBag)
int size = aBag. getCurrentSize;
for(int i=0; i
Bag bagCopy(const Bag& aBag)
int size = aBag. getCurrentSize);
ItemType ItemsCopy|sizel;
ItemsCopy[O]=items|0];
bool duplicated;
for(int i=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!