/*	Improved bank account class which maintains and 
	can display a list of all transactions on the account     */

#ifndef _ACCOUNTCLASS_
#define _ACCOUNTCLASS_

#include <fstream.h>
#include <iostream.h>
//#include <lvp\bool.h>
#include <lvpstring.h>
#include <lvpvector.h>
#include "date.h"

using namespace std;	// October 5, 2001

class AccountClass {
public:
	AccountClass();
	/* Default constructor */
	
	AccountClass(lvpstring AcctName, DateClass AcctOpenDate);
	/*	Opens AcctName account on AcctOpenDate.
		Post: AcctName balance is zero, and transaction recorded */

	void SpecifyAccount(lvpstring AcctName, DateClass AcctOpenDate);
	/*	Assigns AcctName and AcctOpenDate to account if account not initialized
	Post: AcctName assigned to Name and AcctOpenDate assigned to
	OpenDate if account was not already initialized. IsOpen is true.                */

	
	bool Deposit(double Amt, DateClass Date);
	/*	Post: If account open, adds deposit to Acct, records transaction, 
		and returns true; returns false otherwise.                                      */

	bool Withdrawal(double Amt, DateClass Date);
	/*	Post: if Amt<=Balance, Amt deleted from account,
		transaction recorded, and true returned. Otherwise, false returned, 
		attempt recorded, and balance unchanged.                                        */

	//Access functions that return account information
   DateClass GetOpenDate() const;
	/*	Post: Account open date returned. */

	lvpstring GetName() const;
	/*	Post: Name returned          */ 

	double GetBalance() const;
	/*	Post: Current balance returned */

	//Access functions that return transaction information
	int GetTransCount() const;
	/*	Post: Number of transactions returned */

	DateClass GetTransDate(int TransNum) const;
	/*	Post: Date of transaction returned */

	lvpstring GetTransKind(int TransNum) const;
	/*	Post: Type of transaction returned */

	double GetTransAmt(int TransNum) const;
	/*	Post: Amount of transaction returned */

	//Stream functions
	void WriteTransactions(ostream & OutFile) const;
	/*	Writes transactions to OutFile
		Post: All information about the account written to OutFile,
		including all transactions in order by date.                         */

	void Store(ostream & OutFile) const;
	/*	Pre: InFile is open
		Post: Account written in standard format to OutFile */

	void Retrieve(istream & InFile);
	/*	Pre: InFile is open and positioned at a properly formatted account
		Post: Next account has been read from InFile into account              */

private:
   bool IsOpen; 
	lvpstring Name;
	DateClass OpenDate;
	double Balance;
	lvpvector<DateClass> TransDates;
	lvpvector<lvpstring> TransKinds;
	lvpvector<double> TransAmts;

   void AddTransaction(lvpstring Kind, DateClass Date, double Amt);
	/*	Post: Transaction recorded at appropriate position by date. */
};

#include "account3.cpp"
#endif 
 
