#C14547. Banking System Simulation

    ID: 44208 Type: Default 1000ms 256MiB

Banking System Simulation

Banking System Simulation

You are required to implement a simple banking system simulation. Your system should support a number of operations on bank accounts. Each account is associated with an owner and a unique account number (starting from 1000). The system should support the following commands via stdin:

  • CREATE owner: Create a new account for the given owner name. Print the generated account number.
  • DEPOSIT account_number amount: Deposit a positive amount into the account. Print the new balance formatted to one decimal place. If the amount is not positive or if the account does not exist, print "Error".
  • WITHDRAW account_number amount: Withdraw a positive amount from the account provided that sufficient funds exist. Print the new balance formatted to one decimal place. Otherwise, print "Error".
  • TRANSFER src_account dest_account amount: Transfer a positive amount from the source account to the destination account. Print the new balance of the source account formatted to one decimal place. If any error occurs (e.g. insufficient funds, negative amount, or non-existent account), print "Error".
  • DELETE account_number: Delete an account. Print "OK" if the deletion is successful; otherwise, print "Error".
  • BALANCE account_number: Print the current balance of the account formatted to one decimal place. If the account does not exist, print "Error".

Each command is processed sequentially. If any command encounters an error condition, your program must print "Error" for that command and continue processing subsequent commands.

Note: All inputs are provided through standard input (stdin) and outputs must be written to standard output (stdout).

inputFormat

The first line contains an integer T, representing the number of commands. Each of the following T lines contains one command as described above. Commands and their arguments are space-separated. For example:

6 CREATE John DEPOSIT 1000 500 BALANCE 1000 WITHDRAW 1000 200 BALANCE 1000 DELETE 1000

outputFormat

For each command, output the result on a new line. The output is determined as follows:

  • For CREATE, print the generated account number.
  • For DEPOSIT, WITHDRAW, TRANSFER, and BALANCE, print the account balance formatted as a floating-point number with one decimal place.
  • For DELETE, print OK on successful deletion.
  • If a command has an error (such as negative amounts, insufficient funds, or a non-existent account), print Error.## sample
6
CREATE John
DEPOSIT 1000 500
BALANCE 1000
WITHDRAW 1000 200
BALANCE 1000
DELETE 1000
1000

500.0 500.0 300.0 300.0 OK

</p>