Problem #7

Code Wars II
Danger Level: Blue



}Account Balancing~

Point Value: 5
 

Problem Statement

The First Fiscal Bank of Financial Fidelity needs a program to keep account balances up to date.  The old program runs on a large, expensive mainframe, and you've been hired to rewrite it for Windows NT.  In this problem you will write a simple prototype for a full account balancing package.
 

Program Input

The input file PROB07.IN will be a series of deposits and withdraws, each associated with a person's name.  The program should create a new bank account when it encounters a name with the key word BALANCE.  It should then add and subtract the given values as appropriate per the DEPOSIT and WITHDRAW transactions.  Here's some sample input lines:

DIANE BALANCE 450.00
LARRY BALANCE 721.50
DIANE WITHDRAW 63.50
BEATRICE BALANCE 550.00
LARRY BALANCE 1344.71
STEVE WITHDRAW 19.62
LARRY WITHDRAW 246.19
DIANE DEPOSIT 925.22
LARRY WITHDRAW 515.00
BEATRICE DEPOSIT 750.00
STEVE BALANCE 200.00
DIANE WITHDRAW 37.50
BEATRICE DEPOSIT 200.00
STEVE WITHDRAW 19.54
LARRY WITHDRAW 5.15
XAVIER BALANCE 23400.00
DIANE DEPOSIT 925.23
 
 
 
 
 
 

Program Output

The program should print error conditions and final account balances to PROB07.OUT.  It should print a line for each occurance of any of these three error conditions: (1) any DEPOSIT or WITHDRAW transaction for an account that does not exist, (2) assigning a BALANCE to an account already open, and (3) attempting to overdraw the account.  The program should print the line number with the error message.  After reading the entire file, the program should print all the account names, in alphabetical order, along with the current balances.  All dollar values in the output file should be prefixed with a $.  Dollar amounts should be delimited by commas every three significant digits, as shown in the sample output.  Here's the example output from the above input data:

ERROR LINE 5: LARRY CANNOT REASSIGN ACCOUNT BALANCE
ERROR LINE 6: STEVE DOES NOT HAVE AN ACCOUNT
ERROR LINE 9: LARRY CANNOT WITHDRAW $515.00 - BALANCE IS $475.31
--- FINAL BALANCES ---
BEATRICE $1,500.00
DIANE $2,199.45
LARRY $470.16
STEVE $180.46
XAVIER $23,400.00