Question: Below is the class declaration for the Bag class from your text. Refer to this header file to answer a-f. //**ADT bag: Array-based implementation @file

Below is the class declaration for the Bag class from your text. Refer to this header file to answer a-f.

//**ADT bag: Array-based implementation

@file Bag.h*/

#ifndef_BAG

#define_BAG

template

class Bag

{

private:

static const int DEFAULT_BAG_SIZE=6;

ItemType Items[DEFAULT_BAG_SIZE]; //array of Bag Items

int ItemCount; //current count of BagItems

int maxItems; //max capacity of the Bag

//Returns either the index of the element in the array item that

//contains the given targer or -1, if the array does not contain

//the target

int getIndexOf(const ItemType & target) const;

public:

//construct an empty bag

Bag();

//returns number of elements in the Bag

Int getCurrentSize() const;

//returns true if Bag is empty, false otherwise

bool is Empty() const;

//adds newEntry to Bag

bool add(const ItemType & newEntry);

//removes first occurrence of anEntry from Bag

bool remove(const ItemType & anEntry);

//empties the Bag

void clear();

//returns true if Bag contains anEntry, false//otherwise

bool contains (const ITemType&anEntry) const;

//returns the number of occurrences of anEntry in the Bag

Int getFrequencyOf(const ItemType & anEntry) const;

};

//Implementation NOT shown

#endif

Complete the body of the client program below.

#include

#include

#include "Bag.h"

bool replace(Bag&b, string oldValue, string newValue);

using namespace std;

void main()

{

//A. Write a statement to declare an empty Bag of type string named myBag.

//B. Write C++ statements to add the 3 words stored in the array below to myBag.

string ary[]={'"ONE", "TWO", "THREE"};

//C. Add the C++ statements below the following code segment to determine if the input word is contained in myBag and if so remove it from myBag, otherwise output a statement telling the user that the input word is not in myBag. HINT: Call the appropriate public member function available from the Bag class (refer to .h file on prior page). You MAY NOT refer to the arry declared in part b.

void main (){

string word;

cout<<"Please enter a word to look for in myBag:*;

cin>>word;

//d. Call the client function replace to replace the string value of "ONE" with the string value "NONE". You may optionally declare additional variables before the call. Output a statement to indicate whether or not the operation was successful

//e. Write the definition of the client function below that replaces a given item (oldValue) in a given bag with another given item (new Value). The function should return a boolean value to indicate whether the replacement was successful. Remember- items in the bag are not stored in any particular order, so you do not need to be concerned with the position of newValue in the given bag

bool replace(Bag &b, string oldValue, string newValue)

{

}

//f. Write the definition of the public getFrequencyOf member function from the Bag class

/**Counts the number of times a given entry appears in bag

@param anEntry The entry to be counted

@return The number of times anEntry appears in the bag. */

template

int Bag::getFrequencyOf(const ItemType& anEntry) const

{

}

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!