Answered step by step
Verified Expert Solution
Question
1 Approved Answer
One of the most important skills in our craft is interpreting error messages. Remember the ones you receive when you attempt to compile and run
One of the most important skills in our craft is interpreting error messages. Remember the ones you receive when you attempt to compile and run the unmodified code.
The key abstractions employed in this program are Item, ItemStack, and Inventory. Complete ADT implementations have been provided for Item and Inventory.
A partial implementation has been provided for the ItemStack. Your task is to finish the update ItemStack ADT.
This assignment is smaller than the previous two in terms of code and number of new concepts Most of your time will be spent reviewing the basics of pointers. Spend the time reviewing. Practice with pointers. You will need to use pointers in one form or another for the reminder of the semester.
You must implement the:
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, Destructor, and swap you are done with the Big
Logical Equivalence ie operator
LessThan ie operator
swap
Refer to the comments in each function for additional detail.
#include
#include "ItemStack.h
const Item ItemStack::DEFAULTITEM "Air";
ItemStack::ItemStack
:ItemStackDEFAULTITEM,
ItemStack::ItemStackconst Item& inputItem, int s
:quantitys
Create a copy clone of inputItem and reference it with the thisitem
pointer
thisitem inputItem.clone;
ItemStack::ItemStackconst ItemStack& src
Create a copy clone of srcitem and reference it with the
thisitem pointer.
Do not forget to copy srcquantity.
ItemStack::~ItemStack
Every pointer must be deleted to prevent memory leaks item is a pointer
ItemStack& ItemStack::operatorItemStack rhs
swapthis rhs;
return this;
Item ItemStack::getItem const
return thisitem;
int ItemStack::size const
return thisquantity;
void ItemStack::addItemsint a
thisquantity a;
void ItemStack::addItemsFromconst ItemStack& other
thisquantity other.quantity;
bool ItemStack::operatorconst ItemStack& rhs const
Compare this and rhs for equivalence based on the ids of thisitem and
rhsitem.
return false; replace this line
bool ItemStack::operatorconst ItemStack& rhs const
Order sort this and rhs based on the ids of thisitem and rhsitem.
return false; replace this line
void ItemStack::displaystd::ostream& outs const
outs std::right std::setw thissize
thisgetItemgetName;
void swapItemStack& lhs ItemStack& rhs
Swap the item data members and quantity data members for lhs and rhs
#ifndef ITEMSTACKHINCLUDED
#define ITEMSTACKHINCLUDED
#include
#include "Item.h
using namespace std::relops;
A Homogeneousie uniformstack of Items.
class ItemStack
private:
Default Air item with id
static const Item DEFAULTITEM;
Item out of which the stack is composed.
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