Answered step by step
Verified Expert Solution
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 copyandswap method.
Once you have completed the Copy Constructor and Destructor, you are done with the Big
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::relops;
Inventory::Node::Node
:dataItem "Air"
thisnext nullptr;
Inventory::Node::NodeItemStack s
:datas
thisnext nullptr;
Inventory::Inventory
thishead nullptr;
thistail nullptr;
thisslots ;
thisoccupied ;
std::cerr Nodedata
;
Inventory::Inventoryint n
thishead nullptr;
thistail nullptr;
thisslots n;
thisoccupied ;
Inventory::Inventoryconst 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::displaystd::ostream &outs const
outs Used occupied of slots slots"
;
Node it head;
whileit nullptr
outs itdata
;
it itnext;
Inventory& Inventory::operatorInventory rhs
std::swapthis rhs;
return this;
void swapInventory& lhs Inventory& rhs
using std::swap;
swaplhshead, rhshead;
swaplhstail, rhstail;
swaplhsslots, rhsslots;
swaplhsoccupied, rhsoccupied;
Inventory::Node Inventory::findMatchingItemStackNodeconst ItemStack& itemStack
@todo implement this function
return nullptr;
void Inventory::mergeStacksItemStack& lhs const ItemStack& rhs
Update lhs remember rhs is read only
void Inventory::addItemStackNoCheckItemStack itemStack
@todo implement this function#ifndef INVENTORYHINCLUDED
#define INVENTORYHINCLUDED
#include
#include "ItemStack.h
An Inventory is composed of n slots. Each slot may store only
one type of itemspecified by slots
Once all slots are filled, no additional Item types may be
stored. Individual slots may contain any number of the same
Item.
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started