Write a C++ program to implement Stack ADT using array and apply Stack class template to check whether the parentheses are matched. The program includes the following: Define and implement the Stack class template in the file Stack.cpp // Stack.cpp #ifndef STACK_H #define STACK_H template class Stack { public: Stack() } topOfStack = -1; items = new T[CAPACITY]; //Desctructor ~Stack() • { } // Checks if the stack is empty. bool empty() const { } // Makes the stack to the empty state. void clear() } // Insert item in the stack. void push(const T& item) { } // Return the top element. const T& top() const { } // Removes the top element. void pop() { } static const int CAPACITY = 50; private: }; int topOfStack; // -1 for empty stack T✶ items; #endif Please read the comments carefully and implement the Stack class template. The main function is contained in the file lab06.cpp. // lab06.cpp #include #include #include "Stack.cpp" using namespace std; int main() { Stack sc; char c; bool balanced = true; cout << "enter chars, exit when enter 'x': "; cin >> c; // add your code return 0; } The main function checks whether the right or opening parentheses have corresponding left or closing parentheses. 1. Declares a stack which stores characters. 2. Prompts the user to enter a character, stop entering the character when the user enters 'x' 3. If the character entered by user is a left parenthesis '(', push it onto the stack. 4. If the character entered by user is a right parenthesis ')', ■ if the stack is not empty, pop the stack; ■ if the stack is empty, report the unbalance information and break (exit while loop). 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: ((())) (( ) x The parentheses are unbalanced. Enter the sequence: ((())) ( ) ( ) x The parentheses are balanced.
Write a C++ program to implement Stack ADT using array and apply Stack class template to check whether the parentheses are matched. The program includes the following: Define and implement the Stack class template in the file Stack.cpp // Stack.cpp #ifndef STACK_H #define STACK_H template class Stack { public: Stack() } topOfStack = -1; items = new T[CAPACITY]; //Desctructor ~Stack() • { } // Checks if the stack is empty. bool empty() const { } // Makes the stack to the empty state. void clear() } // Insert item in the stack. void push(const T& item) { } // Return the top element. const T& top() const { } // Removes the top element. void pop() { } static const int CAPACITY = 50; private: }; int topOfStack; // -1 for empty stack T✶ items; #endif Please read the comments carefully and implement the Stack class template. The main function is contained in the file lab06.cpp. // lab06.cpp #include #include #include "Stack.cpp" using namespace std; int main() { Stack sc; char c; bool balanced = true; cout << "enter chars, exit when enter 'x': "; cin >> c; // add your code return 0; } The main function checks whether the right or opening parentheses have corresponding left or closing parentheses. 1. Declares a stack which stores characters. 2. Prompts the user to enter a character, stop entering the character when the user enters 'x' 3. If the character entered by user is a left parenthesis '(', push it onto the stack. 4. If the character entered by user is a right parenthesis ')', ■ if the stack is not empty, pop the stack; ■ if the stack is empty, report the unbalance information and break (exit while loop). 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: ((())) (( ) x The parentheses are unbalanced. Enter the sequence: ((())) ( ) ( ) x The parentheses are balanced.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Write the full C++ code for the required output provided in the screenshot
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education