Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ Programming exercise: Implement a stack-based program for evaluating arithmetic expressions containing the standard arithmetic operators +,?,?,/, as well as =. The precedence of

In C++

Programming exercise: Implement a stack-based program for evaluating arithmetic expressions containing the standard arithmetic operators +,?,?,/, as well as =. The precedence of the operators is the standard one: ?, / are at the same level of precedence, which is higher than the precedence for +, ? (same level), which itself is higher than the precedence for = (also same level).

Details and suggestions:

Use two stacks, one containing the operators and the other containing the values.

You may use the stack class in the C++ Standard Library or design your own.

The input is a string of alternating integers and operators, separated by one space.

The first and the last element of the input will be a number.

You may assume that the expression contains at most 1 operator of type =.

If it does, it evaluates to either true or false; otherwise, it evaluates to a number. You may use the strtok command to get the operands contained in the input string. Provide an implementation of your algorithm in a file called EE.cpp. The main function should accept the string, parse it, and print out the value it has. Bonus: test the input string and throw the BadExpression exception if needed.

image text in transcribed

Test cases (you must make sure your program works on these): On input your program should print out 0.6. On input "12-3*2+?, your program should print out 13. On input your program should print out false. If you are attempting the bonus questi "14 ?= 4-3*2+1?= 16" your program should throw the BadExpression exception. on, on input

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

Step: 3

blur-text-image

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

Database Concepts

Authors: David M Kroenke, David J Auer

6th Edition

0132742926, 978-0132742924

More Books

Students also viewed these Databases questions

Question

Question How are VEBA assets allocated when a plan terminates?

Answered: 1 week ago

Question

Question May a taxpayer roll over money from an IRA to an HSA?

Answered: 1 week ago

Question

Question What is the doughnut hole in HSA coverage?

Answered: 1 week ago