Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Could you provide help and an explanation for this question and code I believe that only itemstack.cpp needs to be updated using info from other
Could you provide help and an explanation for this question and code I believe that only itemstack.cpp needs to be updated using info from other samples code was copypasted from java vcs.
4 Your Tasks 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, Itenstack, and Inventory. Complete ADT implementations have been provided for Iten and Inventory. A partial implementation has been provided for the Itenstack. Your task is to finish the update Itenstack ADT. You must implement the: This assignment is smaller than the previous two (in terms of code 1. Copy Constructor and number of new concepts). Most of your time will be spent 2. Destructor reviewing the basics of pointers. Spend the time reviewing. 3. Assignment Operator Practice with pointers. You will need to use pointers (in one form - Once you have completed the Copy Constuctor, Deatructor, and swap you are done with the Big-3. 4. Logical Equivalence (i.e., operator = ) . 5. Less-Than (i.e., operator ). 6. swap Refer to the comments in each function for additional detail. Employ your Head-to-Head Testing Skills from CS 250. 4.1 Three Main Functions? As you look through the provided code, you will find three main functions: one in storage.cpp (as expected), one in Testinventory.cpp, and one in TestItems tack.cpp. If you are creating a project in your IDE do not include both in your project settings. You will need to either create multiple targets in your project settings, or rely on the makefile. You should probably run the tests on a Linux machine... You can compile the main program (storage) and test drivers (testInventory and testItemStack) with make You can then run storage as described above. You can run the Inventory and Itenstack test drivers with- Take note of the semicolon (;) after testinventory. This is a standard Linux trick to run two commands back-to-back. ./testinventory; ./testitenstack PASSED testaddItenStackNoCheck PASSED testAddIteriWithDuplicateItens PASSED testAddItenAfterFul1 PASSED testCopyConstructorFor Enpty PASSED testCopyConstructor PASSED testASSignnentoperator PASSED testDisplay Itemstack: PASSED testDefaultconstructor PASSED testsecondConstructor PASSED testCopyConstructor PASSED testassignnent. PASSED testaddItens PASSED testAddItensFron PASSED testLogicalEquivalence PASSED testlessThan PASSED testDisplay PASSED testSwap If you see FAIL.ED you must revisit revisit the corresponding function(s). There is a mistake somewhere in your code. Where should you look? Pay close attention to the line immediately before FAILED... use that as a starting point. Remember to ask questions if you get stuck. 4.1.1 Segmentation Faults \& Getting Started Since Itemstack's item data member is a pointer Item* iten; segmentation faults are a consideration. If you donnload, compile and run the tests, without implementing anything, you will receive test output similar to: Inventory: PASSED testDefaultConstructor PASSED testConstructorSizeN [1] 21524 segmentation fault (core dunped) ./testinventory Itemstack: [1] 21526 segnentation fault (core dunped) ./testitenstack Here is a free hint. Go to the Copy Constructor and add this->item = src.item->clone(); This line will create a deep copy of src.iten. Once you have made that one-line addition, recompile everything and run ./testinventory; ./testitenstack again. You should see: Inventory: PASSED testDefaultconstructor PASSED testConstructorSizeN FAILURE: testaddItenstackNoCheck:89 ((1it+)==stacksToAdd[]) FAILED testaddItenStackNoCheck FAILURE: testaddIterlWithDuplicateItens:126 ((1it+)== stacksTaAdd[]) FAILED testaddIteriWi thDuplicateItens FAILURE: testaddItenAfterFu11:172 ((it++)== stacksTaAdd[ ] ] ) FAILED testAddItenAfterFFull PASSED testCopyConstructorFor Enpty FAILURE: testCopyConstructor:268 (aCopy == source) FAILED testCopyConstructor FAILURE: testassignnentoperator: 395 (acopy = source) FAILED testassignnentoperator FAILURE: testDisplay:204 (bagstring.find(stacksasstrings[0]) ! std::string:tnpos) FAILED testDisplay Itemstack: PASSED testDefaultConstructor PASSED testsecondConstructor FAILURE: testCopyConstructor:70 (aCopy.size ()=9902 ) FAILED testCopyConstructor FAILURE: testassignnent:91 (acopy.size ()=9092 ) FAILED testassignnent PASSED testaddItens PASSED testAddItensFron FAILURE: testlogicalequivalence: 142 (stack1 = stack2) FAILED testLogicalequivalence FAILURE: testlessThan:164 (stack 3 stack1) FAILED testlessThan PASSED testDisplay FAILURE: testSwap:198 (stack1.getiten().getNane() == "Ice") FAILED testSwap There is nothing wrong with Inventory. Inventory is dependent on Itenstack. Until Itenstack is complete you will see failures in testinventory. Item.h \#ifndef ITEM_H_INCLUDED \#define ITEM H INCLUDED \#include Hinclude string * Item reppesents an individual Item in an inventory. * This includes items such as potions, building materials, and food. * * Only one of each item can exist--i.e., no two items share the * same numeric id. / Class Item \{ private: int id; /// Unique numeric identifier--e+g, 1 std: string name; /// std::string tostr (const T\& thing) std::ostringstream outs; outs
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