Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can somebody solve the following problem in c++. //TODO //Requires the accurately convered expression as a post fix string //Effects: computes and evaluates the postfix

Can somebody solve the following problem in c++.

//TODO //Requires the accurately convered expression as a post fix string //Effects: computes and evaluates the postfix expression by performing Stack //operations, Uses multiple stacks //Modifies nothing

int evaluate(std::string postfix){ std::istringstream input(postfix); char ch; int data=0; Stack result; Stack ops;

//store the expression on the stack while (input >> ch) { if (isOperand(ch)) { data = 0; while (isOperand(ch)) { data = data * 10 + (int)(ch - 48); input >> ch; } result.push(data); continue; } } //since this reverses the postfi expression, store in another stack to //reverse the stack //if operand, store numeric value on result stack // use int(ch)-48 to convert char to integer value // if its an operator, pop two operands from result stack // apply the operator on them and store the resulting value in result stack // GIVEN //switch (ch){ // case '*': result.push(one*two); break; // case '/':result.push(one/two);break; // case '+': result.push(one+two); break; //case '-': result.push(one-two); break; // default: break;

// the final value is on the top of the stack, return this return result.pop(); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Oracle APEX 5 Application Development

Authors: Edward Sciore

2nd Edition

1484209893, 9781484209899

More Books

Students also viewed these Databases questions

Question

How does having more metadata help a tax accountant minimize taxes?

Answered: 1 week ago