SlideShare a Scribd company logo
The program reads data from two files,
itemsList-0x.txt
and
inventoryList-0x.txt
. File extensions on Linux may be arbitrary–i.e., these files
could have been named with
.dat
as the extensions.
The first file,
itemsList-0x.txt
, lists all possible items. Each line represents one item in the
form
id name
.
Example 1: Sample itemsList-0x.txt
0 Air 1 HP Potion 2 MP Potion 5 Iron Ore 3 Bow Tie 4 Dirt 6
Diamond Ore 7 Iron Ingot 8 Diamond 9 Diamond Block
The second file,
inventoryList-0x.txt
, lists each individual inventory–or storage chest–followed by a
list of items.
Example 2: Sample inventoryList-0x.txt
# 5
- 1 10 - 2 5 - 3 2 # 6
- 4 3 - 5 27 - 6 44 - 7 55 - 8 1 - 9 4 - 4 3 # 2
- 2 5 - 9 4 - 8 1 - 5 2 - 10 5
Each line preceded by
#
denotes the start of a new inventory. Each line preceded by
-
denotes an item. The program creates a new inventory each
time a
#
is encountered.
When a
-
is encountered, a stack of items, ItemStack, is created. The
ItemStack
is placed in the
Inventory
based on the following rules:
If the Inventory is empty, store the ItemStack, and
return true
.
If the Inventory is not empty, examine the Inventory.
If a matching ItemStack is found, merge the two ItemStacks and
return true
.
If no matching ItemStack is found, store the new ItemStack and
return true
.
If the Inventory is full,
return false
.
Through the magic of abstraction, this is not one function, but
four (4) functions in total. Yes, it does seem unnecessary at
first. However, each function does one thing and only one thing.
This is an exercise in understanding the thought process behind
abstraction, interfaces, and the
S
/
O
in
S.O.L.I.D
(with some C++ code) in a multi-ADT program.
Most of your time will be spent on understanding the
abstractions (and interfaces) as opposed to spamming
cobblestone blocks… I mean C++ code.
3.2 Output
The output consists of three reports written to standard output,
one after the other.
A report listing items that were stored or discarded.
A report listing all valid items.
Finally, a detailed report is printed. listing data for each
inventory:
Maximum Capacity–i.e., total slots.
Utilized Capacity–i.e., occupied slots
Listing of all items.
If the program is run with the provided input files, the
following output should be generated…
Example 3: Sample Output
Processing Log: Stored (10) HP Potion Stored ( 5) MP Potion
Stored ( 2) Bow Tie Stored ( 3) Dirt Stored (27) Iron Ore
Stored (44) Diamond Ore Stored (55) Iron Ingot Stored ( 1)
Diamond Stored ( 4) Diamond Block Stored ( 3) Dirt Stored (
5) MP Potion Stored ( 4) Diamond Block Discarded ( 1)
Diamond Discarded ( 2) Iron Ore Item List: 0 Air 1 HP
Potion 2 MP Potion 3 Bow Tie 4 Dirt 5 Iron Ore 6
Diamond Ore 7 Iron Ingot 8 Diamond 9 Diamond Block
Storage Summary: -Used 3 of 5 slots (10) HP Potion ( 5)
MP Potion ( 2) Bow Tie -Used 6 of 6 slots ( 6) Dirt (27)
Iron Ore (44) Diamond Ore (55) Iron Ingot ( 1) Diamond (
4) Diamond Block -Used 2 of 2 slots ( 5) MP Potion ( 4)
Diamond Block
3.3 Running the Program
The easiest way to see generate the expected output is to run the
sample executable solution I have provided. These two files are
named as command-line parameters when the program is
executed.
For example, if the sample data above is kept in files itemList-
01.txt and inventoryList-01.txt, then to run this program, do:
./storage itemList-01.txt inventoryList-01.txt
(On a Windows system, you would omit the “./”. If you are
running from Code::Blocks or a similar development
environment, you may need to review how to
supply command-line parameters
to a running program.)
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
,
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 copy-and-swap method.
Once you have completed the Copy Constructor, Destructor, and
swap
you are done with the Big-3.
Logical Equivalence (i.e.,
operator==
).
Less-Than (i.e.,
operator<
).
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
TestItemStack.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
Take note of the semicolon (
;
) after
testInventory
. This is a standard Linux trick to run two commands back-to-
back.
You can then run
storage
as described
above
. You can run the
Inventory
and
ItemStack
test drivers with:
./testInventory; ./testItemStack
If you implemented everything correctly you will see:
Inventory:
PASSED -> testDefaultConstructor
PASSED -> testConstructorSizeN
PASSED -> testAddItemStackNoCheck
PASSED -> testAddItemWithDuplicateItems
PASSED -> testAddItemAfterFull
PASSED -> testCopyConstructorForEmpty
PASSED -> testCopyConstructor
PASSED -> testAssignmentOperator
PASSED -> testDisplay
ItemStack:
PASSED -> testDefaultConstructor
PASSED -> testSecondConstructor
PASSED -> testCopyConstructor
PASSED -> testAssignment
PASSED -> testAddItems
PASSED -> testAddItemsFrom
PASSED -> testLogicalEquivalence
PASSED -> testLessThan
PASSED -> testDisplay
PASSED -> testSwap
If you see
FAILED
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* item;
segmentation faults are a consideration. If you download,
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 dumped) ./testInventory
ItemStack:
[1] 21526 segmentation fault (core dumped) ./testItemStack
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.item
. Once you have made that one-line addition, recompile
everything and run
./testInventory; ./testItemStack
again. You should see:
Inventory:
PASSED -> testDefaultConstructor
PASSED -> testConstructorSizeN
FAILURE: testAddItemStackNoCheck:89 -> (*(it++) ==
stacksToAdd[0])
FAILED -> testAddItemStackNoCheck
FAILURE: testAddItemWithDuplicateItems:126 -> (*(it++) ==
stacksToAdd[0])
FAILED -> testAddItemWithDuplicateItems
FAILURE: testAddItemAfterFull:172 -> (*(it++) ==
stacksToAdd[0])
FAILED -> testAddItemAfterFull
PASSED -> testCopyConstructorForEmpty
FAILURE: testCopyConstructor:268 -> (aCopy == source)
FAILED -> testCopyConstructor
FAILURE: testAssignmentOperator:305 -> (aCopy == source)
FAILED -> testAssignmentOperator
FAILURE: testDisplay:204 ->
(bagString.find(stacksAsStrings[0]) != std::string::npos)
FAILED -> testDisplay
ItemStack:
PASSED -> testDefaultConstructor
PASSED -> testSecondConstructor
FAILURE: testCopyConstructor:70 -> (aCopy.size() == 9002)
FAILED -> testCopyConstructor
FAILURE: testAssignment:91 -> (aCopy.size() == 9002)
FAILED -> testAssignment
PASSED -> testAddItems
PASSED -> testAddItemsFrom
FAILURE: testLogicalEquivalence:142 -> (stack1 == stack2)
FAILED -> testLogicalEquivalence
FAILURE: testLessThan:164 -> (stack3 < stack1)
FAILED -> testLessThan
PASSED -> testDisplay
FAILURE: testSwap:198 -> (stack1.getItem().getName() ==
"Ice")
FAILED -> testSwap
There is nothing wrong with
Inventory
.
Inventory
is dependent on
ItemStack
. Until
ItemStack
is complete you will see failures in
testInventory
.

More Related Content

Similar to The program reads data from two files, itemsList-0x.txt and .docx

1 The ProblemThis assignment deals with a program places ite.docx
1 The ProblemThis assignment deals with a program places ite.docx1 The ProblemThis assignment deals with a program places ite.docx
1 The ProblemThis assignment deals with a program places ite.docx
croftsshanon
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
wilcockiris
 
Matopt
MatoptMatopt
A05
A05A05
A05
lksoo
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
marvellous2
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
Mohamed Abdallah
 
fileop report
fileop reportfileop report
fileop report
Jason Lu
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance Meetup
David Barreto
 
Cppcheck
CppcheckCppcheck
Cppcheck
PVS-Studio
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make
YASHU40
 
embeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptxembeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptx
sangeetaSS
 
Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3
FabMinds
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
cargillfilberto
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
drandy1
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
Techglyphs
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
monicafrancis71118
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
Nico Ludwig
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
ReKruiTIn.com
 
Analysis of merge requests in GitLab using PVS-Studio for C#
Analysis of merge requests in GitLab using PVS-Studio for C#Analysis of merge requests in GitLab using PVS-Studio for C#
Analysis of merge requests in GitLab using PVS-Studio for C#
Andrey Karpov
 
PVS-Studio for Visual C++
PVS-Studio for Visual C++PVS-Studio for Visual C++
PVS-Studio for Visual C++
Andrey Karpov
 

Similar to The program reads data from two files, itemsList-0x.txt and .docx (20)

1 The ProblemThis assignment deals with a program places ite.docx
1 The ProblemThis assignment deals with a program places ite.docx1 The ProblemThis assignment deals with a program places ite.docx
1 The ProblemThis assignment deals with a program places ite.docx
 
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docximport java.io.BufferedReader;import java.io.BufferedWriter;.docx
import java.io.BufferedReader;import java.io.BufferedWriter;.docx
 
Matopt
MatoptMatopt
Matopt
 
A05
A05A05
A05
 
Lecture 1
Lecture 1Lecture 1
Lecture 1
 
Embedded C - Lecture 1
Embedded C - Lecture 1Embedded C - Lecture 1
Embedded C - Lecture 1
 
fileop report
fileop reportfileop report
fileop report
 
Angular Optimization Web Performance Meetup
Angular Optimization Web Performance MeetupAngular Optimization Web Performance Meetup
Angular Optimization Web Performance Meetup
 
Cppcheck
CppcheckCppcheck
Cppcheck
 
Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make Question 1 briefly respond to all the following questions. make
Question 1 briefly respond to all the following questions. make
 
embeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptxembeddedc-lecture1-160404055102.pptx
embeddedc-lecture1-160404055102.pptx
 
Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3Python Programming | JNTUK | UNIT 1 | Lecture 3
Python Programming | JNTUK | UNIT 1 | Lecture 3
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
Bt0082 visual basic
Bt0082 visual basicBt0082 visual basic
Bt0082 visual basic
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Analysis of merge requests in GitLab using PVS-Studio for C#
Analysis of merge requests in GitLab using PVS-Studio for C#Analysis of merge requests in GitLab using PVS-Studio for C#
Analysis of merge requests in GitLab using PVS-Studio for C#
 
PVS-Studio for Visual C++
PVS-Studio for Visual C++PVS-Studio for Visual C++
PVS-Studio for Visual C++
 

More from oscars29

The Progressive PresidentsThe presidential election of 1912 wa.docx
The Progressive PresidentsThe presidential election of 1912 wa.docxThe Progressive PresidentsThe presidential election of 1912 wa.docx
The Progressive PresidentsThe presidential election of 1912 wa.docx
oscars29
 
The project is structured as follows Project Part Deliverable P.docx
The project is structured as follows Project Part Deliverable P.docxThe project is structured as follows Project Part Deliverable P.docx
The project is structured as follows Project Part Deliverable P.docx
oscars29
 
The Progressive era stands out as a time when reformers sought to ad.docx
The Progressive era stands out as a time when reformers sought to ad.docxThe Progressive era stands out as a time when reformers sought to ad.docx
The Progressive era stands out as a time when reformers sought to ad.docx
oscars29
 
The Progressive Presidents The presidential election of 1912 was.docx
The Progressive Presidents The presidential election of 1912 was.docxThe Progressive Presidents The presidential election of 1912 was.docx
The Progressive Presidents The presidential election of 1912 was.docx
oscars29
 
The Progressive Presidents The presidential election of 1912 w.docx
The Progressive Presidents The presidential election of 1912 w.docxThe Progressive Presidents The presidential election of 1912 w.docx
The Progressive Presidents The presidential election of 1912 w.docx
oscars29
 
the project is attached.Be as specific as possible.  Describe ho.docx
the project is attached.Be as specific as possible.  Describe ho.docxthe project is attached.Be as specific as possible.  Describe ho.docx
the project is attached.Be as specific as possible.  Describe ho.docx
oscars29
 
The project is application oriented, but focuses on the usage and co.docx
The project is application oriented, but focuses on the usage and co.docxThe project is application oriented, but focuses on the usage and co.docx
The project is application oriented, but focuses on the usage and co.docx
oscars29
 
The Progressive PresidentsThe presidential election of 1912 was .docx
The Progressive PresidentsThe presidential election of 1912 was .docxThe Progressive PresidentsThe presidential election of 1912 was .docx
The Progressive PresidentsThe presidential election of 1912 was .docx
oscars29
 
The Progressive u 17 Toward the end of the oral argum.docx
The Progressive  u   17   Toward the end of the oral argum.docxThe Progressive  u   17   Toward the end of the oral argum.docx
The Progressive u 17 Toward the end of the oral argum.docx
oscars29
 
The project involves the following five partsIntroduction.docx
The project involves the following five partsIntroduction.docxThe project involves the following five partsIntroduction.docx
The project involves the following five partsIntroduction.docx
oscars29
 
The programming Language is c++. I need a program that will initiali.docx
The programming Language is c++. I need a program that will initiali.docxThe programming Language is c++. I need a program that will initiali.docx
The programming Language is c++. I need a program that will initiali.docx
oscars29
 
The project is a video presentation of a PowerPoint. I will need not.docx
The project is a video presentation of a PowerPoint. I will need not.docxThe project is a video presentation of a PowerPoint. I will need not.docx
The project is a video presentation of a PowerPoint. I will need not.docx
oscars29
 
The purpose of this 5 page paper is to write about any compound, for.docx
The purpose of this 5 page paper is to write about any compound, for.docxThe purpose of this 5 page paper is to write about any compound, for.docx
The purpose of this 5 page paper is to write about any compound, for.docx
oscars29
 
The purpose of these assignment is to allow students the opp.docx
The purpose of these assignment is to allow students the opp.docxThe purpose of these assignment is to allow students the opp.docx
The purpose of these assignment is to allow students the opp.docx
oscars29
 
The Progressive EraTriangle Shirtwaist Factory Fire.docx
The Progressive EraTriangle Shirtwaist Factory Fire.docxThe Progressive EraTriangle Shirtwaist Factory Fire.docx
The Progressive EraTriangle Shirtwaist Factory Fire.docx
oscars29
 
The purpose of the strategic plan is to allow the selected healthc.docx
The purpose of the strategic plan is to allow the selected healthc.docxThe purpose of the strategic plan is to allow the selected healthc.docx
The purpose of the strategic plan is to allow the selected healthc.docx
oscars29
 
The purpose of the Final Paper is to apply critical insight to disce.docx
The purpose of the Final Paper is to apply critical insight to disce.docxThe purpose of the Final Paper is to apply critical insight to disce.docx
The purpose of the Final Paper is to apply critical insight to disce.docx
oscars29
 
The purpose of the Feasibility Analysis is to gain insights into the.docx
The purpose of the Feasibility Analysis is to gain insights into the.docxThe purpose of the Feasibility Analysis is to gain insights into the.docx
The purpose of the Feasibility Analysis is to gain insights into the.docx
oscars29
 
The purpose of the Final Paper is for you to examine the issues rela.docx
The purpose of the Final Paper is for you to examine the issues rela.docxThe purpose of the Final Paper is for you to examine the issues rela.docx
The purpose of the Final Paper is for you to examine the issues rela.docx
oscars29
 
The purpose of the Domestic Use Water Analysis is to understand th.docx
The purpose of the Domestic Use Water Analysis is to understand th.docxThe purpose of the Domestic Use Water Analysis is to understand th.docx
The purpose of the Domestic Use Water Analysis is to understand th.docx
oscars29
 

More from oscars29 (20)

The Progressive PresidentsThe presidential election of 1912 wa.docx
The Progressive PresidentsThe presidential election of 1912 wa.docxThe Progressive PresidentsThe presidential election of 1912 wa.docx
The Progressive PresidentsThe presidential election of 1912 wa.docx
 
The project is structured as follows Project Part Deliverable P.docx
The project is structured as follows Project Part Deliverable P.docxThe project is structured as follows Project Part Deliverable P.docx
The project is structured as follows Project Part Deliverable P.docx
 
The Progressive era stands out as a time when reformers sought to ad.docx
The Progressive era stands out as a time when reformers sought to ad.docxThe Progressive era stands out as a time when reformers sought to ad.docx
The Progressive era stands out as a time when reformers sought to ad.docx
 
The Progressive Presidents The presidential election of 1912 was.docx
The Progressive Presidents The presidential election of 1912 was.docxThe Progressive Presidents The presidential election of 1912 was.docx
The Progressive Presidents The presidential election of 1912 was.docx
 
The Progressive Presidents The presidential election of 1912 w.docx
The Progressive Presidents The presidential election of 1912 w.docxThe Progressive Presidents The presidential election of 1912 w.docx
The Progressive Presidents The presidential election of 1912 w.docx
 
the project is attached.Be as specific as possible.  Describe ho.docx
the project is attached.Be as specific as possible.  Describe ho.docxthe project is attached.Be as specific as possible.  Describe ho.docx
the project is attached.Be as specific as possible.  Describe ho.docx
 
The project is application oriented, but focuses on the usage and co.docx
The project is application oriented, but focuses on the usage and co.docxThe project is application oriented, but focuses on the usage and co.docx
The project is application oriented, but focuses on the usage and co.docx
 
The Progressive PresidentsThe presidential election of 1912 was .docx
The Progressive PresidentsThe presidential election of 1912 was .docxThe Progressive PresidentsThe presidential election of 1912 was .docx
The Progressive PresidentsThe presidential election of 1912 was .docx
 
The Progressive u 17 Toward the end of the oral argum.docx
The Progressive  u   17   Toward the end of the oral argum.docxThe Progressive  u   17   Toward the end of the oral argum.docx
The Progressive u 17 Toward the end of the oral argum.docx
 
The project involves the following five partsIntroduction.docx
The project involves the following five partsIntroduction.docxThe project involves the following five partsIntroduction.docx
The project involves the following five partsIntroduction.docx
 
The programming Language is c++. I need a program that will initiali.docx
The programming Language is c++. I need a program that will initiali.docxThe programming Language is c++. I need a program that will initiali.docx
The programming Language is c++. I need a program that will initiali.docx
 
The project is a video presentation of a PowerPoint. I will need not.docx
The project is a video presentation of a PowerPoint. I will need not.docxThe project is a video presentation of a PowerPoint. I will need not.docx
The project is a video presentation of a PowerPoint. I will need not.docx
 
The purpose of this 5 page paper is to write about any compound, for.docx
The purpose of this 5 page paper is to write about any compound, for.docxThe purpose of this 5 page paper is to write about any compound, for.docx
The purpose of this 5 page paper is to write about any compound, for.docx
 
The purpose of these assignment is to allow students the opp.docx
The purpose of these assignment is to allow students the opp.docxThe purpose of these assignment is to allow students the opp.docx
The purpose of these assignment is to allow students the opp.docx
 
The Progressive EraTriangle Shirtwaist Factory Fire.docx
The Progressive EraTriangle Shirtwaist Factory Fire.docxThe Progressive EraTriangle Shirtwaist Factory Fire.docx
The Progressive EraTriangle Shirtwaist Factory Fire.docx
 
The purpose of the strategic plan is to allow the selected healthc.docx
The purpose of the strategic plan is to allow the selected healthc.docxThe purpose of the strategic plan is to allow the selected healthc.docx
The purpose of the strategic plan is to allow the selected healthc.docx
 
The purpose of the Final Paper is to apply critical insight to disce.docx
The purpose of the Final Paper is to apply critical insight to disce.docxThe purpose of the Final Paper is to apply critical insight to disce.docx
The purpose of the Final Paper is to apply critical insight to disce.docx
 
The purpose of the Feasibility Analysis is to gain insights into the.docx
The purpose of the Feasibility Analysis is to gain insights into the.docxThe purpose of the Feasibility Analysis is to gain insights into the.docx
The purpose of the Feasibility Analysis is to gain insights into the.docx
 
The purpose of the Final Paper is for you to examine the issues rela.docx
The purpose of the Final Paper is for you to examine the issues rela.docxThe purpose of the Final Paper is for you to examine the issues rela.docx
The purpose of the Final Paper is for you to examine the issues rela.docx
 
The purpose of the Domestic Use Water Analysis is to understand th.docx
The purpose of the Domestic Use Water Analysis is to understand th.docxThe purpose of the Domestic Use Water Analysis is to understand th.docx
The purpose of the Domestic Use Water Analysis is to understand th.docx
 

Recently uploaded

How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
Wahiba Chair Training & Consulting
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
iammrhaywood
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
EduSkills OECD
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
MJDuyan
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
dot55audits
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
ssuser13ffe4
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
WaniBasim
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
Celine George
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
TechSoup
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
Katrina Pritchard
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
spdendr
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 

Recently uploaded (20)

How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience How to Create a More Engaging and Human Online Learning Experience
How to Create a More Engaging and Human Online Learning Experience
 
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptxNEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
NEWSPAPERS - QUESTION 1 - REVISION POWERPOINT.pptx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptxBeyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
Beyond Degrees - Empowering the Workforce in the Context of Skills-First.pptx
 
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) CurriculumPhilippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
Philippine Edukasyong Pantahanan at Pangkabuhayan (EPP) Curriculum
 
ZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptxZK on Polkadot zero knowledge proofs - sub0.pptx
ZK on Polkadot zero knowledge proofs - sub0.pptx
 
math operations ued in python and all used
math operations ued in python and all usedmath operations ued in python and all used
math operations ued in python and all used
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Liberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdfLiberal Approach to the Study of Indian Politics.pdf
Liberal Approach to the Study of Indian Politics.pdf
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
How to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 InventoryHow to Setup Warehouse & Location in Odoo 17 Inventory
How to Setup Warehouse & Location in Odoo 17 Inventory
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Walmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdfWalmart Business+ and Spark Good for Nonprofits.pdf
Walmart Business+ and Spark Good for Nonprofits.pdf
 
BBR 2024 Summer Sessions Interview Training
BBR  2024 Summer Sessions Interview TrainingBBR  2024 Summer Sessions Interview Training
BBR 2024 Summer Sessions Interview Training
 
Solutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptxSolutons Maths Escape Room Spatial .pptx
Solutons Maths Escape Room Spatial .pptx
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 

The program reads data from two files, itemsList-0x.txt and .docx

  • 1. The program reads data from two files, itemsList-0x.txt and inventoryList-0x.txt . File extensions on Linux may be arbitrary–i.e., these files could have been named with .dat as the extensions. The first file, itemsList-0x.txt , lists all possible items. Each line represents one item in the form id name . Example 1: Sample itemsList-0x.txt 0 Air 1 HP Potion 2 MP Potion 5 Iron Ore 3 Bow Tie 4 Dirt 6 Diamond Ore 7 Iron Ingot 8 Diamond 9 Diamond Block The second file, inventoryList-0x.txt , lists each individual inventory–or storage chest–followed by a list of items. Example 2: Sample inventoryList-0x.txt # 5 - 1 10 - 2 5 - 3 2 # 6 - 4 3 - 5 27 - 6 44 - 7 55 - 8 1 - 9 4 - 4 3 # 2 - 2 5 - 9 4 - 8 1 - 5 2 - 10 5
  • 2. Each line preceded by # denotes the start of a new inventory. Each line preceded by - denotes an item. The program creates a new inventory each time a # is encountered. When a - is encountered, a stack of items, ItemStack, is created. The ItemStack is placed in the Inventory based on the following rules: If the Inventory is empty, store the ItemStack, and return true . If the Inventory is not empty, examine the Inventory. If a matching ItemStack is found, merge the two ItemStacks and return true . If no matching ItemStack is found, store the new ItemStack and return true .
  • 3. If the Inventory is full, return false . Through the magic of abstraction, this is not one function, but four (4) functions in total. Yes, it does seem unnecessary at first. However, each function does one thing and only one thing. This is an exercise in understanding the thought process behind abstraction, interfaces, and the S / O in S.O.L.I.D (with some C++ code) in a multi-ADT program. Most of your time will be spent on understanding the abstractions (and interfaces) as opposed to spamming cobblestone blocks… I mean C++ code. 3.2 Output The output consists of three reports written to standard output, one after the other. A report listing items that were stored or discarded. A report listing all valid items. Finally, a detailed report is printed. listing data for each inventory: Maximum Capacity–i.e., total slots.
  • 4. Utilized Capacity–i.e., occupied slots Listing of all items. If the program is run with the provided input files, the following output should be generated… Example 3: Sample Output Processing Log: Stored (10) HP Potion Stored ( 5) MP Potion Stored ( 2) Bow Tie Stored ( 3) Dirt Stored (27) Iron Ore Stored (44) Diamond Ore Stored (55) Iron Ingot Stored ( 1) Diamond Stored ( 4) Diamond Block Stored ( 3) Dirt Stored ( 5) MP Potion Stored ( 4) Diamond Block Discarded ( 1) Diamond Discarded ( 2) Iron Ore Item List: 0 Air 1 HP Potion 2 MP Potion 3 Bow Tie 4 Dirt 5 Iron Ore 6 Diamond Ore 7 Iron Ingot 8 Diamond 9 Diamond Block Storage Summary: -Used 3 of 5 slots (10) HP Potion ( 5) MP Potion ( 2) Bow Tie -Used 6 of 6 slots ( 6) Dirt (27) Iron Ore (44) Diamond Ore (55) Iron Ingot ( 1) Diamond ( 4) Diamond Block -Used 2 of 2 slots ( 5) MP Potion ( 4) Diamond Block 3.3 Running the Program The easiest way to see generate the expected output is to run the sample executable solution I have provided. These two files are named as command-line parameters when the program is executed. For example, if the sample data above is kept in files itemList- 01.txt and inventoryList-01.txt, then to run this program, do:
  • 5. ./storage itemList-01.txt inventoryList-01.txt (On a Windows system, you would omit the “./”. If you are running from Code::Blocks or a similar development environment, you may need to review how to supply command-line parameters to a running program.) 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 , 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.
  • 6. 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 copy-and-swap method. Once you have completed the Copy Constructor, Destructor, and swap you are done with the Big-3. Logical Equivalence (i.e., operator== ). Less-Than (i.e., operator< ). swap Refer to the comments in each function for additional detail.
  • 7. 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 TestItemStack.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 Take note of the semicolon ( ; ) after testInventory . This is a standard Linux trick to run two commands back-to-
  • 8. back. You can then run storage as described above . You can run the Inventory and ItemStack test drivers with: ./testInventory; ./testItemStack If you implemented everything correctly you will see: Inventory: PASSED -> testDefaultConstructor PASSED -> testConstructorSizeN PASSED -> testAddItemStackNoCheck PASSED -> testAddItemWithDuplicateItems PASSED -> testAddItemAfterFull PASSED -> testCopyConstructorForEmpty PASSED -> testCopyConstructor PASSED -> testAssignmentOperator PASSED -> testDisplay
  • 9. ItemStack: PASSED -> testDefaultConstructor PASSED -> testSecondConstructor PASSED -> testCopyConstructor PASSED -> testAssignment PASSED -> testAddItems PASSED -> testAddItemsFrom PASSED -> testLogicalEquivalence PASSED -> testLessThan PASSED -> testDisplay PASSED -> testSwap If you see FAILED 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.
  • 10. 4.1.1 Segmentation Faults & Getting Started Since ItemStack ’s item data member is a pointer Item* item; segmentation faults are a consideration. If you download, 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 dumped) ./testInventory ItemStack: [1] 21526 segmentation fault (core dumped) ./testItemStack 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
  • 11. src.item . Once you have made that one-line addition, recompile everything and run ./testInventory; ./testItemStack again. You should see: Inventory: PASSED -> testDefaultConstructor PASSED -> testConstructorSizeN FAILURE: testAddItemStackNoCheck:89 -> (*(it++) == stacksToAdd[0]) FAILED -> testAddItemStackNoCheck FAILURE: testAddItemWithDuplicateItems:126 -> (*(it++) == stacksToAdd[0]) FAILED -> testAddItemWithDuplicateItems FAILURE: testAddItemAfterFull:172 -> (*(it++) == stacksToAdd[0]) FAILED -> testAddItemAfterFull PASSED -> testCopyConstructorForEmpty FAILURE: testCopyConstructor:268 -> (aCopy == source) FAILED -> testCopyConstructor
  • 12. FAILURE: testAssignmentOperator:305 -> (aCopy == source) FAILED -> testAssignmentOperator FAILURE: testDisplay:204 -> (bagString.find(stacksAsStrings[0]) != std::string::npos) FAILED -> testDisplay ItemStack: PASSED -> testDefaultConstructor PASSED -> testSecondConstructor FAILURE: testCopyConstructor:70 -> (aCopy.size() == 9002) FAILED -> testCopyConstructor FAILURE: testAssignment:91 -> (aCopy.size() == 9002) FAILED -> testAssignment PASSED -> testAddItems PASSED -> testAddItemsFrom FAILURE: testLogicalEquivalence:142 -> (stack1 == stack2) FAILED -> testLogicalEquivalence FAILURE: testLessThan:164 -> (stack3 < stack1) FAILED -> testLessThan PASSED -> testDisplay
  • 13. FAILURE: testSwap:198 -> (stack1.getItem().getName() == "Ice") FAILED -> testSwap There is nothing wrong with Inventory . Inventory is dependent on ItemStack . Until ItemStack is complete you will see failures in testInventory .