Question
One of the most important skills in our craft is interpreting error messages. Remember the ones you receive when you attempt to compile the unmodified
One of the most important skills in our craft is interpreting error messages. Remember the ones you receive when you attempt to compile the unmodified code.
The key abstractions employed in this program are Item, ItemStack, and Inventory. Can you finish ADT implementations have been provided for the former two. A partial implementation has been provided for the Inventory. Your task is to finish the Inventory.
You can implement the Copy Constructor, findMatchingItemStack, and display with loops.
You can, alternatively, use the built-in C++ functions discussed in Review 03 Example 5 (if you like a challenge).
You must implement:
Copy Constructor
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, you are done with the Big-3.
Inventory::isFull - refer to documentation in Inventory.h.
Inventory::findMatchingItemStackIterator - refer to documentation in Inventory.h.
Inventory::addItemStackNoCheck - refer to documentation in Inventory.h.
Inventory::mergeStacks - refer to documentation in ItemStack.h.
Inventory::display. This must generate the Inventory summary.
Note there is no formatting applied with setw. All spacing consists of hard-coded spaces.
Employ your Head-to-Head Testing Skills from CS 250.
inventory.cpp
inventory.h
\#include \#include "Inventory.h" // Allow the compiler to define the remaining // comparison operators using namespace std::rel_ops; Inventory: : Inventory() :I Inventory (10) \{ \} Inventory: : Inventory (int n ) \{ this-slots =n; // this->allitemstacks.reserve (n); // only works for std::vector \} Inventory: : Inventory(const Inventory\& sre) \{ // @todo - implement this function \} Inventory: : Inventory() \{ // Done! Be able to explain why. \} I i \{ int Inventory:: utilizedSlots() const return allitemstacks.size(); \} int Inventory::emptyslots() const \{ \#include \#include "Inventory.h" /I Allow the compiler to define the remaining // comparison operators using namespace std::rel_ops; I Inventory:: Inventory() :Inventory (10) \} I I Inventory: : Inventory (int n ) this >s lots =n; // this->allitemstacks.reserve (n); // only works for std: :vector \} I I \{ Inventory:: Inventory (const Inventory\& src) II Catodo - implement this function //Pointing head and tail to nullptr this > head = nullptr; this > tail = nullptr; //copying the no. of slots from the other this 5 lots = src.slots; this->occupied =0; //Copying the data from sre for ( Node *it = src. head; it = nullptr; it=1t>next) \{ this->additems ( it->data ); \} \} Inventory: : Inventory() \{ // Done! Be able to explain why. //A new node with the data item Stack is added and the number of occupied slots are increased by 1. this->next=Node(itemstack); this->occupied=this->occupied +1; \} Inventory\& Inventory: : operator = (Inventory rhs) \{ std:: swap(*this, rhs); return *this; \} / vo I void swap (Inventory\& lhs, Inventory\& rhs) using std:: swap; Swap (1hs.allitemstacks, rhs.allitemstacks); swap(1hs.slots, rhs.slots); \} bc b f bool operator = (const Inventory\& lhs, const Inventory\& rhs) if (lhs.utilizedSlots() != rhs.utilizedSlots()) \{ 3 if \} return false; I/ The two Inventory objects have the same number of used \& unused slots using const_iterator = Inventory: iconst_iterator; const_iterator IhsIt = lhs , begin (); const_iterator rhsIt = rhs, begin () ; while (lhsit 1= lhs.end ( ) \&\& rhsit I= rhs.end () ) \{ if ( lhsIt != rhsIt) \{ return false; \}Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started