Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Analyze the algorithms, provide a brief review of the stack(s) included, and explain the time complexity of the individual functions (push & pop). ====================================================================================== Programs:

Analyze the algorithms, provide a brief review of the stack(s) included, and explain the time complexity of the individual functions (push & pop).

======================================================================================

Programs:

InventoryItem.h:

// Specification file for the InventoryItem class

#ifndef INVENTORYITEM_H #define INVENTORYITEM_H #include #include using namespace std;

class InventoryItem { private: long serialNum; //integer variable for serial number string manufactDate; //member that holds the date for part manfactured int lotNum; //integer hold the lot number public: InventoryItem() { serialNum=0; //integer variable for serial number manufactDate="01/01/2000"; //set default date as 01/01/2000 lotNum=0; } // Constructor InventoryItem(long serialNum, string manufactDate,int lotNum) { setSerialNum(serialNum); setManufactDate (manufactDate); setLotNum(lotNum); } // define mutators here void setSerialNum(long serialNum) { this->serialNum = serialNum; } void setManufactDate (string manufactDate) { this->manufactDate = manufactDate; } void setLotNum(int lotNum) { this->lotNum=lotNum; } // define accessors here long getSerialNum() const { return serialNum;//return serial Number of the manufactured item } string getManufactDate() { return manufactDate;//return Date of the manufactured item } int getLotNum() { return lotNum; } friend ostream& operator<<(ostream &out,InventoryItem &item) { out << "\tSerial number: " << item.getSerialNum() << endl; out << "\tManufacture date: " << item.getManufactDate() << endl; out << "\tLotNum: " << item.getLotNum() << endl; return out; }

};

#endif

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Stack.h:

// Dynamic type stack class that can hold objects of any class. #include using namespace std; // DynStack template

template class Stack { private: struct Node { T item; Node *next; }; Node *top; public: Stack(){ top = NULL; } void push(T); void pop(T &); bool isEmpty(); };

template void Stack::push(T num) { Node *newNode = new Node; //Allocate a new node and store num there newNode->item = num; //If there are no nodes in the list, make the newNode first node. if (isEmpty()) { top = newNode; newNode->next = NULL; } else //otherwise, insert newNode before top { newNode->next = top; top =newNode; } }

template void Stack::pop(T &item) { Node *t; //temporary point //make sure the stack isn't empty if (isEmpty()) { cout << "The stack is empty. "; } else //pop value off top of stack { item = top->item; t = top->next; delete top; top = t; } }

template bool Stack::isEmpty() { if (top==NULL) return true; else return false; }

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Inventory.cpp:

#include #include "InventoryItem.h" #include "Stack.h" using namespace std;

int main() { Stack inventoryStack; // create stack InventoryItem item; // create inventory item object int ch; // Menu choice long serialNum; // Serial number string manufactDate; // Manufacture date int lotNum=1; do { // Display the menu. cout << " ------ Inventory Menu -------- "; cout << "1. Enter a part into the inventory. "; cout << "2. Take a part from the inventory. "; cout << "3. Quit. "; cout << "Please make a choice (1, 2, or 3): "; cin >> ch; // Validate choice while (ch < 1 || ch > 3) { cout << "Please enter 1, 2, or 3: "; cin >> ch; } // Act on the user's choice. switch(ch) { case 1: // Enter a part into inventory. cout << " You have chosen to add an item to the inventory bin. "; cout << "Enter the item's serial number: "; cin >> serialNum; cout << "Enter the item's manufacture date: "; cin >> manufactDate; inventoryStack.push(InventoryItem(serialNum,manufactDate,lotNum)); lotNum++; break; case 2: // Take a part out of inventory. cout << " You have chosen to remove an item from the inventory bin. "; if (inventoryStack.isEmpty()) cout << "No parts to remove. "; else { inventoryStack.pop(item); cout << " The part you removed was: "; cout <

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_2

Step: 3

blur-text-image_3

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

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

1 What demand is and what affects it.

Answered: 1 week ago

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago