Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Write the definition of the client function below that replaces a given item (item ToReplace) in a given bag with another given item (replacementitem).

image text in transcribedimage text in transcribed

 
// Write the definition of the client function below that replaces a given item (item ToReplace) 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 concemed with the position of new Value in the given bag! 1) boot replace(Bag&b, string itemToReplace, string replacementitem) 2) Il Write C++ client code to call the replace function to replace the string value of "ONE" with the string value "NONE" in yourBag. Write an output a statement to indicate whether or not the operation was successful. 2. Below is the class dcclaration for the Bag class from your text. Refer to this header file to answer parts a and b. /** ADT bag: Array-based implementation. @file Bag.h 7 #ifndef _BAG #define _BAG template class Bag private: static const int DEFAULT_BAG_SIZE = 6; Item Type items (DEFAULT_BAG_SIZE); Il array of Bag items int itemCount; Il current count of Bag items int maxitems; Il max capacity of the Bag // Returns either the index of the element in the array items that Il contains the given target or -1, if the array does not contain // the target. int getindexOf(const Item Type& target) const; public: l/construct an empty bag Bag(); //returns number of elements in the Bag int getCurrent Sizel ) const; //returns true if Bag is empty, false otherwise bool isEmpty() const; // adds newEntry to Bag bool add(const Item Type& newEntry); //removes first occurrence of anEntry from Bag bool remove(const Item Type& anEntry); Il empties the Bag void clear(); l/returns true if Bag contains anEntry, false otherwise bool contains(const Item Type& anEntry) const: Il returns the number of occurrences of anEntry in the Bag int getFrequency Of(const Item Type & an Entry) const; Il implementation NOT shown Meridif

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Next Generation Databases NoSQLand Big Data

Authors: Guy Harrison

1st Edition

1484213300, 978-1484213308

More Books

Students also viewed these Databases questions