Previous Section  < Free Open Study >  Next Section

The Bank.hpp File


// Bank.hpp: This is the header file for the main classes that 

// exist solely on the Bank side of the application.



#ifndef _BANK_

#define _BANK_



#define BANK_SIDE



#include ''consts.hpp''

#include ''trans.hpp''

#include ''network.hpp''



// Forward class declarations.

class Bank;



// The Account class contains the account number, the PIN number,

// and the balance. While Accounts seem to have a type on the ATM

// side of the application, this type becomes a suffix letter (S or

// C) on the account number on the Bank side of the application.

// The get_balance method is used by Balance::process, which must

// be able to get its current balance from the account for return to

// the ATM user. 

class Account {

      char account_name[small_string];

      char pin[small_string];

      double balance;

public:

  Account(char* acc_name, char* p, double amount = 0.0);

  double get_balance();

// The verify_account method checks that the account name and PIN 

// number passed in are equal to that of the account.

   int verify_account(char* acc_name, char* p);

// The check_balance method ensures that the account balance is at

//least ''amount'' in value. The modify_balance will add the

// amount argument to the balance of the account. Deposits modify

// with a positive amount, Withdrawals modify with a negative

// amount, and transfers do both.

   int check_balance(double amount);

   void modify balance(double amount);

// The equal method checks if the account name passed in is equal to

// that of the account. This is used by the find_account method of

// the AccountList class.

   int equal(char* acc_name);

   void print(FILE*);

   };





class AccountList{

      Account** accountList;

      int accountnum;

      unsigned size;

public:

     AccountList(unsigned sz);

     AccountList(unsigned sz, const char* AccountFile);

     ~AccountList();

     Account* find_account(char* acc_num);

     int add_account(Account* a);

     void print(FILE* fd);

};





// The ATMProxy is a very important class in the design of this

// application. It is the representative of the real ATM within the

// Bank application's address space. While its counterpart, the

// BankProxy in the ATM application, is mostly reactive, the

// BankProxy is proactive. It must know who its Bank object is so it

// can send it messages whenever the network delivers a request to

// process a transaction. The Network class is a wrapper for an

// appropriate byte-delivery mechanism (files, pipes, sockets,

// TCP\IP, a squirrel with the information on a piece of paper so it

// can type it in with its nose, etc.). The activate method is the

// main driver of the Bank application. The Bank acts as a general

// server for this class.

class ATMProxy{

      Bank* bank;

   Network* network;

public:

     ATMProxy(Bank* b, Network* n);

     void activate();

};





// The Bank is constructed from a data file of accounts. In a

// real-world bank application, the bank would undoubtedly have

// many more responsibilities. The big one for this application is

// the processing of transactions.

class Bank {

     AccountList* accountList;

     TransactionList* transList;

public:

     Bank(unsigned sz, const char* accounts_file);

     ~Bank();

     int add_account(char* account_num, char* pin, double

balance = 0.0);

     int process(Transaction* t);

};



#endif

    Previous Section  < Free Open Study >  Next Section