CS 150 - Intro to Programming - Fall 2001


Programming Project 5

25 points - Due: Thursday, November 15 by 2:45pm


Part 1 (15 points)

This problem involves a simplified version of the way that a company looks up and maintains information about a particular customer's account. The program first reads in the company's database from a file called "accounts.dat". Each line of the file contains a customer's account number and balance. (Make your own test files using any text editor. Include at least one test file when you turn in your program. Print the test file on a separate piece of paper.)

Two arrays are declared to hold up to MAX elements one for the account numbers and one for the balances. The value of MAX should be defined in a const statement. If the data file contains more than MAX accounts, only the first MAX should be read and a warning message is issued. Your program should also print a warning message if the data file is empty.

For example, the input file might look like this

734	    921.37
5126	-38.14
710	  -1005.00
2084 	 12.01
986	    345.29

Once the input phase is over, allow the user to enter an account number. The program should print the account number and corresponding balance. If the account number is not in the list, print an appropriate message. Continue to accept account numbers until a zero sentinel is entered.

Account number > 5261                           //example run - look up account 5261
The balance for account #5261 is -38.14
Account number > 1586                           //this account number not found in the array
Account #1586 is not listed.
Account number > 0
Bye For Now

Your program must contain the following:

int lookupAcct(int currAcct,     //account number to find
              int acctNums[],     //array that holds all the account numbers
              int numAccts)      //total number of accounts (and balances) stored
              

Given an account number to look up (the first argument) and the database information (2nd and 3rd arguments) the function returns the index of the account number if and only if the account number actually exists and -1 otherwise. Your program must use the above prototype for the lookupAcct function.

Of course, you should test this program for both full arrays(numAccts contains MAX accounts) and partially filled arrays. Include tests where the data file has fewer than MAX accounts, exactly MAX accounts, more than MAX accounts and an empty file..

Part 2 (10 points)

Once part one is working allow for credits and debits to the accounts. For this part you will need to implement a menu that offers the user the ability to lookup a balance, credit an account, and make a debit to an account or exit the program. The program must run in a loop allowing the user to continue until she chooses to exit.

Your program must contain the following:

After each transaction the balance for that account should be printed.

Sample Run:
Enter one of the following
L Lookup a balance
C Credit an account
D Debit an account
E Exit the program
User enters C:
Account number to Credit > 5216
Amount of Credit > 12.50
The balance for account #5216 is -25.64
User enters D:
Account number to Debit > 734
Amount of Debit > 88.20
The balance for account #734 is 833.17

Test your program by adding credits and posting debits for accounts in the database and accounts not in the database.

Notes:

What to turn in:

Paper copies to be turned in:

You will need to turn in a "hard" copy of your source code files for both part one and part two. Staple the pages together in the following order: Part one then part two then a hard copy of your test file as the last page. The hard copy is due at the beginning of lecture the day the program is due.

Files to be Turned In to the drop box by the due date shown above:

lastnameP5Part1.cpp Program for part one
lastnameP5Part2.cpp Program for part two
"accounts.dat" test file for part one and two