CEng242 Homework 4
Due 28th April 2002

In this homework, you will implement a simple account management application for banking in C++. You will implement three basic classes. Each Bank class object has a name (name of the bank) attribute and may contain a group of Account objects . There is no limit in the number of Account objects that a Bank object may contain.

An Account object will contain the account information of a customer. Basic account information consists of the account id which is an integer, name of the account owner which is a string with at most 40 characters long, and current amount of money which is a double value. Also each account object will keep track of all past transactions on this account. Again there is no limit in the number of transactions.

Transaction class consists of: a TransType value which is the type of the transaction, a Money typed value, and timestamp of the transaction including the date and time in precision of seconds. Also if type of the transaction is a transfer (TRANSIN or TRANSOUT) then it should contain the account id and account owner name information of the transfer account as well.

Since transactions can be in 3 different currencies, you will use the Money value given below instead of a single double value. amount in Money structure will be multiplied by the rate to calculate the exact amount. Since rate may be different for different transactions, it will be kept as a part of each transaction. You are given the following class prototypes for your objects:

#include<time.h>
enum Exception {NEGATIVEAMOUNT, NEGATIVERATE, NOTENOUGHAMOUNT,
                ACCOUNTNOTFOUND, ACCOUNTEXISTS};
enum Currency {TL,EURO,DOLAR} type;
enum TransType {OPEN,WITHDRAW,DEPOSIT,TRANSIN,TRANSOUT};
struct Money {
        Currency type;
        double amount;
        double rate;
        Money(double amnt=0.0,Currency ty=TL, double rt=1.0) {
              amount=amnt; type=ty; rate=rt; }
};

class Transaction {
        /* your implementation here */
public:
        Transaction(TransType, Money);
        Transaction(TransType, Money,int,const char []);
        double operator! ();
	int operator< (Transaction &);
friend  ostream & operator<< (ostream &,Transaction &);
};


class Account {
        /* your implementation here */
public:
        Account(int,const char[],Money);
        Account(int,const char[]);
        Account(Account &);
        int getid();
        const char * getname();
        double getamount();
        Account & operator= (Account &);
        Account & operator+ (Money);
        Account & operator- (Money);
        Account & transferto(Account &,Money);
        Account & transferfrom(Account &,Money);
        Account & operator|=(Account &);
friend ostream & operator<< (ostream &,Account &);
}


class Bank {
        /* your implementation here */
public:
        Bank(const char []);
        Bank(Bank &);
        void newAccount(int,const char[]);
        void newAccount(int,const char[],Money);
        Bank & operator=(Bank &);
        Account &operator[](int);
        Account &operator[](const char []);
        void deleteAccount(int);
        void deleteAccount(const char[]);
friend ostream & operator<< (ostream &,Bank &);
}

For Transaction class, member functions are described as:

operator!()

Will return the exact amount of the transaction on the account in TL. Withdrawals and transfers to another account will return a negative value and others will return a positive value.
operator<(Transaction &)

Will return if the timestamp of current transaction is less than the timestamp of the first parameter. If true 1 is returned, otherwise (timestamps are equal or current transaction has a larger value) 0 is returned.
<<(...)

Not a member function but a friend declaration to extend iostream operators for this class. Will output a single line transaction information on the given stream.

For Account class, member functions are described as:

Account(int,const char [],Money)

Constructor which will set the basic attributes account id and account owner name and inserts the first OPEN transaction. Third parameter is the initial amount of the account
Account(int,const char [])

Constructor which will set the basic attributes and inserts the first OPEN transaction with 0 TL initial amount.
getid()

Will return the integer account id.
getname()

Will return the account owner name.
getamount()

Will return the current amount in the account.
operator=(Account&)

Will copy the transaction and amount information from one Account to the current account. Account id and owner name will be kept as the same and old transactions will be cleared. Returns the reference to current account.
operator+(Money)

Adds a DEPOSIT transaction to current account and modifies the totals accordingly. Returns the reference to current account.
operator-(Money)

Adds a WITHDRAW transaction to current account and modifies the totals accordingly. Returns the reference to current account.
transferto(Account &,Money)

Adds a TRANSOUT (money transfer to another account) transaction to current account and modifies the totals accordingly. First parameter is the destination account of the money. Note that, it will also cause a TRANSIN transaction to the first parameter. Returns the reference to current account.
transferfrom(Account &,Money)

Adds a TRANSIN (money transfer from another account) transaction to current account and modifies the totals accordingly. First parameter is the source account of the money. Note that, it will also cause a TRANSOUT transaction to the first parameter. Returns the reference to current account.
operator|=(Account &)

Merges the transactions from current object and the first parameter object into the current object and returns a reference to the current object. Merging results in the initial amount of accounts (OPEN transactions) are summed (merged into a single OPEN) and all other transactions are sorted chronologically and applied cumulatively to the total amount.
<<(...)

Not a member function but a friend declaration to extend iostream operators for this class. Will print basic account information and a listing of all transactions chronologically.

For Bank class, member functions are described as:

Bank(const char [])

Constructor which will also set the name of the bank.
newAccount(...)

Opens a new account in the current Bank object. One version is for an account with a non-0 initial amount, the other version is for a 0 initial amount. It should create and insert a new account to the data structure kept inside of the Bank object.
operator=(Bank &)

Copies all accounts in the first parameter Bank to the current bank. All accounts will be cleared. Returns the reference of the current bank.
operator[](int)

Finds and returns the reference of the account with the given id.
operator[](const char[])

Finds and returns the reference of the account with the given account owner name. Name match will be case insensitive.
deleteAccount(...)

Closes and deletes the given account.
<<(...)

Not a member function but a friend declaration to extend iostream operators for this class. Will print a list of accounts in the current bank. Listing will contain the bank name and for all accounts id, owner and current amount.

Output format for Transaction is given as follows:

Character 1-4:
Type of the transaction (left aligned). `Open', `Wit.', `Dep.', `TrFr', `TrTo' strings will be used.
Character 6-19:
Timestamp of the transaction. Use strftime() function with "%d-%m-%y %H:%M" format.
Character 21-35:
Optional explanation for the transfer transactions. Contains the first 10 characters from the owner name (right aligned) followed by the 5 digit right aligned account id. If not a transfer transaction, it is filled by spaces.
Character 37-46:
Amount in the currency of the transaction. If it is TL no decimal points, otherwise 2 decimal points after dot.
Character 47-48:
Currency indicator (left aligned). One of `TL' `$' and `Eu' strings.
Character 50-57:
Exchange rate. No decimal dots
Character 59-69:
Effective transaction amount (in TL). It is negative or positive according to the transaction type.
Output of the line is not ended by a newline. Do not check for field overflows.

Output format for Account is given as follows:

Account id: ...
Account owner: ...
Current amount: ... TL
Op  |     Time     |  Explanation  |    Amount  | Rate   | Effective |Tot. after
----+--------------+---------------+------------+--------+-----------+----------
Open 12-04-02 13:34                    1000000TL        1     1000000    1000000
TrFr 14-04-02 10:00       Onur  123     500000TL        1      500000    1500000
Wit. 14-04-02 11:00                     800000TL        1     -800000     700000

... parts will be filled by the corresponding value. Total after part will be filled by the cumulative amount so far after the transaction.

Output format for Bank is given as follows:

Bank name:...
Account id|    Account owner                         |Current amount(TL)
----------+------------------------------------------+----------------
......
Column fields are: Account id (1-10, right aligned), Account owner (12-53, left aligned), Current amount (55-70, right aligned, no decimal dot). Accounts will be listed in increasing order of account id.

You should consider all errors and raise the corresponding value from Exception data type. You should implement destructors of dynamic storage classes so that no garbage should be produced. Also your implementation should not contain any auxiliary functions or other public member functions. All other functions should be private class members.

You can use i=time(NULL);...=localtime(&i); call to get the current time of the system. See manual pages of localtime, time and strftime for details.

Submission details and examples will be given later.



1