Answered step by step
Verified Expert Solution
Question
1 Approved Answer
#ifndef STACKTYPE _ H _ INCLUDED #define STACKTYPE _ H _ INCLUDED const int MAX _ ITEMS = 5 ; class FullStack / / Exception
#ifndef STACKTYPEHINCLUDED
#define STACKTYPEHINCLUDED
const int MAXITEMS ;
class FullStack
Exception class thrown
by Push when stack is full.
;
class EmptyStack
Exception class thrown
by Pop and Top when stack is emtpy.
;
template
class StackType
public:
StackType;
bool IsFull;
bool IsEmpty;
void PushItemType;
void Pop;
ItemType Top;
private:
int top;
ItemType itemsMAXITEMS;
;
#endif STACKTYPEHINCLUDED
stacktype.cpp
#include "StackType.h
template
StackType::StackType
top ;
template
bool StackType::IsEmpty
return top ;
template
bool StackType::IsFull
return top MAXITEMS;
template
void StackType::PushItemType newItem
if IsFull throw FullStack;
top;
itemstop newItem;
template
void StackType::Pop
if IsEmpty throw EmptyStack;
top;
template
ItemType StackType::Top
if IsEmpty throw EmptyStack;
return itemstop;
Generate the driver file maincpp where you perform the following tasks. Note that you cannot make any change to
the header file or the source file.
Operation to Be Tested and Description of Action Input Values Expected Output
Create a stack of integers
Check if the stack is empty Stack is Empty
Push four items
Check if the stack is empty Stack is not Empty
Check if the stack is full Stack is not full
Print the values in the stack in the order the values are given as
input
Push another item
Print the values in the stack
Check if the stack is full Stack is full
Pop two items
Print top item
Take strings of parentheses from the user as input and use a stack to
check if the string of parentheses is balanced or not
Balanced
Balanced
Not balanced
Not balanced
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started