Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

object oriented programming in C++ please read the spec carefully Assignment #3 - Evaluating Mathematical Epressions : due 1/10 Tue (at 11:59pm) A Mathematical epression

object oriented programming in C++
please read the spec carefully
image text in transcribed
image text in transcribed
Assignment \#3 - Evaluating Mathematical Epressions : due 1/10 Tue (at 11:59pm) A Mathematical epression is something like the following 2+(5(3.1(3.3)+sin(6.1)))/ log_ 2(3)(15)2, in which there is a mixture of arithmetic expression, trigonometric, and logarithmic functions. Here is a list of those 12 functions. 1. Arithmetic: +/ along with the unary , i.e. 5 2. Unary functions: sin0. cos(),tan(),log(0,log,(b)(a),sqr(0,2N{3} You should use the corresponding math functions delcared in to implement them. Remarks 1. Unary negation - inote that 5(2) must be interpreted as (5(2)) instead of (5)(2). The unary operator - acts on 5 and turns its value negative. 2. log() stands for natural log, i.e. with base e=2.718 3. log{b}(a) is ordanry logarithm with base b. Use the log( ) function in to implement log{b} (a) as log(a)/log(b). 4. sqrt\{\} is square root. Note that its syntax uses the curly braces (\} instead of the parentheses () 5. 2{3} stands for 2 raising to the third power, which is equal to 8 6. Note that, according to our syntax, the curly braces (\} are only used in logarithm's subscript log_\{b\} (a) and power's superscript 5.1 {2} 7. The operators priorities are listed as follows. Least priority: + and . Medium priority: unary negation - . High priority: * and /. Highest priority: *, sin , cos. \( \tan , \log _{\text {_ }}(\}(), \log () \), sqrt ( ). If two operators have the same priority, they should be evaluated in the left-to-right direction. Write a class Expression that holds the value of a Mathematical epression and it has two member functions input () and eval(), in which the latter evaluates the expression. We strongly suggest you use the get1ine() function to read the whole expression as a string object (remember to include ). Do not use cinstr; as it will stop on whitespaces. Use getline(cin, str); instead to read the whole line (in which str is a string object). The main function is given as follows. Do not change main() otherwise you may lose penalty points. int main () {// Do NOT CHANGE MAIN!! Expression expl; exp1. input(): expl.evali(); return 0 ; Try to explore the power of C++andmakeyourprogramasflexibleaspossible,Le.ifnew functions like sinh or tanh are added in the future, you do not need to modify too much of your work to support them. Hint You may need to use two stacks to do this assignment. One for storing the operands, and the other for storing the operators. You can use the standard library templates to do that. Include to use their templates. You also need to include and libraries. Grading \& Submission Same as Assignment $2.70% correctness and 30% style. Submit your sourcecode (with detailed comments) both on OJ and eLearn. No need to prepare a README file. Input 1 2+(5(3.1{3.3}+sin(6.1))}/log2{3}(15)2 Output 1 Input 2 Output 2

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

Students also viewed these Databases questions