Question: ---------------------------------------------------------------------------- Code for ArrayBag.cpp: #include template int ArrayBag ::getCurrentSize() const { return itemCount; } template bool ArrayBag ::isEmpty() const { return !itemCount; // itemCount ==

 ---------------------------------------------------------------------------- Code for ArrayBag.cpp: #include template int ArrayBag::getCurrentSize() const { returnitemCount; } template bool ArrayBag::isEmpty() const { return !itemCount; // itemCount ==

----------------------------------------------------------------------------

Code for ArrayBag.cpp:

#include  template  int ArrayBag::getCurrentSize() const { return itemCount; } template  bool ArrayBag::isEmpty() const { return !itemCount; // itemCount == 0; } template  bool ArrayBag::add(const ItemType& newEntry) { bool hasRoomToAdd(itemCount  bool ArrayBag::remove(const ItemType& anEntry) { int locatedIndex(getIndexOf(anEntry) ); bool canRemoveItem(locatedIndex > -1); if (canRemoveItem) { --itemCount; items[locatedIndex] = items[itemCount]; } return canRemoveItem; } template  void ArrayBag::clear() { itemCount = 0; } template  bool ArrayBag::contains(const ItemType& anEntry) const { int curIndex(0); while (curIndex  int ArrayBag::getFrequencyOf(const ItemType& anEntry) const { int frequency(0); int curIndex(0); while (curIndex  std::vector ArrayBag::toVector() const { std::vector bagContents; for (int i(0); i  int ArrayBag::getIndexOf(const ItemType& target) const { int searchIndex(0); while (searchIndex  

-----------------------------------------------------------

Code for BagInterface.h:

#ifndef BAG_INTERFACE_ #define BAG_INTERFACE_ #include  /** @class BagInterface BagInterface.h "BagInterface.h" * * BagInterface abstract base class template. */ template  class BagInterface { public: /** Virtual destructor. (See C++ Interlude 2.) */ virtual ~BagInterface() {} /** Gets the current number of entries in this bag. * * @return The integer number of entries currently in the bag. */ virtual int getCurrentSize() const = 0; /** Sees whether this bag is empty. * * @return True if the bag is empty, or false if not. */ virtual bool isEmpty() const = 0; /** Adds a new entry to this bag. * * @post If successful, newEntry is stored in the bag and the * count of items in the bag has increased by 1. * * @param newEntry The object to be added as a new entry. * * @return True if addition was successful, or false if not. */ virtual bool add(const ItemType& newEntry) = 0; /** Removes one occurrence of a given entry from this bag, if * possible. * * @post If successful, anEntry has been removed from the bag and * the count of items in the bag has decreased by 1. * * @param anEntry The value of the entry to be removed. * * @return True if removal was successful, or false if not. */ virtual bool remove(const ItemType& anEntry) = 0; /** Removes all entries from this bag. * * @post This bag contains no items (thus the count is 0). */ virtual void clear() = 0; /** Counts the number of times a given entry appears in bag. * * @param anEntry The value of the entry to be counted. * * @return The number of times anEntry appears in this bag. */ virtual int getFrequencyOf(const ItemType& anEntry) const = 0; /** Tests whether this bag contains a given entry. * * @param anEntry The value of the entry to locate. * * @return True if this bag contains anEntry, or false * otherwise. */ virtual bool contains(const ItemType& anEntry) const = 0; /** Converts this bag into a vector. * * @return A vector containing all the entries in this bag. */ virtual std::vector toVector() const = 0; }; #endif

--------------------------------------------------------------

Code for ArrayBag.h:

#ifndef ARRAY_BAG_ #define ARRAY_BAG_ #include  #include "BagInterface.h" /** @class ArrayBag ArrayBag.h "ArrayBag.h" * * Specification of an array-based ADT bag. */ template  class ArrayBag : public BagInterface { private: /** Maximum capacity of this bag. */ static const int DEFAULT_CAPACITY = 6; /** Data storage. */ ItemType items[DEFAULT_CAPACITY]; /** Number of items in this bag. */ int itemCount = 0; /** Maximum capacity of this bag. */ int maxItems = DEFAULT_CAPACITY; /** Gets the index of target in the array 'items' in this bag. * * @param target The ItemType value to retrieve the index of. * * @return The index of the element in the array 'items' that * contains 'target' or -1 if the array does not contain * 'target'. */ int getIndexOf(const ItemType& target) const; public: /** Default constructor. */ ArrayBag() = default; /** Virtual destructor. */ virtual ~ArrayBag() = default; virtual int getCurrentSize() const; virtual bool isEmpty() const; virtual bool add(const ItemType& newEntry); virtual bool remove(const ItemType& anEntry); virtual void clear(); virtual int getFrequencyOf(const ItemType& anEntry) const; virtual bool contains(const ItemType& anEntry) const; virtual std::vector toVector() const; }; #include "ArrayBag.cpp" #endif

----------------------------------------------------------------------------------------------------

Please Create a driver in c++ with edited files

 
Implement a new ADT: a "bag with receipts." You can start with the Bag Interface.h, ArrayBag.h, and ArrayBag.cpp files. These can be found on the course Web site. A "bag with receipts works like this: When an item is inserted into the bag, a unique "receipt" for the item is returned by the add operation. To remove an item from the bag, the "receipt" for that item must be passed into the remove operation. The remove operation only removes the item associated with the receipt that it receives (there is no value-based remove operation) Specification and Design The specification for the class of "bag with receipts" differs from the ADT bag provided in the text in the following ways: The add operation must return a unique integer "receipt" for each object inserted into the container. Note that when an object associated with a given receipt is removed from the container, then that receipt value can and should be reused for a subsequently added object. The remove operation takes an integer argumentthe receipt associated with the object to remove from the container. And, the remove operation must return a copy of the object that has been removed from the bag. The design for the class "bag with receipts" will require keeping track of the stored objects and their associated receipts. One approach to solving this problem is to use parallel arrays. A set of parallel arrays involve keeping two or more arrays that are the same size (i.e. same number of elements) and use the same index to access different parts of the same "object" stored in the data. As a parallel array example (note that this has nothing to do with this assignment beyond being an example of the use of a parallel array), suppose that we are storing the following data on a team of athletes: Name Height Joe 165 Rachel || 142 Tim 157 We could create parallel arrays to store this data: one array of type std::string to store the names, the other array of type un signed int to store the heights: std::string names [3]; unsigned int heights [3]; W or 'unsigned heights[3]; Then each individual athlete has their data stored at the same index across both of the parallel arrays: names [0] = "Joe"; height: [0] = 165; names [1] = "Rachel"; heights[1] = 142; names [21 - "Tim"; height: [2] = 157; The data storage that you use for your "bag with receipts" class must be array-based. You are required to design and implement a complete testing suite. The tests you design must test all aspects of the code in your "bag with receipts" class. Implementation Start by creating the directory structure to store the files and directories) for your project 2 solution. Creating Bag with Receipts Copy, rename, and edit the Bag Interface.h header file for the ADT "bag with receipts," so that it: Is cohesive (give this file and the abstract base class it contains an appropriate name). Edit the abstract base class's specifications for the class "bag with receipts." The edits will involve: 1. Editing the method prototypes to match the descriptions given above. 2. Editing all of the comments so that the file, the class, and the methods are all properly named and documented. Then copy, rename, and edit the ArrayBag.h and ArrayBag.cpp files. These files and the class they contain must be renamed so everything remains cohesive. Then edit the specifications so that they describe the ADT "bag with receipts." Hints on this process follow below. When initial files are prepared, create a git repository and add these initial files (including the CMakelists.txt file) to version control. You must use git to regularly save versions of all of your source code with appropriate messages. You will be graded on your final git log (see Turn In section below). Parallel Arrays A suggested technique (you are not required to use this approach) for implementing the ADT "bag with receipts" is to use parallel arrays. This implementation approach would use the parallel arrays. Item Type items (DEFAULT_CAPACITY); bool inUse (DEFAULT_CAPACITY); The inuse array is used to indicate which elements in the items array are currently in use. Thus, all elements in the inuse array should be initialized to false in the constructor The "receipt" for an object must be a unique integer value. The easiest value to use as the receipt is the index where that object is stored in the parallel arrays. For example, the receipt for the first item inserted will be 0 (zero) as it is inserted in the first available position in the arrays. Thus, the add operation must search the inuse array for the first available location for insertion of this new object (i.e. the first index i where inuse[i] is false). Then use this index (1) to insert the object into the container and Then return that index as the receipt. The remove operation takes a receipt an integer value) and must check if the receipt matches an index that is in use. If it is, then remove that object and return a copy of the removed object (return-by-value). Note that other ArrayBag operations may be affected by these changes in implementation. For example, suppose a user inserted four values and then removed the second one. This would create a gap in the values stored in the items array that cannot be ignored by the tovector operation. The tovector routine must use the inuse array to know which values in the items array should be put in the vector (i.e. which elements are in use). Other existing operations may require similar changes. Be sure you exercise all ADT operations in your testing. Implement a new ADT: a "bag with receipts." You can start with the Bag Interface.h, ArrayBag.h, and ArrayBag.cpp files. These can be found on the course Web site. A "bag with receipts works like this: When an item is inserted into the bag, a unique "receipt" for the item is returned by the add operation. To remove an item from the bag, the "receipt" for that item must be passed into the remove operation. The remove operation only removes the item associated with the receipt that it receives (there is no value-based remove operation) Specification and Design The specification for the class of "bag with receipts" differs from the ADT bag provided in the text in the following ways: The add operation must return a unique integer "receipt" for each object inserted into the container. Note that when an object associated with a given receipt is removed from the container, then that receipt value can and should be reused for a subsequently added object. The remove operation takes an integer argumentthe receipt associated with the object to remove from the container. And, the remove operation must return a copy of the object that has been removed from the bag. The design for the class "bag with receipts" will require keeping track of the stored objects and their associated receipts. One approach to solving this problem is to use parallel arrays. A set of parallel arrays involve keeping two or more arrays that are the same size (i.e. same number of elements) and use the same index to access different parts of the same "object" stored in the data. As a parallel array example (note that this has nothing to do with this assignment beyond being an example of the use of a parallel array), suppose that we are storing the following data on a team of athletes: Name Height Joe 165 Rachel || 142 Tim 157 We could create parallel arrays to store this data: one array of type std::string to store the names, the other array of type un signed int to store the heights: std::string names [3]; unsigned int heights [3]; W or 'unsigned heights[3]; Then each individual athlete has their data stored at the same index across both of the parallel arrays: names [0] = "Joe"; height: [0] = 165; names [1] = "Rachel"; heights[1] = 142; names [21 - "Tim"; height: [2] = 157; The data storage that you use for your "bag with receipts" class must be array-based. You are required to design and implement a complete testing suite. The tests you design must test all aspects of the code in your "bag with receipts" class. Implementation Start by creating the directory structure to store the files and directories) for your project 2 solution. Creating Bag with Receipts Copy, rename, and edit the Bag Interface.h header file for the ADT "bag with receipts," so that it: Is cohesive (give this file and the abstract base class it contains an appropriate name). Edit the abstract base class's specifications for the class "bag with receipts." The edits will involve: 1. Editing the method prototypes to match the descriptions given above. 2. Editing all of the comments so that the file, the class, and the methods are all properly named and documented. Then copy, rename, and edit the ArrayBag.h and ArrayBag.cpp files. These files and the class they contain must be renamed so everything remains cohesive. Then edit the specifications so that they describe the ADT "bag with receipts." Hints on this process follow below. When initial files are prepared, create a git repository and add these initial files (including the CMakelists.txt file) to version control. You must use git to regularly save versions of all of your source code with appropriate messages. You will be graded on your final git log (see Turn In section below). Parallel Arrays A suggested technique (you are not required to use this approach) for implementing the ADT "bag with receipts" is to use parallel arrays. This implementation approach would use the parallel arrays. Item Type items (DEFAULT_CAPACITY); bool inUse (DEFAULT_CAPACITY); The inuse array is used to indicate which elements in the items array are currently in use. Thus, all elements in the inuse array should be initialized to false in the constructor The "receipt" for an object must be a unique integer value. The easiest value to use as the receipt is the index where that object is stored in the parallel arrays. For example, the receipt for the first item inserted will be 0 (zero) as it is inserted in the first available position in the arrays. Thus, the add operation must search the inuse array for the first available location for insertion of this new object (i.e. the first index i where inuse[i] is false). Then use this index (1) to insert the object into the container and Then return that index as the receipt. The remove operation takes a receipt an integer value) and must check if the receipt matches an index that is in use. If it is, then remove that object and return a copy of the removed object (return-by-value). Note that other ArrayBag operations may be affected by these changes in implementation. For example, suppose a user inserted four values and then removed the second one. This would create a gap in the values stored in the items array that cannot be ignored by the tovector operation. The tovector routine must use the inuse array to know which values in the items array should be put in the vector (i.e. which elements are in use). Other existing operations may require similar changes. Be sure you exercise all ADT operations in your testing

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!