#C14239. Bank Account Operations Simulation

    ID: 43866 Type: Default 1000ms 256MiB

Bank Account Operations Simulation

Bank Account Operations Simulation

In this problem, you are to simulate operations on bank accounts. There are three types of accounts:

  • Account: Supports deposit and withdrawal operations. Withdrawals are only processed if sufficient funds are available.
  • CheckingAccount: Inherits from Account and permits overdraft withdrawals up to a specified overdraft limit.
  • SavingsAccount: Inherits from Account and supports the application of interest. Interest is applied only when the balance is positive. The new balance is computed using the formula: \( new\;balance = old\;balance + old\;balance \times interest\_rate \).

Your program will process a series of commands provided via standard input and output the balance for every check_balance command.

inputFormat

The input begins with an integer ( Q ) representing the number of operations. Each of the following ( Q ) lines contains one command. The available commands are:

  • create [AccountType] [parameters]: Initializes an account. For an Account, provide the initial balance. For a CheckingAccount, provide the initial balance and overdraft limit. For a SavingsAccount, provide the initial balance and interest rate.
  • deposit x: Deposits the integer \( x \) into the account (only if \( x > 0 \)).
  • withdraw x: Withdraws the integer \( x \) from the account if the conditions for withdrawal are met.
  • apply_interest: For SavingsAccount only, applies interest as per the formula above (does nothing for other account types).
  • check_balance: Prints the current balance to standard output.

outputFormat

For each check_balance command, print the current balance on a new line to standard output.## sample

3
create Account 0
deposit 100
check_balance
100

</p>