Question: 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::rel_ops;
//----------------------------------------------------
Inventory::Inventory() : slots(10){}
//----------------------------------------------------
Inventory::Inventory(int n) : slots(n), allItemStacks(n){}
//----------------------------------------------------
Inventory::Inventory(const Inventory &src) : slots(src.slots), allItemStacks(src.allItemStacks){}
//----------------------------------------------------
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::const_iterator Inventory::begin() const {
return allItemStacks.begin();
}
//----------------------------------------------------
Inventory::const_iterator Inventory::end() const {
return allItemStacks.end();
}
//----------------------------------------------------
void Inventory::display(std::ostream &outs) const {
outs << "Used "<< utilizedSlots()<<" of "<< slots <<" slots
";
for (const auto &itemStack : allItemStacks){
outs <<""<< itemStack <<"
";
}
}
//----------------------------------------------------
Inventory::iterator Inventory::findMatchingItemStackIterator(const ItemStack& itemStack){
return std::find(allItemStacks.begin(), allItemStacks.end(), itemStack);
}
//----------------------------------------------------
void Inventory::addItemStackNoCheck(ItemStack itemStack){
allItemStacks.push_back(itemStack);
}
//----------------------------------------------------
Inventory& Inventory::operator=(Inventory rhs){
std::swap(*this, rhs);
return *this;
}
//----------------------------------------------------
void swap(Inventory& lhs, Inventory& rhs){
using std::swap;
swap(lhs.allItemStacks, rhs.allItemStacks);
swap(lhs.slots, rhs.slots);
}
//----------------------------------------------------
bool operator==(const Inventory& lhs, const Inventory& rhs){
if (lhs.utilizedSlots()!= rhs.utilizedSlots()){
return false;
}
if (lhs.emptySlots()!= rhs.emptySlots()){
return false;
}
for (auto lhIt = lhs.begin(), rhIt = rhs.begin(); lhIt != lhs.end() && rhIt != rhs.end(); ++lhIt, ++rhIt){
if (*lhIt !=*rhIt){
return false;
}
}
return true;
}
//----------------------------------------------------
void Inventory::mergeStacks(ItemStack& lhs, const ItemStack& rhs){
lhs.addItems(rhs.size());
}
I get
Processing Log:
Discarded (10) HP Potion
Discarded (5) MP Potion
Discarded (2) Bow Tie
Discarded (3) Dirt
Discarded (27) Iron Ore
Discarded (44) Diamond Ore
Discarded (55) Iron Ingot
Discarded (1) Diamond
Discarded (4) Diamond Block
Discarded (3) Dirt
Discarded (5) MP Potion
Discarded (4) Diamond Block
Discarded (1) Diamond
Discarded (2) Iron Ore
Item List:
0 Air

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!