logo CodeStepByStep logo

evaluateMathExpression

Language/Type: C++ recursion string return
Related Links:

Write a recursive function named evaluateMathExpression that accepts a string parameter representing a math expression on integers and returns the result of that math expression. The expression will consist of single-digit integers and possible operators. All operators will be surrounded by parentheses; we would say that the expression is fully parenthesized. The operators will be either + or *. For example, the call of evaluateMathExpression("((1+2)*(3+1)+(1*(2+2)))") should return xxxx . You may assume that the string is non-empty and does not contain any other characters.

Constraints: Your code must be recursive and not use any loops. Do not declare any global variables or any auxiliary data structures. You can declare as many primitive variables and strings as you like.

Function: Write a C++ function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.