Question: 2 e 2 : 4 3 : 7 8 A question about the ADT Bag Here is the definition for the array based Bag class:
e :
:
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 ;
ItemType itemsDEFAULTCAPACITY: 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 if the array does not contain
the target.
int getIndexOfconst ItemType& target const;
public:
ArrayBag;
int getCurrentSizel const; bool isEmpty const;
bool addconst ItemType& newEntry; bool removeconst ItemType& anEntry;
void clear:
bool containsconst ItemType& anEntry const; int getFrequencyOfconst ItemType& anEntry const; vectortemType toVector const;
; end ArrayBag
Question points
Consider writing a client function nonmember 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 bagCopyBag ItemType& aBag
int size aBag. getCurrentSizel;
forint i; i
aBag.removeitemsi;
return aBag;
b
Template
Bag ItemType bagCopyconst Bag ItemType& aBag
vector ItemType items aBag.toVector;
Bag ItemType newBag;
int size items.size;
forint i; i
void bagCopyBag aBag
int size aBag. getCurrentSize;
forint i; i
Bag bagCopyconst Bag& aBag
int size aBag. getCurrentSize;
ItemType ItemsCopysizel;
ItemsCopyOitems;
bool duplicated;
forint i; i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
