Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program (program.cpp along with Stack.h and Stack.cpp). - In Stack.h

ID: 3634923 • Letter: W

Question

Write a C++ program (program.cpp along with Stack.h and Stack.cpp).

- In Stack.h and Stack.cpp, create a stack that stores char data. Doesn’t matter whether you implement static stack or dynamic stack.

- In program.cpp, write a main function that asks the user to enter a series of parentheses and/or braces, then indicates whether or not they’re properly nested:

Example 1:
Enter parentheses and/or braces: ((){}{()})
Parentheses/braces are nested properly

Example 2:
Enter parentheses and/or braces: {{{()}}
Parentheses/braces are NOT nested properly

- Hint: As the program reads characters, have it push each left parenthesis or left brace. When it reads a right parenthesis or brace, have it pop the stack and check if the popped item is a matching parenthesis or brace (If not, the parentheses/braces aren’t nested properly). When there is no more character to read, check if the stack is empty; if so, the parentheses/braces are matched.

Explanation / Answer

# include # include # define SIZE 20 class stack { int a[SIZE]; int tos; // Top of Stack public: stack(); void push(int); int pop(); int isempty(); int isfull(); }; stack::stack() { tos=0; //Initialize Top of Stack } int stack::isempty() { return (tos==0?1:0); } int stack::isfull() { return (tos==SIZE?1:0); } void stack::push(int i) { if(!isfull()) { cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote