/*	AccountClass class implementation */

#include <iostream.h>
#include <lvpvector.h>
#include <lvpstring.h>

using namespace std;	// October 5, 2001

//--------------------------------------------------------------------------------
AccountClass::AccountClass(lvpstring AcctName, lvpstring AcctOpenDate)
	: Name(AcctName), OpenDate(AcctOpenDate), Balance(0),
	TransDates(0), TransKinds(0), TransAmts(0)
/*	Opens AcctName account on AcctOpenDate.
	Post: AcctName balance is zero, and transaction recorded */
{
}
//--------------------------------------------------------------------------------
void AccountClass::Deposit(double Amt, lvpstring Date)
/*	Adds deposit to Acct and records transaction
	Post: Amt added to account, and transaction recorded */
{
	Balance += Amt;
	TransDates.resize(TransDates.length() + 1);
	TransDates[TransDates.length()-1] = Date;

	TransKinds.resize(TransKinds.length() + 1);
	TransKinds[TransKinds.length()-1] = "Deposit";

	TransAmts.resize(TransAmts.length() + 1);
	TransAmts[TransAmts.length()-1] = Amt;
}
//--------------------------------------------------------------------------------
bool AccountClass::Withdrawal(double Amt, lvpstring Date)
/*	Subtracts withdrawal from account and records transaction
	Post: if Amt<=Balance, Amt deleted from account, transaction recorded,
	and true returned. Otherwise, false returned, attempt recorded, 
	and balance unchanged.                                                                              */
{
	TransDates.resize(TransDates.length() + 1);
	TransDates[TransDates.length()-1] = Date;
	TransKinds.resize(TransKinds.length() + 1);
	TransAmts.resize(TransAmts.length() + 1);
	TransAmts[TransAmts.length()-1] = Amt;
	if (Amt <= Balance) {
		Balance -= Amt;
		TransKinds[TransKinds.length()-1] = "Withdrawal";
		return(true);
	}
	else {
		TransKinds[TransKinds.length()-1] = "Withdrawal/Failed";
		return(false);
	}
}
//--------------------------------------------------------------------------------
double AccountClass::GetBalance() const
/*	Determines current balance
	Post: Current balance returned */
{
	return (Balance);
}
//--------------------------------------------------------------------------------
void AccountClass::WriteTransactions(ostream & OutFile) const
/*	Writes transactions to OutFile
	Post: All information about the account written to OutFile,
	including a list of all transactions.                                        */
{
	OutFile.setf(ios::fixed);
	OutFile.precision(2);
	OutFile << Name << endl;
	OutFile << "Acct opened on " << OpenDate << " Balance: "
	<< Balance << endl;
	OutFile << "Transactions" << endl;
	for (int i=0; i<TransDates.length(); i++) {
		OutFile.width(12); OutFile << TransDates[i];
		OutFile.width(22); OutFile << TransKinds[i];
		OutFile.width(12); OutFile << TransAmts[i] << endl;
	}
}

