Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ you will be implementing the stack through the use of a linked list. 2.2.1 resrcStack The class is dened according to the simple

In c++

you will be implementing

the stack through the use of a linked list.

2.2.1 resrcStack

The class is dened according to the simple UML diagram below:

resrcStack

-top: stackNode*

----------------------------

+resrcStack()

+~resrcStack()

+push(t: stackNode*):void

+pop():void

+peek():stackNode *

+print():void

+tallyWeights():int

+calculateStorageRequirements():string

The class variables are dened below:

top: The current top of the stack. It will start as null but should refer to the top of

the stack.

The class methods are dened below:

resrcStack: The class constructor. It will start by initialising the variables to null.

resrcStack: The class destructor. It will deallocate all of the memory assigned by

the class.

push: This will receive a stackNode to add onto the current stack. The node is

added from the top.

pop: This will remove the top resrcNode from the stack. If it is empty, print out

"EMPTY" with a newline at the end and no quotation marks. When removing the

node, it should be deleted.

peek: This will return the top node of the stack but without removing it from the

stack.

print: This will print the entire contents of the stack. For each resrc node in the

stack, print the following information out sequentially, line by line. The format of

this is as follows:

Resource: Unrefined Ores

Quantity: 12

Resource: Refined Alloys

Quantity: 1000

Remember that when printing, the rst nodes added will be printed last. The rst

node to be printed should be the last node pushed into the stack.

tallyWeights: This function will tally up the weights for all nodes in the stack and

return their total weight. If empty, return -1.

calculateStorageRequirements: This function must determine what the storage re-

quirement for the materials contained in the stack. The resulting type of storage

unit is returned. The storage requirements are determined as follows:

1. wooden crate: If the weights of the items together are less than 100, a wooden

crate should prove sucient.

2. steel crate: A steel crate will be required if the weights of the items total 200

or more and the number of nodes, is greater than 5 but less than 10.

3. silo: A silo is required when the number of node is greater than 10 under all

circumstances.

This should return wooden crate, steel crate or silo. If none of the conditions are

met, return "LOGISTICS ERROR" without the quotation marks. The wooden

crate takes precedence over the steel crate which takes precedence over the silo for

what to return.

2.2.2 stackNode

The class is dened according to the simple UML diagram below:

stackNode

-resrc:T

+next:stackNode *

-weight: int

------------------------

+stackNode(i:T,w:int)

+~stackNode()

+getResrc():T

+getWeight():int

The class variables are dened below:

resrc: This is the basic resource unit. It will describe the resource contained within

the box. It might be a code that describes the contents or just a description and so

must be a template type to accommodate for a variety of manifests.

next: A pointer to the next node of the stack.

weight: A variable which describes the total weight of the resources contained within

the class.

The class methods are dened below:

stackNode: A class constructor. It receives the template type and the weight for

that item.

stackNode: The class destructor. It should print out "Resource Unit Destroyed"

with no quotation marks and a new line at the end.

getResrc: This returns the template variable stored within the class.

You will be allowed to use the following libraries: string, iostream.

Your submission must contain stackNode.h,

stackNode.cpp, resrcStack.h, resrcStack.cpp, main.cpp and a makefile.

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

Intranet And Web Databases For Dummies

Authors: Paul Litwin

1st Edition

0764502212, 9780764502217

More Books

Students also viewed these Databases questions