Given intstack.h, usestack.cpp, and evalfull.cpp. You must write a C++ function
ID: 3792231 • Letter: G
Question
Given intstack.h, usestack.cpp, and evalfull.cpp.
You must write a C++ function balanced to complete this program the evalfull.cpp.
. Edit evalFull.cpp so that balanced implements the following algorithm:
Just one stack is needed, and it is already created in the skeleton: stack<char *> s is an object of the STL stack class that is set up to store C strings like "(".
Compile and test it on some balanced and some unbalanced expressions. If balanced, the program should print a result, or at least throw a different exception string like the following sample runs of our solution:
Then Edit usestack.cpp again to try this algorithm on a postfix expression (remember the stack in usestack.cpp only handles int values), and print the results to cout. For example, here is how the second expression from above could be evaluated (starts with a fresh stack):
Example
Please select a different expression - make up a simple one, but not too simple, so you know you understand the steps. Don't make it so complicated that you won't have time to complete it before lab ends. Show the expression you are evaluating in a comment at the top. Compile and test it.
Explanation / Answer
#ifndef INTSTACK_H #define INTSTACK_H #define CAPACITY 10 class Stack { public: Stack() : next(0) { } void push(int n) { data[next++] = n; } void pop() { --next; } int top() const { return data[next-1]; } bool empty() const { return nextRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.