Question: C++ Programming Assignment - Please Help Code To Work From: ArrayBag.cpp // Created by Frank M. Carrano and Timothy M. Henry. // Copyright (c) 2017

C++ Programming Assignment - Please Help

C++ Programming Assignment - Please Help Code To Work From: ArrayBag.cpp //

Code To Work From:

ArrayBag.cpp // Created by Frank M. Carrano and Timothy M. Henry. // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey. template bool ArrayBag::add(const ItemType& newEntry) { bool hasRoomToAdd = (itemCount  ArrayBag::ArrayBag(): itemCount(0), maxItems(DEFAULT_CAPACITY) { } // end default constructor template int ArrayBag::getCurrentSize() const { return itemCount; } // end getCurrentSize template bool ArrayBag::isEmpty() const { return itemCount == 0; } // end isEmpty template std::vector ArrayBag::toVector() const { std::vector bagContents; for (int i = 0; i  bool ArrayBag::contains(const ItemType& anEntry) const { bool isFound = false; int curIndex = 0; // Current array index while (!isFound && (curIndex  void ArrayBag::clear() { itemCount = 0; } // end clear template int ArrayBag::getIndexOf(const ItemType& target) const { bool isFound = false; int result = -1; int searchIndex = 0; // If the bag is empty, itemCount is zero, so loop is skipped while (!isFound && (searchIndex  bool ArrayBag::remove(const ItemType& anEntry) { int locatedIndex = getIndexOf(anEntry); bool canRemoveItem = !isEmpty() && (locatedIndex > -1); if (canRemoveItem) { itemCount--; items[locatedIndex] = items[itemCount]; } // end if return canRemoveItem; } // end remove template int ArrayBag::getFrequencyOf(const ItemType& anEntry) const { int frequency = 0; int curIndex = 0; // Current array index while (curIndex  

ArrayBag.h

// Created by Frank M. Carrano and Timothy M. Henry. // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey. /** Header file for an array-based implementation of the ADT bag. Listing 3-1. @file ArrayBag.h */ #ifndef ARRAY_BAG_ #define ARRAY_BAG_ #include "BagInterface.h" template class ArrayBag : public BagInterface { private: static const int DEFAULT_CAPACITY = 6; // Small size to test for a full bag ItemType items[DEFAULT_CAPACITY]; // 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: ArrayBag(); int getCurrentSize() const; bool isEmpty() const; bool add(const ItemType& newEntry); bool remove(const ItemType& anEntry); void clear(); bool contains(const ItemType& anEntry) const; int getFrequencyOf(const ItemType& anEntry) const; std::vector toVector() const; }; // end ArrayBag #include "ArrayBag.cpp" #endif

BagInterface.h

// Created by Frank M. Carrano and Timothy M. Henry. // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey. /** Listing 1-1. @file BagInterface.h */ #ifndef BAG_INTERFACE_ #define BAG_INTERFACE_ #include  template class BagInterface { public: /** 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 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 Bag contains no items, and the count of items is 0. */ virtual void clear() = 0; /** Counts the number of times a given entry appears in this bag. @param anEntry The entry to be counted. @return The number of times anEntry appears in the bag. */ virtual int getFrequencyOf(const ItemType& anEntry) const = 0; /** Tests whether this bag contains a given entry. @param anEntry The entry to locate. @return True if bag contains anEntry, or false otherwise. */ virtual bool contains(const ItemType& anEntry) const = 0; /** Empties and then fills a given vector with all entries that are in this bag. @return A vector containing all the entries in the bag. */ virtual std::vector toVector() const = 0; /** Destroys this bag and frees its assigned memory. (See C++ Interlude 2.) */ virtual ~BagInterface() { } }; // end BagInterface #endif

bagtester.cpp

// Created by Frank M. Carrano and Timothy M. Henry. // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey. #include  #include  #include "ArrayBag.h" using std::cout; using std::endl; using std::string; void displayBag(ArrayBag<:string>& bag) { cout  bagItems = bag.toVector(); int numberOfEntries = (int)bagItems.size(); for (int i = 0; i & bag) { cout  bag; cout  

Assignment 4.1 [20 points] Do Programming Problem 6 at the end of chapter 3. The problem refers to Programming Problem 5 of Chapter 1, which you didn't do, but it was just writing out specifications for a "Set" ADT, which is just a slight variation on the "Bag" ADT. Your task this week is to write an "Array Set" class to implement the "Set" ADT. You don't need to write out the specifications. The vast majority of your code will be copied directly from the ArrayBag class of chapter 3. You just need to make minor adjustments to reflect the fact that duplicate elements are not allowed. (Note that you will receive 0 if your submitted code allows duplicate elements, since this is pretty much the only thing we are changing.) Also, we won't have a frequency of member function. Your ArraySet class must be derived from a "SetInterface" abstract class. There's almost no work for you to do here. Just copy the "Baginterface" class from chapter 1. None of the code in that abstract class will need to be modified, except that the frequency Of() member function will be removed. If you find the part about deriving the class from "SetInterface" confusing, be sure to ask about it in the discussion! Here is the source code from the text that you are to use as a starting point: ArrayBag.cpp ArrayBag.h BagInterface.h bagtester.cpp Assignment 4.2 [25 points] Add member functions setUnion(), set Intersection(), and setDifference(). (Don't add them to the SetInterface class -- this causes too many headaches.) These operations on sets are covered in Math 4. If you don't know what they mean, you can read about them in Exercises 6, 7, and 8 of chapter 1. The functions should all perform the operation on the Array Set calling object and the Array Set parameter and return the resulting Array Set. The setUnion() function should have an additional parameter that is set to false if the operation fails (because the size of the result exceeds the capacity of the ArraySet). Here's a snippet of client code: bool myFlag; set1 = set2.setUnion ( set 3, myFlag); if (!myFlag) { cout

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!