1. Engineering
  2. Computer Science
  3. lab exercise write a c program to implement stack adt...

Question: lab exercise write a c program to implement stack adt...

Question details

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 <iostream» using namespace std; template <typename T> 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 <typename T> Stack<T>::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 <iostream» using namespace std; template <typename T> 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: #endifThe main function is contained in the file lab04.cpp /I lab04.cpp #include <string> #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

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution