petervanhoef / Calculator-Brain

My solutions for CS193P Winter 2017 Assignment II: Calculator Brain

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Task 10: Add an Undo button

petervanhoef opened this issue · comments

Add an Undo button to your Calculator. In Assignment 1’s Extra Credit, you might have added a “backspace” button. Here we’re talking about combining both backspace and actual undo into a single button. If the user is in the middle of entering a number, this Undo button should be backspace. When the user is not in the middle of entering a number, it should undo the last thing that was done in the CalculatorBrain. Do not undo the storing of M’s value (but DO undo the setting of a variable as an operand).

See hint 10:
Without undo, it’s only possible to enter numeric values for M. If you try to store anything else as the value of M (for example, π, or 23÷2), that expression becomes the new active expression in the calculator, replacing the one you wanted to evaluate in the first place. Once you have undo, though, you can back up to the previous expression after setting M. For example, enter M cos, then π, then →M, then undo (to get rid of the π) ... now your calculator will show the value of cos(M) which should be -1.