1. Use a below-given starter code. Use StackInterface.(h), and ArrayStack.(h,cpp). You will write your own StackDriver.cpp application file. IT'S IN C++Also...If the class that you create is Star, remember that you will declare your stack as follows:ArrayStack myStarStack;and you will push, pop, and peek Star objects.2. Create your own class definition. I should have at least one attribute, a constructor, and set and get methods for each attribute in your class.NOTE: If your class is offensive your lab will be rejected and you will receive a score of zero. I'm sorry I have to say this but there is a history of this happening and it is not appropriate.3. Write a driver program that exercises the Stack class from the downloaded starter code. Create multiple instances of your own class and demonstrate the stack operations: push, pop, and peek. ( you write your own class that you will put on the stack and you will write a driver that pushes, peeks, and pops your class items onto and off of the stack.)4. Your driver should not require input from the user. All data should be hard-coded in the driver.ArrayStack.cpp#include // For assert#include "ArrayStack.h" // Header filetemplateArrayStack::ArrayStack() : top(-1){} // end default constructor// Copy constructor and destructor are supplied by the compilertemplatebool ArrayStack::isEmpty() const{ return top <>} // end isEmptytemplatebool ArrayStack::push(const ItemType& newEntry){ bool result = false; if (top < max_stack="" -="" 1)="" does="" stack="" have="" room="" for=""> {top++;items[top] = newEntry;result = true; } // end if return result;} // end pushStackInterface.h#ifndef _STACK_INTERFACE#define _STACK_INTERFACEtemplateclass StackInterface{public: /** Sees whether this stack is empty.@return True if the stack is empty, or false if not. */ virtual bool isEmpty() const = 0; /** 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 stackhas 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, andthe stack is unchanged.@return The top of the stack. */ virtual ItemType peek() const = 0;}; // end StackInterface#endiftemplatebool ArrayStack::pop(){ bool result = false; if (!isEmpty()) {top--;result = true; } // end if return result;} // end poptemplateItemType ArrayStack::peek() const{ assert(!isEmpty()); // Enforce precondition // Stack is not empty; return top return items[top];} // end peek// End of implementation file.ArrayStack.h#ifndef _ARRAY_STACK#define _ARRAY_STACK#include "StackInterface.h"const int MAX_STACK = 50;templateclass ArrayStack : public StackInterface{private: ItemType items[MAX_STACK]; // Array of stack items int top; // Index to top of stackpublic:ArrayStack(); // Default constructorbool isEmpty() const;bool push(const ItemType& newEntry);bool pop();ItemType peek() const;}; // end ArrayStack#include "ArrayStack.cpp"#endif
ArrayStack.cpp
#include // For assert#include "ArrayStack.h" // Header filetemplateArrayStack::ArrayStack() : top(-1){} // end default constructor// Copy constructor and destructor are supplied by the compilertemplatebool ArrayStack::isEmpty() const{ return top <>} // end isEmptytemplatebool ArrayStack::push(const ItemType& newEntry){ bool result = false; if (top < max_stack="" -="" 1)="" does="" stack="" have="" room="" for=""> {top++;items[top] = newEntry;result = true; } // end if return result;} // end pushStackInterface.h#ifndef _STACK_INTERFACE#define _STACK_INTERFACEtemplateclass StackInterface{public: /** Sees whether this stack is empty.@return True if the stack is empty, or false if not. */ virtual bool isEmpty() const = 0; /** 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 stackhas 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, andthe stack is unchanged.@return The top of the stack. */ virtual ItemType peek() const = 0;}; // end StackInterface#endiftemplatebool ArrayStack::pop(){ bool result = false; if (!isEmpty()) {top--;result = true; } // end if return result;} // end poptemplateItemType ArrayStack::peek() const{ assert(!isEmpty()); // Enforce precondition // Stack is not empty; return top return items[top];} // end peek// End of implementation file.ArrayStack.h#ifndef _ARRAY_STACK#define _ARRAY_STACK#include "StackInterface.h"const int MAX_STACK = 50;templateclass ArrayStack : public StackInterface{private: ItemType items[MAX_STACK]; // Array of stack items int top; // Index to top of stackpublic:ArrayStack(); // Default constructorbool isEmpty() const;bool push(const ItemType& newEntry);bool pop();ItemType peek() const;}; // end ArrayStack#include "ArrayStack.cpp"#endif
StackInterface.h
#ifndef _STACK_INTERFACE#define _STACK_INTERFACEtemplateclass StackInterface{public: /** Sees whether this stack is empty.@return True if the stack is empty, or false if not. */ virtual bool isEmpty() const = 0; /** 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 stackhas 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, andthe stack is unchanged.@return The top of the stack. */ virtual ItemType peek() const = 0;}; // end StackInterface#endiftemplatebool ArrayStack::pop(){ bool result = false; if (!isEmpty()) {top--;result = true; } // end if return result;} // end poptemplateItemType ArrayStack::peek() const{ assert(!isEmpty()); // Enforce precondition // Stack is not empty; return top return items[top];} // end peek// End of implementation file.ArrayStack.h#ifndef _ARRAY_STACK#define _ARRAY_STACK#include "StackInterface.h"const int MAX_STACK = 50;templateclass ArrayStack : public StackInterface{private: ItemType items[MAX_STACK]; // Array of stack items int top; // Index to top of stackpublic:ArrayStack(); // Default constructorbool isEmpty() const;bool push(const ItemType& newEntry);bool pop();ItemType peek() const;}; // end ArrayStack#include "ArrayStack.cpp"#endif
templatebool ArrayStack::pop(){ bool result = false; if (!isEmpty()) {top--;result = true; } // end if return result;} // end poptemplateItemType ArrayStack::peek() const{ assert(!isEmpty()); // Enforce precondition // Stack is not empty; return top return items[top];} // end peek// End of implementation file.ArrayStack.h#ifndef _ARRAY_STACK#define _ARRAY_STACK#include "StackInterface.h"const int MAX_STACK = 50;templateclass ArrayStack : public StackInterface{private: ItemType items[MAX_STACK]; // Array of stack items int top; // Index to top of stackpublic:ArrayStack(); // Default constructorbool isEmpty() const;bool push(const ItemType& newEntry);bool pop();ItemType peek() const;}; // end ArrayStack#include "ArrayStack.cpp"#endif
#ifndef _ARRAY_STACK#define _ARRAY_STACK#include "StackInterface.h"const int MAX_STACK = 50;templateclass ArrayStack : public StackInterface{private: ItemType items[MAX_STACK]; // Array of stack items int top; // Index to top of stackpublic:ArrayStack(); // Default constructorbool isEmpty() const;bool push(const ItemType& newEntry);bool pop();ItemType peek() const;}; // end ArrayStack#include "ArrayStack.cpp"#endif
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here