Please note, this blog entry is from a previous course. You might want to check out the current one.
Add the capability to your CalculatorBrain to allow the pushing of variables onto its internal stack. Do so by implementing the following API in your CalculatorBrain …
func pushOperand(symbol: String) -> Double? var variableValues: Dictionary<String,Double>These must do exactly what you would imagine they would: the first pushes a “variable” onto your brain’s internal stack (e.g. pushOperand(“x”) would push a variable named x) and the second lets users of the CalculatorBrain set the value for any variable they wish (e.g. brain.variableValues[“x”] = 35.0). pushOperand should return the result of evaluate() after having pushed the variable (just like the other pushOperand does).
Implementing the push method looks just like the existing one, the only difference is that we append a variable instead of an operand:
func pushOperand(symbol: String) -> Double? { opStack.append(Op.Variable(symbol)) return evaluate() }
Continue reading “cs193p – Project #2 Assignment #2 Task #5”