CS302 / Program 6

Sections 15 & 22
Instructor: Colby O'Donnell

Due Date: Wednesday, Nov 26, 8:30 AM


Fir$t Virtual Bank


Program Six will demonstrate the use of classes. In this program you will be implementing a banking system. With this system, users can access their bank accounts from one or more ATMs (Automated Teller Machines). Each account is associated with a bank, and each ATM is associated with a single bank. A bank can be be associated with several accounts and several ATMs, however. You will write the code for the ATM (Automated Teller Machine) class, and the Account class. We have provided you with a header file for each of the classes, bank.h, atm.h, and account.h. You should not need to modify these header files (so don't!) The only file you will need to modify is atm.cpp. This file contains a skeleton for the member functions you will need to write. The file also includes some functions (such as main) which we have provided for you.

The Bank Class

The Bank class has been provided for you as an object file (you will not have access to the source file). You will need to add the file bank.obj to your project (see Getting Started for information on how to add this file to your project). The definition of the Bank class is provided in the file bank.h.

The Bank class consists of multiple accounts, and provides methods for making deposits, withdrawals, and balance inquiries. The class also provides methods for verifying account ID's and PIN numbers. For simplicity, new accounts cannot be created and current accounts can not be deleted. The current accounts, associated with each Bank object are loaded from an input file which is specified in the constructor. The Bank class performs most of it's tasks by calling member functions of the appropriate account.

The ATM Class

Each ATM has a Bank associated with it, along with other properties, such as a name, the number of transactions processed, the amount of money available, etc. The definition of the ATM class can be found in atm.h.

Each ATM object has a limited amount of cash (initially specified in the constructor). Cash that has been deposited at the ATM is added to this pool of cash, while cash withdrawals are taken from this pool of cash. If a withdrawal is requested for more cash than the ATM object has available, then an error message should be displayed, and the withdrawal denied. The ATM class has member functions for logging a customer in, logging a customer out, withdrawing, and depositing money from the current user's account, and checking the current balance of the user's account. Each transaction the user performs (transactions are: withdrawals, deposits, and balance checks) should be added to a receipt, which can be printed when the user logs out of the ATM machine (i.e. when the logout method is called). You can make your receipt as fancy as you want, as long as it contains the basic information. The sample executable has a fairly fancy receipt. The ATM class performs most of its tasks by calling methods of the Bank class with which the ATM is associated. (Note that there is no direct connection between ATM objects and Account objects!)

The Account Class

The Account class is responsible for keeping track of the current balance of an account, as well as the ID and PIN number of the account and the account owner's name.

The Account class has member functions for updating the current balance for an account, returning the current balance, as well as methods for checking ID's and PIN numbers. Lastly, the += and -= operators have been overloaded for performing deposits and withdrawals, respectively. The Account class should not handle checking to make sure the amount of money in the account stays positive -- this is up to the Bank object which holds the Account.

Getting Started

You will need to do the following before you can start working on this assignment:
  1. Create a new project (as you have done previously).
  2. Copy the files atm.cpp, atm.h, bank.h, account.h, bank.obj, tyme.dat, trans1.dat from P:\course\cs302\public\html\C++\atm\ to your project directory.
  3. Go to the Project menu, select Add To Project/Files and add all those files (except for the .dat files) to the project. (Don't forget the .obj file.)
  4. If you want to view the .dat files, you could do so by choosing File/Open... in Visual C++. I haven't tried, but you might also be able to add them to the project.

Data Files and Testing

The data files for this program are all in the P:\course\cs302\public\html\C++\atm\ directory. We have this path defined as a constant string given at the top of atm.cpp. If you wanted to change this directory, you should just have to change the string.

Bank objects need to be passed the name of a file inside their constructor. This file contains the information about their accounts. Currently the program will always look at the file "tyme.dat" in the directory given above, but again, you may wish to change that for testing purposes.

We have provided two means of testing your ATM and account code, by keyboard input or by file input. In both cases the format of the interaction with the ATM is the same -- it's just the input type that differs. You give input as a series of transactions followed by the word END. Files should have END as their last line.

Each transaction starts off with the name of the ATM it's directed to: either "state", "grocery", or "CS". You can abbreviate these with their first letter and case doesn't matter. After that, the transaction is a series of commands ending with a Logout command. Possible commands are:

  • L id pin --> Login with ID number id, and pin number pin. This should be the first command given in a "proper" interaction, but your ATM should be able to handle people who try and do transactions without logging in. (id and pin should both be integers)
  • W number --> Withdraw number amount of money from the account.
  • D number --> Deposit number amount of money in the account
  • B --> report the balance of the account
  • X Y or X N --> logout, and give a receipt (X Y) or don't (X N). This ends the transaction.
You can see a sample transaction file at P:\course\cs302\public\html\C++\atm\trans1.dat If you would like to use this file, you can just type "trans1.dat" when the program asks you what file to use, since the P:\...\atm\ path is hard-coded in by default (see start of this section).

Handin Procedure

Electronically submit one C++ source file, called "atm.cpp" and an executable called "program6.exe" (all lower case). You will not receive full credit for this assignment if your source files are improperly named or if you handin any other files besides those.

Hints

  • Do the Account class first: most of the methods are very easy to do and will get you used to working with classes.
  • Read the comments carefully! There are a number of special cases to check for, and you need to make sure to handle them (for instance, what happens if I try and withdraw a negative amount of money?)
  • Look at the sample executable: it's in P:\course\cs302\public\html\C++\atm\atm.exe and is fancier than what you need to do, but is pretty good about covering all possible situations.
  • Even if you don't start coding this project right away, make sure you know how to get the .obj file and the .h files included in the project correctly within a day or two, or you won't be able to work later on.

(Last modified: 11/24/97)