Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The key abstractions employed in this program are Inventory , Item , and ItemStack . Complete ADT implementations have been provided for the latter two.

The key abstractions employed in this program are Inventory, Item, and ItemStack. Complete ADT implementations have been provided for the latter two.

The Inventory class is partially implemented. Your task is to complete the Inventory ADT. The code provided will not run correctly until you complete all the following methods:

1.Copy Constructor

2.Destructor

3.Assignment Operator

(Note this is already provided and complete. Refer to our discussions of the copy-and-swap method.

Once you have completed the Copy Constructor and Destructor, you are done with the Big-3.)

4.Inventory::isFull - refer to documentation in Inventory.h.

5.Inventory::findMatchingItemStackNode - refer to documentation in Inventory.h.

6.Inventory::mergeStacks - refer to documentation in Inventory.h.

7.Inventory::addItemStackNoCheck - refer to documentation in Inventory.h.

The partial implementation provided assumes that each Inventory will keep track of items in a linked list. You must not change this choice of data structure unless you want a zero.

This is the code, on top of the instructions provided ,some of the comments in the code have instructions, please follow them as well.

#include  #include "Inventory.h" // Allow the compiler to define the remaining // comparison operators using namespace std::rel_ops; //------------------------------------------------------------------------------ Inventory::Node::Node() :data(Item(0, "Air"), 0) { this->next = nullptr; } //------------------------------------------------------------------------------ Inventory::Node::Node(ItemStack s) :data(s) { this->next = nullptr; } //------------------------------------------------------------------------------ Inventory::Inventory() { this->head = nullptr; this->tail = nullptr; this->slots = 10; this->occupied = 0; //std::cerr << Node().data << " "; } //------------------------------------------------------------------------------ Inventory::Inventory(int n) { this->head = nullptr; this->tail = nullptr; this->slots = n; this->occupied = 0; } //------------------------------------------------------------------------------ Inventory::Inventory(const Inventory &src) { // @todo implement this function } //------------------------------------------------------------------------------ Inventory::~Inventory() { // @todo implement this function } //------------------------------------------------------------------------------ bool Inventory::isFull() const { // @todo implement this function // // If this is more than one line // in the form "return (boolean expression);" // you are overthinking the problem return true; // This line is a placeholder. Remove it. } //------------------------------------------------------------------------------ void Inventory::display(std::ostream &outs) const { outs << " -Used " << occupied << " of " << slots << " slots" << " "; Node* it = head; while(it != nullptr){ outs << " " << it->data << " "; it = it->next; } } //------------------------------------------------------------------------------ Inventory& Inventory::operator=(Inventory rhs) { std::swap(*this, rhs); return *this; } //------------------------------------------------------------------------------ void swap(Inventory& lhs, Inventory& rhs) { using std::swap; swap(lhs.head, rhs.head); swap(lhs.tail, rhs.tail); swap(lhs.slots, rhs.slots); swap(lhs.occupied, rhs.occupied); } //------------------------------------------------------------------------------ Inventory::Node* Inventory::findMatchingItemStackNode(const ItemStack& itemStack) { // @todo implement this function return nullptr; } //------------------------------------------------------------------------------ void Inventory::mergeStacks(ItemStack& lhs, const ItemStack& rhs) { // Update lhs... remember rhs is read only } //------------------------------------------------------------------------------ void Inventory::addItemStackNoCheck(ItemStack itemStack) { // @todo implement this function }

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

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

Are these written ground rules?

Answered: 1 week ago

Question

Have ground rules been established for the team?

Answered: 1 week ago

Question

a. How are members selected to join the team?

Answered: 1 week ago