Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Below is the class dcclaration for the Bag class from your text. Refer to this header file to answer parts a and b. /**

image text in transcribedimage text in transcribedimage text in transcribed

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 1) Add a constructor to the Bag class that creates a bag from a given array of entries. 2) /NWrite the constructor protoype (declaration) that should be added to the header file Bag.h. 3) Wrtite the complete definition of the new constructor that should be added to implementation file I/Bag.cpp. //THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER // Method to replace() //THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER bool relpace(int x,int location, int *bag[]) // THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER int i=0; // THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER while(i 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 1) Add a constructor to the Bag class that creates a bag from a given array of entries. 2) /NWrite the constructor protoype (declaration) that should be added to the header file Bag.h. 3) Wrtite the complete definition of the new constructor that should be added to implementation file I/Bag.cpp. //THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER // Method to replace() //THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER bool relpace(int x,int location, int *bag[]) // THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER int i=0; // THIS IS NOT ACCEPTED, PLEASE DO IT WITHOUT POINTER while(i

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

How To Build A Million Dollar Database

Authors: Michelle Bergquist

1st Edition

0615246842, 978-0615246840

More Books

Students also viewed these Databases questions