Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone help me with this code. #include #include #include Inventory.h / / Allow the compiler to define the remaining / / comparison operators
Can someone help me with this code.
#include
#include
#include "Inventory.h
Allow the compiler to define the remaining
comparison operators
using namespace std::relops;
Inventory::Inventory : slots
Inventory::Inventoryint n : slotsn allItemStacksn
Inventory::Inventoryconst Inventory &src : slotssrcslots allItemStackssrcallItemStacks
Inventory::~Inventory
int Inventory::utilizedSlots const
return allItemStacks.size;
int Inventory::emptySlots const
return slots utilizedSlots;
int Inventory::totalSlots const
return slots;
bool Inventory::isFull const
return utilizedSlots slots;
Inventory::iterator Inventory::begin
return allItemStacks.begin;
Inventory::iterator Inventory::end
return allItemStacks.end;
Inventory::constiterator Inventory::begin const
return allItemStacks.begin;
Inventory::constiterator Inventory::end const
return allItemStacks.end;
void Inventory::displaystd::ostream &outs const
outs "Used utilizedSlots of slots slots
;
for const auto &itemStack : allItemStacks
outs itemStack
;
Inventory::iterator Inventory::findMatchingItemStackIteratorconst ItemStack& itemStack
return std::findallItemStacksbegin allItemStacks.end itemStack;
void Inventory::addItemStackNoCheckItemStack itemStack
allItemStacks.pushbackitemStack;
Inventory& Inventory::operatorInventory rhs
std::swapthis rhs;
return this;
void swapInventory& lhs Inventory& rhs
using std::swap;
swaplhsallItemStacks, rhsallItemStacks;
swaplhsslots, rhsslots;
bool operatorconst Inventory& lhs const Inventory& rhs
if lhsutilizedSlots rhsutilizedSlots
return false;
if lhsemptySlots rhsemptySlots
return false;
for auto lhIt lhsbegin rhIt rhsbegin; lhIt lhsend && rhIt rhsend; lhIt, rhIt
if lhIt rhIt
return false;
return true;
void Inventory::mergeStacksItemStack& lhs const ItemStack& rhs
lhsaddItemsrhssize;
I get
Processing Log:
Discarded HP Potion
Discarded MP Potion
Discarded Bow Tie
Discarded Dirt
Discarded Iron Ore
Discarded Diamond Ore
Discarded Iron Ingot
Discarded Diamond
Discarded Diamond Block
Discarded Dirt
Discarded MP Potion
Discarded Diamond Block
Discarded Diamond
Discarded Iron Ore
Item List:
Air
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started