Question: #include #include using namespace std; // I created my own stacks, by using some of your code and combine them into one. const int MAX_ITEMS
#include
class StackType { public: StackType(); // Class constructor. bool IsFull() const; // Function: Determines whether the stack is full. // Pre: Stack has been initialized. // Post: Function value = (stack is full) bool IsEmpty() const; // Function: Determines whether the stack is empty. // Pre: Stack has been initialized. // Post: Function value = (stack is empty) void Push(ItemType item); // Function: Adds newItem to the top of the stack. // Pre: Stack has been initialized. // Post: If (stack is full), FullStack exception is thrown; // otherwise, newItem is at the top of the stack. void Pop(); // Function: Removes top item from the stack. // Pre: Stack has been initialized. // Post: If (stack is empty), EmptyStack exception is thrown; // otherwise, top element has been removed from stack. ItemType Top(); // Function: Returns a copy of top item on the stack. // Pre: Stack has been initialized. // Post: If (stack is empty), EmptyStack exception is thrown; // otherwise, top element has been removed from stack. char top; ItemType items[MAX_ITEMS]; }; StackType::StackType() { top = -1; } bool StackType::IsEmpty() const { return (top == -1); } bool StackType::IsFull() const { return (top == MAX_ITEMS-1); } void StackType::Push(ItemType newItem) { if( IsFull() ) throw FullStack(); top++; items[top] = newItem; } void StackType::Pop() { if( IsEmpty() ) throw EmptyStack(); top--; } ItemType StackType::Top() { if (IsEmpty()) throw EmptyStack(); return items[top]; } int main() { StackType S; S.Push('P'); S.Push('R'); S.Push('Y'); S.Push('B'); S.Push('Y'); S.Push('G'); StackType storecolor; char color; cout
================== I am able to get the Output, You can modify it now, You need to call S.Top() and not S.Top
I .h file, we just add the class Structure and nothing else. You can move your class to .h file if you want
// I created my own stacks, by using some of your code and combine them into one from this comment , till this much.. char top; ItemType items[MAX_ITEMS]; };
add all into .h file and then you need to include here like #include "Stack.h" in Test Code
*************************HOW DO I ADD A PRINT STACK - BEFORE, DURING AND AFTER THANKS C++ CODE BLOCK
StackType S; S. PushC'P' S.PushC'R' S. PushC'Y; S.PushC'B' S.PushC'Y' S. PushC'G'; StackType storecolor; char color; cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
