#C14803. Simulation of a Simple Bank Account

    ID: 44493 Type: Default 1000ms 256MiB

Simulation of a Simple Bank Account

Simulation of a Simple Bank Account

This problem requires you to implement a simple BankAccount class that can simulate basic banking operations. The class should support the following operations:

  • deposit(amount): Increases the account balance by amount. The amount must be positive.
  • withdraw(amount): Decreases the account balance by amount if there are sufficient funds, and the amount must be positive. If the withdrawal amount is greater than the current balance, an error should occur.
  • get_balance(): Returns the current balance of the account.

The operations will be provided via standard input. The first line specifies the initial balance of the account, and each subsequent line represents one operation. There are 3 types of operations:

  • deposit X – deposit the amount X.
  • withdraw X – withdraw the amount X.
  • get – print the current balance.

Your solution should use standard input for reading and standard output for printing results. Any error conditions (invalid deposit/withdraw amounts or insufficient funds) will not be tested.

Note: Any formulas in your explanation should be written in \(\LaTeX\) format. For instance, a deposit operation can be represented as: \(\text{new balance} = \text{old balance} + \text{amount}\).

inputFormat

The first line contains a number representing the initial balance of the account. The next line contains an integer \(n\) that denotes the total number of operations. Each of the following \(n\) lines contains an operation in one of the following formats:

  • deposit X — add a positive number X to the account.
  • withdraw X — subtract a positive number X from the account if sufficient funds exist.
  • get — output the current balance.

outputFormat

For each get operation, output the current balance of the account on a separate line.

## sample
0
2
deposit 50
get
50

</p>