
// File: account.h
 
#include <iostream>
using namespace std;

//  The base class, with all member inlined
class Account {
public:
  // The constructor just records the initial balance, which
  // defaults to 0.0
  Account( double bal = 0.0 ) : balance(bal) {}

  // The deposit member function assumes the amount to be
  // deposited is non-negative and therefore does not check it.
  void deposit( double amt ) { balance += amt; }

  //  Just return the balance.
  double get_balance( ) const { return balance; }
  
protected:
  // private:
  double balance;  // the account's current balance
};


class SavingsAccount : public Account {
public:
  SavingsAccount( double bal = 5000000,    // Initial balance
                   double pct = 5.0 );  // percentage interest rate

  double compound( );  // computes and deposits interest
  double withdraw( double amt );   // attempt withdrawl

protected:
  double rate;  // periodic interest rate
};


class CheckingAccount :  public Account {
public:
  //  The constructor which is defined in account.C
  CheckingAccount( double bal = 0.0,   // initial balance
		   double lim = 500.0, // lower limit for free checking  
		   double chg = 0.50 ); // per check charge

  // Cash a check assuming the amt is positive.  Check, however to see 
  // if it would cause an overdraft: if so, return 0.0 without
  // changing the balance.  Otherwise, return the amount charged to
  // the account, which includes a charge if the balance is less than
  // the limit.
  double cash_chk( double amt );

protected:
  double limit;    // lower limit for free checking
  double charge;   // per check charge
};



//  For a time savings account, the only funds available for withdrawl
//  are the interest earnings.  This is declared as derived class of
//  SavingsAccount, and it redefines two member functions from
//  SavingsAccount.

class TimeAccount : public SavingsAccount {
public:
  //  The constructor which is defined in account.C
  TimeAccount( double bal = 0.0,    // initial balance
	       double pct = 5.0 );  // percentage interest rate

  double compound( );             // redefinition
  double withdraw( double amt );  // redefinition
  double get_avail() const { return funds_avail; };

protected:
  double funds_avail;  // amount available for withdrawl
};


