/* * Minimal C++ BankAccount class * CSE 374 demo, 12/07-12/15, HP * * This file contains both the class declaration and the full implementation. * In real code these would be split into header and implementation files. */ #include using namespace std; // Class Specification class BAccount { public: // constructor BAccount(int number, int balance); // methods virtual int get_account(); virtual int get_balance(); virtual void deposit(int amount); private: // instance variables int number; // account number int balance; // current balance }; // Implementation // Same as earlier C++ object examples, except that the "this" // pointer is used explicitly instead of letting the compiler // fill it in. // constructor BAccount::BAccount(int number, int balance) { this->number = number; this->balance = balance; } // methods int BAccount::get_account() { return this->number; } int BAccount::get_balance() { return this->balance; } void BAccount::deposit(int amount) { this->balance += amount; } // test int main() { BAccount *one = new BAccount(17,0); one->deposit(100); cout << "balance is " << one->get_balance() << endl; BAccount *two = new BAccount(42,500); cout << "balance is " << two->get_balance() << endl; delete one; delete two; return 0; }