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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

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<Star> 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 <cassert> // For assert
#include "ArrayStack.h" // Header file

template<class ItemType>
ArrayStack<ItemType>::ArrayStack() : top(-1)
{
} // end default constructor

// Copy constructor and destructor are supplied by the compiler

template<class ItemType>
bool ArrayStack<ItemType>::isEmpty() const
{
   return top < 0;
} // end isEmpty

template<class ItemType>
bool ArrayStack<ItemType>::push(const ItemType& newEntry)
{
   bool result = false;
   if (top < MAX_STACK - 1) // Does stack have room for newEntry?
   {
top++;
items[top] = newEntry;
result = true;
   } // end if
  
   return result;
} // end push

StackInterface.h

#ifndef _STACK_INTERFACE
#define _STACK_INTERFACE

template<class ItemType>
class 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 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



template<class ItemType>
bool ArrayStack<ItemType>::pop()
{
   bool result = false;
   if (!isEmpty())
   {
top--;
result = true;
   } // end if
  
   return result;
} // end pop


template<class ItemType>
ItemType ArrayStack<ItemType>::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;

template<class ItemType>
class ArrayStack : public StackInterface<ItemType>
{
private:
   ItemType items[MAX_STACK]; // Array of stack items
   int top; // Index to top of stack
  
public:
ArrayStack(); // Default constructor
bool isEmpty() const;
bool push(const ItemType& newEntry);
bool pop();
ItemType peek() const;
}; // end ArrayStack

#include "ArrayStack.cpp"
#endif

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 7 images

Blurred answer
Knowledge Booster
Stack operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education