# write simple calculator using unorder map

Write a simple calculator program that will evaluate equations. When started, the user will type in an equation, in the form:

[variable] = [operand] [operator] [operand]

where [variable] must be a one-word name of a variable that does not start with a digit or -, [operand] is an integer or variable name, and [operator] is one of +, -, *, /, and %. If the equation was valid, the calculator program should output the value that was stored in the variable. The calculator program should be able to throw 3 types of exceptions: BadOperatorException (operator that’s not +-*/%), UninitializedVariable exception (putting a variable on the RHS that hasn’t been assigned a value), and BadEquationException (an equation that doesn’t have all 5 parts).

You have been provided a driver and header file; you just need to provide implementations for the functions in the header. Individual functions are described in comments in the header file. One of the first lines in your source file (after including the header) should be

unordered_map<string, int> Variable::vars;

The Variable class has a static data member named vars that stores all of the variable values, and this line initializes that static variable.

**Starting files:**

**Sample input:**

x = 1 + 2

y = x * 14

z = y – 5

z = y / 5

m = y % z

x = m – z

x = x * x

bad equation

x = undefined – undefined

x = x + 0

x = y = z

x = x – 0

y = y * 1

z = z / 1

quit

**Sample output:**

x = 1 + 2

3

y = x * 14

42

z = y – 5

37

z = y / 5

8

m = y % z

2

x = m – z

-6

x = x * x

36

bad equation

The equation does not have 5 parts: [variable] = [operand] [operator] [operand]

x = undefined – undefined

Variable is not initialized

x = x + 0

36

x = y = z

Your operator is invalid

x = x – 0

36

y = y * 1

42

z = z / 1

8

quit