C++ Programming Exercise: Implement a command-line calculator that allows the user to enter an expre

C++ Programming Exercise:

Implement a command-line calculator that allows the user to enter an expression containing numbers, variables, brackets, and operators. The calculator will also allow assignments to a variable. After the user enters the expression the program will evaluate it and display the value. If the expression is part of an assignment its value will be also be stored in the variable. The operators are +, -, *, /, % and ^ (exponentiation). (These are all binary operators.) % should be applicable to floating point numbers and work like it does in Java. There are three types of bracket: parentheses ( ( ) ) , square brackets ( [ ] ) and braces ( {} ). A variable may be any single lowercase letter. (Uninitialized variables can have any value.) The calculator will loop until the user enters a blank line. Here is a sample run below:

> 3 + 4.5

7.5

> a = 6*2/5

2.4

> b = a+1

3.4

> b

3.4

> c = b^2

11.56

> a * {b A????1 (c + 0.84)}

-21.6

> 7.5 % 3

1.5

> 5 % -2

1

> -5 % 2

-1

> a = 1 / 0

infinity

> 1 / a

0

> a / a

NaN

> d = (-1)^0.5

NaN

> d / d

NaN

> + 4 5

illegal expression

> 4 + -c

illegal expression

>

Bye!

Use a two step process (infix -> postfix -> value). Provide a debugging mode where you also output the equivalent postfix expression:

> 5 + 4 * 2

5 4 2 * +

13

>

Convert all input to type double and display results with reasonable precision. The default precision is probably OK (e.g. 0.333333 for 1/3.0). DonA????1t add A????1bells and whistlesA????1 or make those things part of a mode that can be turned on or off. Input should be accepted with or without spaces. For example 2+2, 2 +2 and 2 + 2 should all work. A minus sign can be part of a number (e.g. 4+-6) or a binary operator (e.g. 4A????1a). A minus is never a unary operator (so 4+-a would be illegal).

Can someone give me the code for this programming problem?

Need your ASSIGNMENT done? Use our paper writing service to score better and meet your deadline.


Click Here to Make an Order Click Here to Hire a Writer