Question: Given the stack template specification below, add the copy ctor and assignment operator, code the member function implementations, and execute the driver program to test
Given the stack template specification below, add the copy ctor and assignment operator, code the member function implementations, and execute the driver program to test the class. Test using a minimum of two template classes in the same program (as part of your testing design and code a client function that has a pass-by-value stack parameter).
#ifndef _stack_h
#define _stack_h
// stack.h - Stack class header file
#include "stkxcptn.h"
const int MAX_ITEMS = 25;
template
class Stack
{
private :
int top; // top of stack
int max; // max size of stack
T * items; // items a pointer to an item
public :
Stack(); // default size of MAX_ITEMS
Stack(int max); // max is stack size
~Stack(); // destructor
void makeEmpty(); // Post: stack is empty
bool isFull() const; // returns top + 1 == max
bool isEmpty() const; // returns top == -1
void push(T itm); // throws exception PushOnFullStack if the stack isFull,
// else puts itm on top of stack
void pop(T & itm); // throws exception PopOnMTStack if stack isEmpty,
// else removes top item and stores it in itm
}; // end Stack
#endif
// stkxcptn.h
#ifndef DS_2_stkxcptn_h
#define DS_2_stkxcptn_h
#include
#include
using namespace std;
const int MAX_ITEMS = 25; // max items in stack
class PushOnFullStack
{
private:
string msg;
public:
PushOnFullStack(): msg("Attempt to push full stack")
{ }
string getMessage()
{ return msg; }
}; // PushOnFullStack
class PopOnMTStack
{
private:
string msg;
public:
PopOnMTStack(): msg("Attempt to pop empty stack")
{ }
string getMessage()
{ return msg; }
}; // PopOnMTStack
#endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
