Answered step by step
Verified Expert Solution
Link Copied!

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 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. Complete 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.
Please only make changes in inventory.cpp
#include
#include
#include "Inventory.h"
// Allow the compiler to define the remaining
// comparison operators
using namespace std::rel_ops;
//------------------------------------------------------------------------------
Inventory::Inventory()
:Inventory(10)
{
}
//------------------------------------------------------------------------------
Inventory::Inventory(int n)
{
this->slots = n;
// this->allItemStacks.reserve(n); // only works for std::vector
}
//------------------------------------------------------------------------------
Inventory::Inventory(const Inventory& src)
{
// @todo - implement this function
}
//------------------------------------------------------------------------------
Inventory::~Inventory()
{
// Done! Be able to explain why.
}
//------------------------------------------------------------------------------
int Inventory::utilizedSlots() const
{
return allItemStacks.size();
}
//------------------------------------------------------------------------------
int Inventory::emptySlots() const
{
return slots - utilizedSlots();
}
//------------------------------------------------------------------------------
int Inventory::totalSlots() const
{
return slots;
}
//------------------------------------------------------------------------------
bool Inventory::isFull() const
{
// @todo - implement this function
return false; // replace this line
}
//------------------------------------------------------------------------------
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" <<"
";
// @todo - implement the rest of function
//
//2 spaces "" before each ItemStack line
}
//------------------------------------------------------------------------------
Inventory::iterator Inventory::findMatchingItemStackIterator(const ItemStack& itemStack)
{
// @todo - implement this function
return allItemStacks.end();
}
//----------------------------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago