1. Engineering
  2. Computer Science
  3. write a cprogram to implement stack adt using array and...

Question: write a cprogram to implement stack adt using array and...

Question details

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 <iostream> using nanespace std; template <typenane T> 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 #endifPlease 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 <typename Stack . h T> Stack<T> :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 <iostream> using namespace std; template <typename T> 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 <string> #include Stackh #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.

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