Answer the question in C++ program. Modify the use of stack from class template to a class for si...

Answer the question in the C++ program.

Modify the use of stack from class template to a class for single dimension dynamic integer array objects (use the dynamic integer array implementation). In the driver file create 3 dynamic integer arrays of size 2, 3 and 4. Now, fill up these three arrays with user inputs. Push these arrays into a stack. Finally, print the stack.

The code for the stack is given below:

//the header file
#ifndef STACKTYPE_H_INCLUDED
#define STACKTYPE_H_INCLUDED
#include <iostream>
using namespace std;
const int MAX_ITEMS = 10;
class FullStack
// Exception class thrown
// by Push when stack is full.
{
};
class EmptyStack
// Exception class thrown
// by Pop and Top when stack is empty.
{
};
template <class ItemType>
class StackType
{
public:
StackType();
bool IsFull();
bool IsEmpty();
void Push(ItemType);
void Pop();
ItemType Top();
private:
int top;
ItemType items[MAX_ITEMS];
};
#include "stacktype.tpp"
#endif // STACKTYPE_H_INCLUDED

//the tpp file
#include "stacktype.h"
template <class ItemType>
StackType<ItemType>::StackType()
{
top = -1;
}
template <class ItemType>
bool StackType<ItemType>::IsEmpty()
{
return (top == -1);
}
template <class ItemType>
bool StackType<ItemType>::IsFull()
{
//int lastIndex = MAX_ITEMS -1;
return (top == MAX_ITEMS -1);
}
template <class ItemType>
void StackType<ItemType>::Push(ItemType newItem)
{
if(IsFull())
throw FullStack();
top++;
items[top] = newItem;
}
template <class ItemType>
void StackType<ItemType>::Pop()
{
if(IsEmpty())
throw EmptyStack();
top--;
}
template <class ItemType>
ItemType StackType<ItemType>::Top()
{
if (IsEmpty())
throw EmptyStack();
return items[top];
}

Solved
Programming in C,C++ 1 Answer Fahad Ahmed