Question: Lab Exercise Write a C++ program to implement Stack ADT using array and apply Stack to check whether the parentheses are matched. The program includes

 Lab Exercise Write a C++ program to implement Stack ADT usingarray and apply Stack to check whether the parentheses are matched. Theprogram includes the following: Define the stack class template in the header

Lab Exercise 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 stack.h // Stack.h #ifndef STACK H #define STACK H #include class Stack public: // Constructor Stack) //Desctructor -Stack() // Makes the stack to the empty state void make_empty) // Checks if the stack is empty bool empty) const; // Insert item in the stack. void push (const T& item); // Return the top element const T& top) const; // Removes the element fron the front void pop); static const int CAPACITY- 5 private int topofstack;// -1 for empty stack T* theArray #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 "Stack,h" template Stack::Stack() topOfstack -1 theArray = 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 class Stack public: // Constructor Stack() topOfStack 1; theArray = new T[CAPACITY]; // add other member functions static const int CAPACITY 50 private: int topofstack; T* theArray: #endif The main function is contained in the file lab04.cpp /I 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. 1. 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; f 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: The parentheses are balanced Seperate Compilation This lab exercise should be put under cse330/lab04 subdirectory $g++ -c Stack.cpp $g++ -c lab04.cpp $g+ Stack.o lab04.0 -O lab04 $./lab04

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!