Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C++program to implement Stack ADT using array and apply Stack to check whether the parentheses are matched. The program includes the following .
Write a C++program to implement Stack ADT using array and apply Stack to check whether the parentheses are matched. The program includes the following . Define the stack class template in the header file Steck.h Stack.h #ifndef STACK H tdcfine STACK H #include using nanespace std; template class Stack public constructor Stack); Desctructor Stack) Nakes the stack to the empty state void make_empty); Chacks if the stack is ampty bool empty() const; // nsert iten in the stack void push(const T& item); Return the top element const T&top) const; Removes the elenent fron the front void pop); static canst int CAPACITY 5e private int topofStack; -1 for empty stack #endif Please read the comments carefully and implement the Stack class template You can implement the Stack class template in the seperate file stack.cpp // Stack.cpp #include template Stack :Stack() top0fStack theArray = -1; new T[CAPACITY]; // add other member functions You also can put the implementation of the Stack class template in Stack.h. // Stack.h #ifndef STACK H #define STACK H #include using namespace std; template class Stack public: // Constructor Stack() topofStack1; theArraynew T[ CAPACITY]; // add other member functions static const int CAPACITY = 50; private int topOfStack; T theArrays 0; #endif The main function is contained in the file lab04.cpp. // lab04.cpp #include #include "Stack"h" #include "Stack.cpp'. // add if the interface and implementation are seperate int main() The main function checks whether the righ or opening parentheses are correspond to the left or closing parentheses I. Declare a stack which stores charactors. 2. Prompty the user to enter a charactor, stop entering the charactor when the user enter x. 3. If the character entered by user is a righ parenthesis, push it noto the stack. 4. If the character entered by user is a left parenthesis, if the stack is not empty, pop the stack; if the stack is empty, report the unbalance information and return. 5. After the user completes entering, if the stack is empty, report the balance information, otherwise, report the unbalance information The expected result: Enter the sequence: The parentheses are unbalanced. Enter the sequence: CC)) e The parentheses are 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