// A bank account class #include "stdafx.h" #include #include #include class Account { // private members are those that cannot be changed directly by the owner // of the account. The bank has access to them and may change them. private: double balance; std::string name; // the interest rate both constant, and static. This means the value // is the same (const) for all instances of the class, so we only need // one version (static) static const double interestRate; public: // public access // here the public or account user can change the // balance only by depositing cash (using deposit function) // or by withdrawing cash (using withdraw) void withdraw(double amount) // withdraw cash { balance = balance - amount;} void deposit(double amount) // deposit cash { balance = balance + amount;} void endYear() // pay interest at the end of the Year { balance = (1+interestRate)*balance; } void printBalance() { std::cout << name <<"'s balance is " << balance << " \n"; } // constructor function, can't use defaults now // as we need to specify a name when we open the account Account(int initial_balance,std::string name_) { balance = initial_balance; name=name_;} }; // static members must be initialised outside the class const double Account::interestRate=0.05; // make a Bank class to store a set of bank accounts class Bank { //make everything public at the start public: // storage for the accounts std::vector accounts; // pay interest into all accounts void endYear() { for(int i=0;i