#pragma once #include "stack.h" class Calculator { public: double value; //calculator's current value stack history; Calculator() { value =0; } Calculator(double x) { value = x; } void clear() { history.push(value); value = 0; } void add(double x) { history.push(value); value = value + x; //equivalent: value += x; } void divide(double x) { history.push(value); value = value / x; //or: value /= x; } void multiply(double x) { history.push(value); value = value * x; //or: value *= x; } void subtract(double x) { history.push(value); value = value - x; //or: value -= x; } void undo() { value = history.pop(); } double display() { return value; } };