Question
Please write code in c++ Use the linkedstack.h, node.h and stackinterface.h provided below the question. Write a program to handle the flow of widgets into
Please write code in c++
Use the linkedstack.h, node.h and stackinterface.h provided below the question.
Write a program to handle the flow of widgets into and out of a warehouse. The warehouse will have numerous deliveries of new widgets and orders for widgets. The widgets in a filled order are billed at a profit of 50 percent over their cost. Each delivery of new widgets may have a different cost associated with it. The accountants for the firm have instituted a last-in, first-out system for filling orders. This means that the newest widgets are the first ones sent out to fill an order. Also, the most recent orders are filled first. This function of inventory can be represented using two stacks: orders-to-be-filled and widgets-on-hand. When a delivery of new widgets is received, any unfilled orders (on the orders-to-be-filled stack) are processed and filled. After all orders are filled, if there are widgets remaining in the new delivery, a new element is pushed onto the widgets-on-hand stack. When an order for new widgets is received, one or more objects are popped from the widgets-on-hand stack until the order has been filled. If the order is completely filled and there are widgets left over in the last object popped, a modified object with the quantity updated is pushed onto the widgets-on-hand stack. If the order is not completely filled, the order is pushed onto the orders-to-be-filled stack with an updated quantity of widgets to be sent out later. If an order is completely filled, it is not pushed onto the stack. Write a class with functions to process the shipments received and to process orders. After an order is filled, display the quantity sent out and the total cost for all widgets in the order. Also indicate whether there are any widgets remaining to be sent out at a later time. After a delivery is processed, display information about each order that was filled with this delivery and indicate how many widgets, if any, were stored in the object pushed onto the widgets-on-hand stack.
LINKEDSTACK.H
#pragma once // Created by Frank M. Carrano and Tim Henry. // Copyright (c) 2013 __Pearson Education__. All rights reserved.
/** ADT stack: Link-based implementation. Listing 7-3. @file LinkedStack.h */
#include "StackInterface.h" #include "Node.h" #include
template
public: // Constructors and destructor: LinkedStack(); // Default constructor LinkedStack(const LinkedStack
// Stack operations: bool isEmpty() const; bool push(const ItemType& newItem); bool pop(); ItemType peek() const; }; // end LinkedStack
// Created by Frank M. Carrano and Tim Henry. // Copyright (c) 2013 __Pearson Education__. All rights reserved.
/** Listing 7-4. @file LinkedStack.cpp */
#include
template
template
if (origChainPtr == nullptr) topPtr = nullptr; // Original stack is empty else { // Copy first node topPtr = new Node
// Point to last node in new chain Node
// Advance original-chain pointer origChainPtr = origChainPtr->getNext();
// Copy remaining nodes while (origChainPtr != nullptr) { // Get next item from original chain ItemType nextItem = origChainPtr->getItem();
// Create a new node containing the next item Node
// Link new node to end of new chain newChainPtr->setNext(newNodePtr);
// Advance pointer to new last node newChainPtr = newChainPtr->getNext();
// Advance original-chain pointer origChainPtr = origChainPtr->getNext(); } // end while
newChainPtr->setNext(nullptr); // Flag end of chain } // end if } // end copy constructor
template
template
template
return true; } // end push
template
// Return deleted node to system nodeToDeletePtr->setNext(nullptr); delete nodeToDeletePtr; nodeToDeletePtr = nullptr;
result = true; } // end if
return result; } // end pop
template
// Stack is not empty; return top return topPtr->getItem(); } // end getTop // End of implementation file.
NODE.H
// Created by Frank M. Carrano and Tim Henry. // Copyright (c) 2013 __Pearson Education__. All rights reserved.
/** @file Node.h Listing 4-1 */ #ifndef _NODE #define _NODE #include
public: Node(); Node(const ItemType& anItem); Node(const ItemType& anItem, Node
/** @file Node.cpp Listing 4-2 */
template
template
template
template
template
template
template
STACKINTERFACE.H
// Created by Frank M. Carrano and Tim Henry. // Copyright (c) 2013 __Pearson Education__. All rights reserved.
/** @file StackInterface.h */
#ifndef _STACK_INTERFACE #define _STACK_INTERFACE #include
template
/** Adds a new entry to the top of this stack. @post If the operation was successful, newEntry is at the top of the stack. @param newEntry The object to be added as a new entry. @return True if the addition is successful or false if not. */ virtual bool push(const ItemType& newEntry) = 0;
/** Removes the top of this stack. @post If the operation was successful, the top of the stack has been removed. @return True if the removal is successful or false if not. */ virtual bool pop() = 0;
/** Returns the top of this stack. @pre The stack is not empty. @post The top of the stack has been returned, and the stack is unchanged. @return The top of the stack. */ virtual ItemType peek() const = 0; }; // end StackInterface #endif
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