#include #include #include #include using namespace std; class account { string nm; long bal; // balance is in pennies (or smaller) public: // account(string n) : nm(n), bal(0) {} account(string n, long initial_bal = 0) : nm(n), bal(initial_bal) { // check the invariant! if (nm == "" || bal < 0) throw runtime_error("account(): invalid parameters"); } string name() const { return nm; } long balance() const { return bal; } long deposit(long amount) { // can also do withdraw // check the invariant! account tmp(nm, bal+amount); bal = tmp.bal; return bal; } long withdraw(long amount) { return deposit(-amount); // re-use code, don't copy-paste!!! } };