Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Stack Post Evaluation Program Help I will rate helpful working solution thumbs up. Please modify my code below to have correct output Assignment: My
C++ Stack Post Evaluation Program Help
I will rate helpful working solution thumbs up. Please modify my code below to have correct output
Assignment:
My code :
#include#include #include #include using namespace std; template class stackType { public: void initializeStack(); bool isEmptyStack() const; bool isFullStack() const; void push(const T& newItem); T top() const; void pop(); stackType(int stackSize = 100); stackType(const stackType & otherStack); ~stackType(); private: int maxStackSize; int stackTop; T *list; void copyStack(const stackType & otherStack); }; template void stackType ::initializeStack() { stackTop = 0; } template bool stackType ::isEmptyStack() const { return (stackTop == 0); } template bool stackType ::isFullStack() const { return (stackTop == maxStackSize); } template void stackType ::push(const T& newItem) { if (!isFullStack()) { list[stackTop] = newItem; stackTop++; } else cout T stackType ::top() const { assert(stackTop != 0); return list[stackTop - 1]; } template void stackType ::pop() { if(!isEmptyStack()) stackTop--; else cout stackType ::stackType(int stackSize) { if (stackSize stackType ::~stackType() { delete [] list; } template void stackType ::copyStack(const stackType & otherStack) { delete [] list; maxStackSize = otherStack.maxStackSize; stackTop = otherStack.stackTop; list = new T[maxStackSize]; for (int j = 0; j stackType ::stackType(const stackType & otherStack) { list = nullptr; //list = 0; copyStack(otherStack); } void evaluateExpression(ifstream& inpF, ofstream& outF, stackType & stack, char& ch, bool& expressionOk); void evaluateOpr(ofstream& out, stackType & stack, char& ch, bool& isExpOk); void discardExp(ifstream& in, ofstream& out, char& ch); void printResult1(ofstream& outF, stackType & stack, bool isExpOk); //void printResult(ofstream& outF, stackType & stack, bool isExpOk); int main() { bool expressionOk; char ch; stackType stack(100); //string file = "exprfile"; ifstream infile; ofstream outfile; infile.open("bookdata"); //infile.open(file.c_str()); if (!infile) { cout > ch; while (infile) { stack.initializeStack(); expressionOk = true; outfile > ch; } infile.close(); outfile.close(); return 0; } void evaluateExpression(ifstream& inpF, ofstream& outF, stackType & stack, char& ch, bool& isExpOk) { double num; while (ch != '=') { switch (ch) { case '#': inpF >> num; outF > ch; outF & stack, char& ch, bool& isExpOk) { double op1, op2; if (stack.isEmptyStack()) { out stack, bool isExpOk) { double result; if (isExpOk) { if (!stack.isEmptyStack()) { result = stack.top(); stack.pop(); if (stack.isEmptyStack()) outF create a stack class that contains a linked list member variable. Using a stack variable, implement the postfix evaluation algorithm. A file will be given at the command line that contains some expressions which may or may not be properly formatted postfix expressions with floating-point operands. You are only required to support the four basic mathematical operations. You are to output each expression along with an error (if it cannot be evaluated) or the evaluation of that expression (if it can be evaluated). You do not need to use iomanip. For example, if the fle exprfile contains the following lines: -4.3-4.3+ The output to the screen when the ./a.out exprfile command is run should be: -4.3-4.3+- -8.6 4 4invalid expression create a stack class that contains a linked list member variable. Using a stack variable, implement the postfix evaluation algorithm. A file will be given at the command line that contains some expressions which may or may not be properly formatted postfix expressions with floating-point operands. You are only required to support the four basic mathematical operations. You are to output each expression along with an error (if it cannot be evaluated) or the evaluation of that expression (if it can be evaluated). You do not need to use iomanip. For example, if the fle exprfile contains the following lines: -4.3-4.3+ The output to the screen when the ./a.out exprfile command is run should be: -4.3-4.3+- -8.6 4 4invalid expression
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started