#include <iostream.h>
#include <iomanip.h>
#include "checking.h"


// These methods are documented in checking.h


/**********************************************************************
 * Checking::Checking
 **********************************************************************/

Checking::Checking(int number, double balance)
: accntNumber(number), accntBalance(balance)
{
}


/**********************************************************************
 * Checking::inputTrans
 **********************************************************************/

void Checking::inputTrans(TransactionType type, double amount)
{
   switch (type)
   {
    case DEPOSIT:
      accntBalance += amount;
      break;

    case WITHDRAWAL:
      accntBalance -= amount;
      break;

    default:
      cout << "Illegal transaction code: " << char(type) << endl;
      break;
   }
}


/**********************************************************************
 * Checking::printBalance
 **********************************************************************/

void Checking::printBalance(void)
{
   // This method twiddles with output formatting.  We need to save
   // the output formatting and then restore it before returning.
   long oldPrecision;
   long oldFixed;

   cout << "The balance for account " << accntNumber << " is ";

   // Save previous formatting.
   oldPrecision = cout.precision(2);
   oldFixed = cout.setf(ios::fixed, ios::floatfield);

   cout << accntBalance << ".\n";

   // Restore previous formatting.
   cout.precision(oldPrecision);
   cout.setf(oldFixed, ios::floatfield);
}
