// @(#)$Id: PlusAccount.C,v 1.7 1997/07/24 21:49:13 leavens Exp $

#include "PlusAccount.h"

PlusAccount::PlusAccount(Money savings_balance,
                         Money checking_balance,
			 const char * name) throw()
   : BankAccount(savings_balance, name), chk_bal(new Money(checking_balance))
{
}

PlusAccount::~PlusAccount() throw()
{
}

// the functions below leak memory (:->)

Money PlusAccount::balance() const throw()
{
  return (*chk_bal) + BankAccount::balance();
}

void PlusAccount::pay_interest(double rate) throw()
{
  BankAccount::pay_interest(rate);
  chk_bal = & ((*chk_bal) * (1.0 + rate));
}

void PlusAccount::withdraw(Money amt) throw()
{
  Money bal = BankAccount::balance();
  if (bal >= amt) {
    BankAccount::withdraw(amt);
  } else {
    chk_bal = & (amt - bal);
    BankAccount::withdraw(bal);
  }
}

void PlusAccount::checking_deposit(Money amt) throw()
{
  chk_bal = & (*chk_bal + amt);
}

void PlusAccount::pay_check(Money amt) throw()
{
 if ((*chk_bal) >= amt) {
   chk_bal = & (*chk_bal - amt);
 } else {
   BankAccount::withdraw(amt - *chk_bal);
   chk_bal = new Money(0L);
 }
}

