// File: ex7-4.cpp #include #include using namespace std; class Account { protected: unsigned long long accountNum; double balance; double intRate; // annual interest rate public: Account(unsigned long long num = 0,double bal = 0,double = 0); void deposit(double amount); void withdraw(double amount); void month_end(); friend ostream& operator<<(ostream& out, const Account& account); }; ostream& operator<<(ostream& out, const Account& account) { out << fixed << setprecision(2); out << "Account: " << account.accountNum << " balance = $" << account.balance << endl; return out; } Account::Account(unsigned long long acc_no,double init_bal,double i_rate) : accountNum(acc_no), balance(init_bal), intRate(i_rate) { cout << "* New Account\t"; cout << *this << endl; } void Account::deposit(double amount) { cout << "Account: " << accountNum << " deposit = $" << amount << endl; balance += amount; } void Account::withdraw(double amount) { cout << "Account: " << accountNum << " withdraw = $" << amount << endl; balance -= amount; } void Account::month_end() { cout << "Account month-end processing: " << accountNum << endl; balance *= (1.+intRate/12.); cout << *this << endl; } class SavingsAccount : public Account { public: SavingsAccount(long acc_no, double init_bal = 50., double i_rate = .02) : Account(acc_no,init_bal,i_rate) { } }; class CheckingAccount : public Account { private: double min_balance; double service_charge; public: CheckingAccount(unsigned long long, double, double = 300.,double = 3.,double = .01); void process_check(double amt) { withdraw(amt); } void month_end(void); }; CheckingAccount::CheckingAccount(unsigned long long acc_no, double init_bal, double min_bal, double service_chg, double i_rate) : Account(acc_no,init_bal,i_rate), min_balance(min_bal), service_charge(service_chg) { } void CheckingAccount::month_end() { cout << "Checking Account month-end processing: " << accountNum << endl; balance *= (1.+intRate/12.); if (balance < min_balance) balance -= service_charge; cout << *this << endl; } int main() { SavingsAccount Mysavings(1234560ULL,500.); CheckingAccount Mychecking(1234561ULL,1000.); Mysavings.deposit(100.); cout << Mysavings << endl; Mysavings.withdraw(200.); cout << Mysavings << endl; Mychecking.deposit(100.); cout << Mysavings << endl; Mychecking.process_check(200.); cout << Mychecking << endl; Mysavings.month_end(); Mychecking.month_end(); }