Question: Below is the class declaration for the Bag class from your text. Refer to this header file to answer parts a - e. /** ADT
Below is the class declaration for the Bag class from your text. Refer to this header file to answer parts a - e.
/** ADT bag: Array-based implementation.
@file Bag.h */
#ifndef _BAG
#define _BAG
templateItemType>
class Bag
{
private:
static const int DEFAULT_BAG_SIZE = 6;
ItemType items[DEFAULT_BAG_SIZE];// array of Bag items
int itemCount;// current count of Bag items
int maxItems;// 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:
//construct an empty bag
Bag( );
//returns number of elements in the Bag
int getCurrentSize( ) const;
//returns true if Bag is empty, false otherwise
bool isEmpty( ) 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
//Write the missingclient codefor parts a - e as indicated below:
#include
#include
#include "Bag.h"
bool replace(Bag
using namespace std;
void main( )
{
// a.Write a statement to declare an empty Bag of type string namedyourBag.
// b.Write C++ statements to add the 6 words stored in the array below to yourBag.
char ary[ ]={"ONE","TWO","THREE", "FOUR", "FIVE", "SIX"};
// c. Write the C++ statements that should follow the code segment below to determine if the input letter is contained in yourBag and if so remove it from yourBag, otherwise output a statement telling the user that the input letter is not in yourBag.HINT:Call the appropriate public member functions available from the Bag class (refer to .h file above).
string word;
cout<<"Please enter a word to look for in yourBag:";
cin >> word;
// d. Write the definition of theclient function belowthat replaces a given item (itemToReplace) in a given bag with another given item (replacementItem). 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!
Note:This function is in main. It is NOT amemberof the Bag class.
bool replace(Bag
{
// e.Write C++client codeto call the replace function to replacethe string value of "ONE" with the string value "NONE" inyourBag.Write an output a statement to indicate whether or not the operation was successful.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
