Assignment 5


In this assignment, you will write a main program and several classes to create and print a small collection of bank accounts. You will also apply deposit and withdrawal transactions to those bank accounts.

1. Initial Setup


  1. Log in to Unix.

  2. Run the setup script for Assignment 5 by typing:

        setup 5
    

2. Input


Input for this program consists of two files.

The first file, named accounts, contains a single bank object written out in binary format. This object will be read by the read_accounts() member function of the bank class (see the member function description below for additional details). Since this is a binary file, you will not be able to read the data in it using the >> operator. See the notes on the course website covering Binary Input and Output / Object Serialization for a description of the technique you will need to use to read this file. Note that reading an entire bank object using ifstream::read() will be very similar to the code in the notes that reads an entire Course object.

The second file, named transactions.txt, contains a series of transaction records in ASCII character format, which means that you can use the >> operator to read the fields of these records. A typical transaction is shown below. The first field on the transaction record is the date of the transaction, followed by an account number, then the transaction type ('D' for deposit or 'W' for withdrawal), and finally a transaction amount.

    06/19 1111111111 D 430.00

You will need to declare variables to hold the data read for each of these fields. To read transaction records until end of file is reached, use a loop like the following:

    while (trans_file >> date)
    {
        // Read remaining data of the transaction record.
        trans_file >> account_number;
        trans_file >> type;
        trans_file >> amount;
        
        // Process this transaction.
        . . .
    }

where trans_file is the name of the ifstream variable opened for the transaction file.

3. Files We Give You


The setup script will create the directory Assign5 under your csci241 directory. It will copy a makefile named makefile to the assignment directory. Like the makefile for Assignment 4, this makefile has only a single executable target named assign5. You can build the entire project for Assignment 5 simply by typing the command make.

Running the command make clean will remove all of the object and executable files created by the make command.

You will also receive symbolic links to the two data files named accounts and transactions.txt described above under 2. Input.

4. Files You Must Write


You will write five files for this assignment:

4.1. account.h

This header file will contain the class definition for a class called account. The account class represents information about a person's bank account. The header file should include an appropriate set of header guards to prevent it from being included more than once in the same source file.

Data Members

The account class should have the following private data members:

Note: Make that sure you code your data members in THE EXACT ORDER LISTED ABOVE and with THE EXACT SAME DATA TYPES. If you use float instead of double or only make the name array 20 characters long instead of 21, your program will not work correctly.

Member Functions

The account class definition should contain public prototypes for all of the member functions in the account.cpp source code file described below.

4.2. account.cpp

This source code file will contain the member function definitions for the account class. The required member functions are described below:

4.3. bank.h

This header file will contain the class definition for a class called bank. The bank class represents information about a collection of bank accounts. The header file should include an appropriate set of header guards to prevent it from being included more than once in the same source file.

Data Members

The bank class should have the following three private data members:

Note: Once again, make sure that you code your data members in the exact order listed above and with the exact same data types.

Member Functions

The bank class definition should contain public prototypes for all of the member functions in the bank.cpp source code file described below.

4.4. bank.cpp

This source code file will contain the member function definitions for the bank class. The required member functions are described below:

You are welcome to write additional private member functions for the bank class as you see fit. For example, you may want to put your sorting algorithm code in its own member function and call it from read_accounts() or place the binary search code in its own member function and call it from process_transactions().

4.5. main.cpp

This file will contain the program's main() function. The logic for this function is quite short:

5. Output


The correct output for this assignment is shown below:

Account Listing for First National Bank

Account Number: 1132264809
Name: Joanna Madsen
Balance: $2805.65

Account Number: 5540853032
Name: Trey Donner
Balance: $4850.75

Account Number: 5745648360
Name: Ronald Jones
Balance: $1340.53

Account Number: 5745734564
Name: Karin Hunt
Balance: $4476.00

Account Number: 6379094723
Name: Blake Reynolds
Balance: $2703.62

Account Number: 7307830409
Name: Jon Mitchell
Balance: $207.45

Account Number: 7415949234
Name: Susan Garcia
Balance: $3738.64

Account Number: 9858542030
Name: Keiko Tanaka
Balance: $11343.82

Transaction Report

Date    Account      Type   Amount     New Balance

08/19   1130034922   D       5500.00   *** Invalid account number ***
08/19   5540853032   W        430.00    4420.75
08/20   7415949234   D       3620.45    7359.09
08/20   9858542030   W        130.00   11213.82
08/20   1132264809   W       3275.23   *** Insufficient funds ***
08/20   6379094723   W        250.00    2453.62

Account Listing for First National Bank

Account Number: 1132264809
Name: Joanna Madsen
Balance: $2805.65

Account Number: 5540853032
Name: Trey Donner
Balance: $4420.75

Account Number: 5745648360
Name: Ronald Jones
Balance: $1340.53

Account Number: 5745734564
Name: Karin Hunt
Balance: $4476.00

Account Number: 6379094723
Name: Blake Reynolds
Balance: $2453.62

Account Number: 7307830409
Name: Jon Mitchell
Balance: $207.45

Account Number: 7415949234
Name: Susan Garcia
Balance: $7359.09

Account Number: 9858542030
Name: Keiko Tanaka
Balance: $11213.82

If you would like a copy of this output to compare against your own program's output using the diff command, it is available on Unix at the pathname /home/turing/t90kjm1/CS241/Output/Spring2021/Assign5/output5.txt.

6. Hints


Like Assignment 4, this assignment has a lot of moving parts and you should not try to write all of the code for it and then hope it works. (ProTip: It almost certainly won't.)

Start by writing account.h and account.cpp. Consider writing a short main program to create a single account object and test it by calling the various methods you wrote. The makefile for the assignment assumes that both the account and bank classes exist, but you can still build your test program without having written the bank class by using a command like this:

    g++ -Wall -Werror -std=c++11 -o test test.cpp account.cpp

(The above command assumes that your main() function to test the account class is in the file test.cpp.)

The bank class depends on the account class, so if your account class is wrong, the bank class is guaranteed to be wrong as well. That means there's really no point in trying to code the bank class until your account class is right (i.e., compiles without warnings or errors and produces the correct results when its member functions are called).

Once your account class seems like it works, then you can start working on the bank class. Start by writing the constructor, the read_accounts() member function (without the sort code), and the print() member function. Don't worry about printing the header or getting the output in sorted order by account number, just make sure that you are reading the account data correctly and can print it out.

Next, write code to sort the account objects by account number. Once again, make sure that the sort is working before you move to the next step (binary search won't work on an unsorted array).

The last part of the assignment that you should write is the process_transactions() member function. Initially, just make sure that you are able to read all the fields of each transaction record. Then add the binary search code and check to make sure that the search works (finds account numbers that are in the array and fails appropriately for account numbers that are not). Next, add the code to process deposits and withdrawals. Check that your account balances are being updated correctly. Finally, write the code to print the transaction report and make sure that your output is formatted in a way that matches the sample output.