#C12915. Simplified Banking System
Simplified Banking System
Simplified Banking System
Implement a simplified banking system that manages multiple bank accounts. Each account is assigned a unique account number starting from 1 and starts with a balance of 0. The system should support the following commands (provided via standard input):
- CREATE <name>: Create a new account with the specified name, and print the assigned account number.
- DEPOSIT <account_number> <amount>: Deposit a positive amount into the specified account. If the amount is not positive, output the error message
Invalid amount
. - WITHDRAW <account_number> <amount>: Withdraw a positive amount from the specified account. If the amount is not positive, output
Invalid amount
; if the account does not have sufficient funds, outputInsufficient funds
. - BALANCE <account_number>: Print the current balance of the specified account (as a floating point number).
- LIST: List the details of all accounts in the order they were created. Each account detail should be printed on a separate line in the format:
Account Number: X, Name: Y, Balance: Z
. - END: Terminate the input.
Your program must read commands from standard input (stdin) and output the results to standard output (stdout). The account operations must handle errors as described above using the precise error messages.
inputFormat
The input consists of several lines, each containing a command. The commands can be one of the following:
• CREATE name
• DEPOSIT account_number amount
• WITHDRAW account_number amount
• BALANCE account_number
• LIST
• END
The input terminates with a line containing only END
.
outputFormat
For each command that produces output, your program should print the result on a new line. Specifically:
• For CREATE, print the assigned account number.
• For BALANCE, print the current balance (as a floating-point number).
• For LIST, print each account's details in separate lines following the format: Account Number: X, Name: Y, Balance: Z
.
• For DEPOSIT or WITHDRAW, if an error occurs, print the corresponding error message (Invalid amount
or Insufficient funds
).## sample
CREATE Alice
BALANCE 1
END
1
0.0
</p>