ESc 014

Lab 2 -- Bank Account Averager
Thursday, April 11, 2002


Lab summary

A bank maintains three types of accounts: savings, checking, and money market accounts. Given a data file containing the balances of these accounts for different customers, write a program that will ask the user for a particular account type (e.g. checking) and then display the average balance for that type across all customers.

Grab the input files

On blackduck in the "esc014pub" directory is a directory named "lab 2". Transfer this directory to the DesktopAnnex folder on your desktop just like you did in last week's lab.

Inside the "lab 2" folder are two files. One is the input file containing account balances. It's called "moneydata.txt". Open it up. Each set of three numbers represents the savings, checking, and money market balances of a single customer (in that order):

112.36	<-- savings acct balance of acct# 0
209.14	<-- checking acct balance of acct# 0
400.00	<-- money market acct balance of acct# 0
90.32	<-- savings acct balance of acct# 1
20.00	<-- checking acct balance of acct# 1
23.33	<-- money market acct balance of acct# 1
11.95	<-- savings acct balance of acct# 2
... etc.
The second file is named "yourNameHere.cpp". Change the filename to your own name (keep the .cpp extension). This is the starter code for your lab. It contains two constants: the total number of accounts (8) and the number of account types (3).

The Details

Your program should consist of two functions. The first is the main function. It should do the following:

  1. Read the balances from "moneydata.txt" into a two-dimensional array. This array will keep track of balances for each of the account types, as the following picture shows:

    Since you know in advance the number of balances you're going to read (3 balances for each of 8 accounts), I recommend using for loops to read in your data. Note that, for the account types, index 0 is for savings accounts, 1 is for checking and 2 is for money market accounts.

  2. Ask the user to choose which type of account s/he would like the program to compute the average of. To make things easier for you, the user can just input a number: 0 for savings, 1 for checking, 2 for money market.
  3. Call the computeAvg function (see below) to find the average for the account type specified.
  4. Display to the user the average returned from computeAvg.

The second function is computeAvg. It will take the two-dimensional array and the user-specified account type as parameters. It will compute the average balance for that type of account across all accounts and return it.

Test to be sure your program works for all account types. Make sure you paste your output into your source code!

How to turn in this lab

Remember, you will be graded on the correctness of your implementation, neatness, presentation, style of your program code, and good use of the C++ language. It's important to comment your code where appropriate and to do little things like space things properly, use readable indentation, and also to make sure the overall design and logic of the program are coherent.

Turn in a hard copy of your source code along with the output appended at the bottom as a comment. Then turn in the source code electronically on BlackBoard.

Return to Lab Index