Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ For this project you need to implement a scientific calculator program. This calculator should be able to read mathematical expressions and assignments, compute the

C++ For this project you need to implement a scientific calculator program. This calculator should be able to read mathematical expressions and assignments, compute the result of the expressions and execute the assignments. Expressions. A mathematical expression can be made up of numbers, variables, mathematical operations, constants, mathematical functions, and parentheses. Some examples of mathematical expressions:

Constants.

Your program should support using the following mathematical constants: Pi = 3.14169 e = 2.718 Functions.

Your program should support the use of the following mathematical functions in the expressions:

sin : the given argument is in Radian.

cos : the given argument is in Radian.

log : computes the natural logarithm of the given argument.

Assignments. An assignment is made up of a variable and an expression and is used to store the result of the expression in the variable. The format of an assignment is let = and the given variable could be used in any expression after this assignment.

Variables. The variables names are strings of alphabetical characters, i.e. a to z and A to Z. You should use a hash-map to store the values of the variables. Note that the names of the variables are case-sensitive, in other words Count and count are two different variables and can have different values. The names quit, let, Pi, e, sin, cos, log will not be used as variable names since they are reserved for constants, functions, to signal the termination of the program and to declare the variables. Some examples of assignments:

let x = 2

let count = 0

let BigValue = 2^2^(2+2^(2+2*2))

Parentheses. The parentheses will always override the order of the operations, regardless of the precedence and/or the associativity of the operators.

Whitespaces. An expression may contain any number of whitespaces between the operators, numbers, constants and parentheses.

Input/Output. Each line of input contains an expression or an assignment. If the input is an assignment your program should compute the result of the right hand side expression and update the value of the left hand side variable. Nothing should be printed for assignments. If the input is an expression, your program should compute the result of the expression and print the result to the output. The result is either a number, the string Division-By-Zero if there is a division-byzero error in the expression, or the string Undeclared-Variable if there is an undeclaredvariable error in the expression. The final line of input will be the string quit, and after your program reads that line it should terminate without printing anything. An example running of the program (input is black, output is bold):

2 + 4 / 2

4

2.3+2.7^2

9.59

4 + 3 / ( 2 4 / 2)

Division-By-Zero

4 / myVar

Undeclared-Variable

let myVar = 4

4 / myVar

1

let myVar = myVar ^ myVar

myVar

256

let x = (2 + 4 * 12 (14 - 6)*2)

myVar x*2

188

quit

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

Business Process Driven Database Design With Oracle PL SQL

Authors: Rajeev Kaula

1st Edition

1795532386, 978-1795532389

Students also viewed these Databases questions

Question

What is the output of the following statements? cout

Answered: 1 week ago

Question

Why does sin 2x + cos2x =1 ?

Answered: 1 week ago

Question

What are DNA and RNA and what is the difference between them?

Answered: 1 week ago

Question

Why do living creatures die? Can it be proved that they are reborn?

Answered: 1 week ago