A bank account system
The problem
Build a program that manages several kinds of bank account, with deposits, withdrawals, transfers, monthly interest and a statement for each account.
Requirements
- An abstract Account class keeps the owner, the balance and a list of transactions, all private
- Savings accounts earn monthly interest, and current accounts allow an overdraft up to a limit
- Every rule that is broken, such as a negative amount or too little money, throws an exception of your own type
- A Bank class owns all the accounts, finds them by number, and cannot be copied
- operator<< prints an account's statement
- All memory is released when the program ends
Technologies
- C++
- Classes
- Inheritance
- Virtual functions
- Exceptions
- vector and map
Step by step
- Write the abstract Account class with deposit, a pure virtual withdraw rule, and a transaction list.
- Write SavingsAccount and CurrentAccount, each with its own withdrawal rule and monthly update.
- Write the exception classes, deriving them from runtime_error, and throw them from the accounts.
- Write Bank, which owns Account pointers in a map from account number, deletes them in its destructor, and forbids copying.
- Add transfers between accounts, making sure a failed withdrawal leaves both balances unchanged.
- Write operator<< for statements, and a small command loop to drive the bank.
- Test overdrafts, transfers to a missing account, and many months of interest.
Expected result
A working bank system where each kind of account follows its own rules and every error is reported clearly.
How it is evaluated
- No balance can be changed except through the account's own member functions
- Each kind of account behaves correctly, and adding a new kind needs no change to Bank
- Every error is reported by an exception and leaves the data unchanged
- Nothing is leaked or deleted twice
Ways to improve it
- Save the accounts to a file and load them again
- Add a fixed-deposit account that cannot be withdrawn from early
- Sort statements by date or amount