Hello!I need to have this assignment finished on November 4th before midnight. For this assignment we are learning about Linked Bags, Recursion, and smart pointers in C++. I was wondering if it is...

1 answer below »
Hello!I need to have this assignment finished on November 4th before midnight. For this assignment we are learning about Linked Bags, Recursion, and smart pointers in C++. I was wondering if it is possible to have a modification done for Parts B and C for the code I written. My code is generic, but the professor is really picky about any lines of code matching up to anything found online. Is it possible to do any modifications so that it doesn't match up to other solutions found?Here is some context of what Parts B and C in the assignment asked us to do:For Part B, we are to implement 8 small additional functions and 2 helper functions to the linked bag. We are given two files, called "LinkedBag340.cpp" and "Include.h" in which we put these implementations in. The descriptions of these 8 functions and helper functions that we need to add are listed in the "Assignment-03.pdf" under the Part B section. The output had to produce similar output shown in the "Asmt03_Run1.txt" and "Asmt03.Run2.txt" The difference between the outputs in Run1 and Run2, could be found under the line "--->>>>> Test 9 --->>>>>." Test 9's output must be identical to the sample outputs except for the random values. The random values in 2 sample runs' output must be different.
For Part C, a copy of Part B's solution must be made, and renamed as "PartC_SmartPointers." Then, going through all of the files in the zip file provided, not just the LinkedBag340.cpp, smart pointers should be added to places wherever it may be appropriate. The output should produce the same output as the Part B output.For further explanation, the instructions under sections Part B and Part C could be found in the "Assignment-03.pdf." I have also attached the zip file containing the work I have done for both parts.
Thanks in advance!
Answered Same DayNov 04, 2021

Answer To: Hello!I need to have this assignment finished on November 4th before midnight. For this assignment...

Aditi answered on Nov 05 2021
157 Votes
Solution/PartB/Asmt03_Run1.txt
----- LINKED BAG 340 C++-----
--->>>>> Test 1 --->>>>>
!add()... #-END 5-FIVE 4-FOUR 4-FOUR 3-THREE 2-TWO 1-ONE 0-ZERO #-BEGIN
!Display bag: #-BEGIN 0-ZERO 1-ONE 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 9 item(s) total
--->>>>> Test 2 --->>>>>
!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 7 item(s) total
!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 5 item(s) total
--->>>>> Test 3 --->>>>>
!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR
-----------> 7 item(s) total
!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 4 --->>>>>
!getCurrentSize340Iterative - Iterative...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 5 --->>>>>
!getCurrentSize340Recursive() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 6 --->>>>>
!getCurrentSize340RecursiveNoHelper() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s
) total
--->>>>> Test 7 --->>>>>
!getFrequencyOf()...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
!getFrequencyOf340Recursive() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 8 --->>>>>
!getFrequencyOf340RecursiveNoHelper() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 9 --->>>>>
!removeRandom340() ---> 4-FOUR
!removeRandom340() ---> 9-NINE
!Display bag: 4-FOUR 5-FIVE #-END #-BEGIN 4-FOUR 9-NINE 0-ZERO
-----------> 7 item(s) total
!removeRandom340() ---> #-BEGIN
!removeRandom340() ---> 4-FOUR
!Display bag: #-END 5-FIVE 4-FOUR 9-NINE 0-ZERO
-----------> 5 item(s) total
!removeRandom340() ---> 9-NINE
!removeRandom340() ---> #-END
!Display bag: 4-FOUR 5-FIVE 0-ZERO
-----------> 3 item(s) total
!removeRandom340() ---> 0-ZERO
!removeRandom340() ---> 5-FIVE
!Display bag: 4-FOUR
-----------> 1 item(s) total
Solution/PartB/Asmt03_Run2.txt
----- LINKED BAG 340 C++-----
--->>>>> Test 1 --->>>>>
!add()... #-END 5-FIVE 4-FOUR 4-FOUR 3-THREE 2-TWO 1-ONE 0-ZERO #-BEGIN
!Display bag: #-BEGIN 0-ZERO 1-ONE 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 9 item(s) total
--->>>>> Test 2 --->>>>>
!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 2-TWO 3-THREE 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 7 item(s) total
!removeSecondNode340()...
!removeSecondNode340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END
-----------> 5 item(s) total
--->>>>> Test 3 --->>>>>
!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR
-----------> 7 item(s) total
!addEnd340()...
!addEnd340()...
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 4 --->>>>>
!getCurrentSize340Iterative - Iterative...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 5 --->>>>>
!getCurrentSize340Recursive() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 6 --->>>>>
!getCurrentSize340RecursiveNoHelper() - Recursive...
---> Current size: 9
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 7 --->>>>>
!getFrequencyOf()...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
!getFrequencyOf340Recursive() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 8 --->>>>>
!getFrequencyOf340RecursiveNoHelper() - Recursive...
---> 0-ZERO: 1
---> 1-ONE: 0
---> 2-TWO: 0
---> 4-FOUR: 3
---> 9-NINE: 2
!Display bag: #-BEGIN 4-FOUR 4-FOUR 5-FIVE #-END 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 9 item(s) total
--->>>>> Test 9 --->>>>>
!removeRandom340() ---> #-END
!removeRandom340() ---> 4-FOUR
!Display bag: 4-FOUR 5-FIVE #-BEGIN 9-NINE 4-FOUR 9-NINE 0-ZERO
-----------> 7 item(s) total
!removeRandom340() ---> 4-FOUR
!removeRandom340() ---> 9-NINE
!Display bag: #-BEGIN 5-FIVE 4-FOUR 9-NINE 0-ZERO
-----------> 5 item(s) total
!removeRandom340() ---> 5-FIVE
!removeRandom340() ---> #-BEGIN
!Display bag: 4-FOUR 9-NINE 0-ZERO
-----------> 3 item(s) total
!removeRandom340() ---> 9-NINE
!removeRandom340() ---> 4-FOUR
!Display bag: 0-ZERO
-----------> 1 item(s) total
Solution/PartB/BagInterface.h
// BagInterface.h
//  Created by Frank M. Carrano and Timothy M. Henry.
// Updated by Duc Ta
//  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
#pragma once
#include
//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//
template
class BagInterface {
public:
    /*--------------------------CSC340------------------------------*/
    // Remove the second node
    virtual bool removeSecondNode340() = 0;
    // Add a node to the end of the linked list
    virtual bool addEnd340(const ItemType&) = 0;
    // getCurrentSize() - Iterative
    virtual int getCurrentSize340Iterative() const = 0;
    // getCurrentSize() - Recursive
    virtual int getCurrentSize340Recursive() const = 0;
    // getCurrentSize() - Recursive
    virtual int getCurrentSize340RecursiveNoHelper() const = 0;
    // getFrequencyOf340Recursive() - Recursive
    virtual int getFrequencyOf340Recursive(const ItemType&) const = 0;
    // getFrequencyOf340Recursive() - Recursive
    virtual int getFrequencyOf340RecursiveNoHelper(const ItemType&) const = 0;
    // Remove a random node
    virtual ItemType removeRandom340() = 0;
    /*--------------------------------------------------------------*/
// Gets the current number of entries in this bag.
    virtual int getCurrentSize() const = 0;
    // Sees whether this bag is empty.
    virtual bool isEmpty() const = 0;
    // Adds a new entry to this bag.
    virtual bool add(const ItemType&) = 0;
    // Removes one occurrence of a given entry from this bag, if possible.
    virtual bool remove(const ItemType&) = 0;
    // Removes all entries from this bag.
    virtual void clear() = 0;
    // Counts the number of times a given entry appears in bag.
    virtual int getFrequencyOf(const ItemType&) const = 0;
    // Tests whether this bag contains a given entry.
    virtual bool contains(const ItemType&) const = 0;
    // Empties and then fills a given vector with all entries that are in this bag.
    virtual std::vector toVector() const = 0;
    // Destroys object and frees memory allocated by object.
    virtual ~BagInterface() { }
}; // end BagInterface
Solution/PartB/Include.h
//    Include.h
#pragma once
#include "Node.cpp"
#include "BagInterface.h"
#include
using namespace std;
template
class LinkedBag : public BagInterface {
/*--------------------------CSC340-------------------------------------*/
public:
    bool removeSecondNode340();
    bool addEnd340(const ItemType&);
    int getCurrentSize340Iterative() const;
    int getCurrentSize340Recursive() const;
    int getCurrentSize340RecursiveNoHelper() const;
    int getFrequencyOf340Recursive(const ItemType&) const;
    int getFrequencyOf340RecursiveNoHelper(const ItemType&) const;
    ItemType removeRandom340();
    
private:
    int getCurrentSize340RecursiveHelper(Node*) const; // if needed
    int getFrequencyOf340RecursiveHelper(Node*, const ItemType&) const; // if needed
/*----------------------------------------------------------------------*/
public:
    LinkedBag();
    LinkedBag(const LinkedBag&);
    virtual ~LinkedBag();
    int getCurrentSize() const;
    bool isEmpty() const;
    bool add(const ItemType&);
    bool remove(const ItemType&);
    void clear();
    bool contains(const ItemType&) const;
    int getFrequencyOf(const ItemType&) const;
    std::vector toVector() const;
private:
    Node* headPtr{ nullptr }; // Pointer to first node
    int itemCount{ 0 };                    // Current count of bag items
    // pointer to the node or the null pointer
    Node* getPointerTo(const ItemType&) const;
};
Solution/PartB/LinkedBag.cpp
Solution/PartB/LinkedBag.cpp
//  LinkedBag.cpp
//  Created by Frank M. Carrano and Timothy M. Henry.
//  Updated by Duc Ta
//  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
#include 
#include "Node.h"
#include "LinkedBag.h"
//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//
template
LinkedBag::LinkedBag() : headPtr(nullptr), itemCount(0) {}
template
LinkedBag::LinkedBag(const LinkedBag& aBag) {
    itemCount = aBag.itemCount;
    Node* origChainPtr = aBag.headPtr;
    if (origChainPtr == nullptr) {
        headPtr = nullptr; 
    }
    else {
        headPtr = new Node();
        headPtr->setItem(origChainPtr->getItem());
        Node* newChainPtr = headPtr; 
        origChainPtr = origChainPtr->getNext();
        while (origChainPtr != nullptr)
        {
            ItemType nextItem = origChainPtr->getItem();
            Node* newNodePtr = new Node(nextItem);
            newChainPtr->setNext(newNodePtr);
            newChainPtr = newChainPtr->getNext();
            origChainPtr = origChainPtr->getNext();
        } 
        newChainPtr->setNext(nullptr);
    }
}
template
LinkedBag::~LinkedBag() {
    clear();

template
bool LinkedBag::isEmpty() const {
    return itemCount == 0;
}
template
int LinkedBag::getCurrentSize() const {
    return itemCount;
}
template
bool LinkedBag::add(const ItemType& newEntry) {
    Node* nextNodePtr = new Node();
    nextNodePtr->setItem(newEntry);
    nextNodePtr->setNext(headPtr);
    headPtr = nextNodePtr;
    itemCount++;
    return true;
}
template
std::vector LinkedBag::toVector() const {
    std::vector bagContents;
    Node* curPtr = headPtr;
    int counter = 0;
    while ((curPtr != nullptr) && (counter < itemCount)) {
        bagContents.push_back(curPtr->getItem());
        curPtr = curPtr->getNext();
        counter++;
    }
    return bagContents;
}
template
bool LinkedBag::remove(const ItemType& anEntry) {
    Node* entryNodePtr = getPointerTo(anEntry);
    bool canRemoveItem = !isEmpty() && (entryNodePtr != nullptr);
    if (canRemoveItem) {
        entryNodePtr->setItem(headPtr->getItem());
        Node* nodeToDeletePtr = headPtr;
        headPtr = headPtr->getNext();
        nodeToDeletePtr->setNext(nullptr);
        delete nodeToDeletePtr;
        nodeToDeletePtr = nullptr;
        itemCount--;
    }
    return canRemoveItem;
}
template
void LinkedBag::clear() {
    Node* nodeToDeletePtr = headPtr;
    while (headPtr != nullptr) {
        headPtr = headPtr->getNext();
        nodeToDeletePtr->setNext(nullptr);
        delete nodeToDeletePtr;
        nodeToDeletePtr = headPtr;
    }
    itemCount = 0;

template
int LinkedBag::getFrequencyOf(const ItemType& anEntry) const {
    int frequency = 0;
    int counter = 0;
    Node* curPtr = headPtr;
    while ((curPtr != nullptr) && (counter < itemCount)) {
        if (anEntry == curPtr->getItem()) {
            frequency++;
        } 
        counter++;
        curPtr = curPtr->getNext();
    }
    return frequency;
}
template
bool LinkedBag::contains(const ItemType& anEntry) const {
    return (getPointerTo(anEntry) != nullptr);
}
template
Node* LinkedBag::getPointerTo(const ItemType& anEntry) const {
    bool found = false;
    Node* curPtr = headPtr;
    while (!found && (curPtr != nullptr)) {
        if (anEntry == curPtr->getItem()) {
            found = true;
        }
        else {
            curPtr = curPtr->getNext();
        }
    }
    return curPtr;

Solution/PartB/LinkedBag.h
// LinkedBag.h
//  Created by Frank M. Carrano and Timothy M. Henry.
// Updated by Duc Ta
//  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
#pragma once
#include "Node.cpp"
#include "BagInterface.h"
//
//
// PLEASE DO NOT CHANGE THIS FILE
//
//
template
class LinkedBag : public BagInterface {
/*--------------------------CSC340-------------------------------------*/
public:
    bool removeSecondNode340();
    bool addEnd340(const ItemType&);
    int getCurrentSize340Iterative() const;
    int getCurrentSize340Recursive() const;
    int getCurrentSize340RecursiveNoHelper() const;
    int getFrequencyOf340Recursive(const ItemType&) const;
    int getFrequencyOf340RecursiveNoHelper(const ItemType&) const;
    ItemType removeRandom340();
private:
    int getCurrentSize340RecursiveHelper(Node*) const; // if needed
    int getFrequencyOf340RecursiveHelper(Node*, const ItemType&) const; // if needed
/*----------------------------------------------------------------------*/
public:
    LinkedBag();
    LinkedBag(const LinkedBag&);
    virtual ~LinkedBag();
    int getCurrentSize() const;
    bool isEmpty() const;
    bool add(const ItemType&);
    bool remove(const ItemType&);
    void clear();
    bool contains(const ItemType&) const;
    int getFrequencyOf(const ItemType&) const;
    std::vector toVector() const;
private:
    Node* headPtr{ nullptr }; // Pointer to first node
    int itemCount{ 0 };                    // Current count of bag items
    // pointer to the node or the null pointer
    Node* getPointerTo(const ItemType&)...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here