TASK

This time you will write a C++ class called "Account" which will help a bank to manage its accounts.

Here is the public interface that you are going to implement.
class Account;
  {
  public:
  int GetAccountNumber();
  int GetBalance();
  void Deposit(int amount);
  void Withdraw(int amount);
  void CancelLastTransaction();
  };
Account *GetAccount(int an);
In the beginning, there are no accounts in the bank. Accounts are identified by their account numbers. GetAccount() function returns the pointer to the Account instance whose account number is an. If such an account does not exist yet, it is created with a 0 balance.

GetAccountNumber() instance function returns the account number of the Account instance it is called for.

GetBalance() instance function returns the balance of the Account instance it is called for.

Deposit() amount dollars to the balance of the Account instance it is called for.

Withdraw() decreases the balance of the Account instnace it is called for by amount dollars. However, if the balance of the account is less than amount, this does nothing.
CancelLastTransaction() cancels the last transaction performed on the Account instance it is called for. If there is no transcation done yet, this does nothing. An unsuccessful Withdraw() is NOT counted as a transaction. If the last transaction done on the account is already cancelled, CancelLastTransaction does nothing.

Your implementation of the interface will be tested by linking it to different C++ programs making use of the class. You can link your implementation to your own testing programs by passing more than one argument to g++.

Sample Program

#include<iostream> using namespace std; class Account { public: int GetAccountNumber(); int GetBalance(); void Deposit(int amount); void Withdraw(int amount); void CancelLastTransaction(); }; Account *GetAccount(int an); int main() { Account *a1,*a2,*b1; a1=GetAccount(123); a2=GetAccount(456); b1=GetAccount(123); if(a1==b1) cout<<"YES"<<endl; else cout<<"NO"<<endl; cout<<a1->GetAccountNumber()<<endl; cout<<a1->GetBalance()<<endl; a1->Deposit(20); cout<<a1->GetBalance()<<endl; b1->Deposit(20); //intentionally b1 cout<<a1->GetBalance()<<endl; a1->Withdraw(15); cout<<a1->GetBalance()<<endl; a1->Withdraw(150); cout<<a1->GetBalance()<<endl; a1->CancelLastTransaction(); cout<<a1->GetBalance()<<endl; a1->CancelLastTransaction(); cout<<a1->GetBalance()<<endl; a2->Deposit(1000); cout<<a1->GetBalance()<<endl; cout<<a2->GetBalance()<<endl; cout<<GetAccount(789)->GetAccountNumber()<<endl; return 0; }

Sample Output

YES 123 0 20 40 25 25 40 40 40 1000 789

Hints

You may get a partial credit for implementing some of the functionality.

Notice that tour source file also should include a declaration of the Account class, probably a more detailed one than the one given in this text.

Assumptions and Constraints

You may safely assume that the number of accounts will not exceed 100.

Submission

Submit your source code(.cpp file) through the submission system.