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 Inventory class

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:
Copy Constructor
Destructor
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.
Inventory::isFull - refer to documentation in Inventory.h.
Inventory::findMatchingItemStackNode - refer to documentation in Inventory.h.
Inventory::mergeStacks - refer to documentation in Inventory.h.
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.
#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#ifndef INVENTORY_H_INCLUDED
#define INVENTORY_H_INCLUDED
#include
#include "ItemStack.h"
/**
* An Inventory is composed of n slots. Each slot may store only
* one type of item--specified by *slots*.
*
* Once all slots are filled, no additional Item types may be
* stored. Individual slots may contain any number of the same
* Item.

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

More Books

Students also viewed these Databases questions

Question

2. Are you varying your pitch (to avoid being monotonous)?

Answered: 1 week ago

Question

3. Are you varying your speaking rate and volume?

Answered: 1 week ago