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.