#C14876. ATM Simulation
ATM Simulation
ATM Simulation
You are required to simulate a simple ATM system. The ATM supports the following operations:
- DEPOSIT X: Deposits an amount X into the ATM. The amount must be positive. After a successful operation, the ATM's new balance is printed.
- WITHDRAW X: Withdraws an amount X from the ATM. The amount must be positive and not exceed the current balance. After a successful operation, the ATM's new balance is printed.
- CHECK: Outputs the current balance.
- HISTORY: Outputs the total number of successful deposit or withdrawal transactions performed.
For any deposit or withdrawal operation that fails (e.g. depositing a non-positive amount or attempting to withdraw more than the available balance), print the corresponding error message as specified below:
- If the deposit amount is not positive, output:
Deposit amount must be greater than zero
. - If the withdrawal amount is not positive, output:
Withdrawal amount must be greater than zero
. - If the withdrawal amount exceeds the current balance, output:
Insufficient funds
.
Initially, the ATM balance is 0.0 and the transaction history is empty.
inputFormat
The input is read from standard input (stdin) in the following format:
- The first line contains an integer T representing the number of operations.
- The next T lines each contain one operation. An operation is one of the following:
DEPOSIT X
where X is a floating-point number.WITHDRAW X
where X is a floating-point number.CHECK
HISTORY
outputFormat
The output must be printed to standard output (stdout). For each input operation, output a result on a new line as follows:
- For a successful
DEPOSIT
orWITHDRAW
operation, print the new balance (as a floating point number). - For a
CHECK
operation, print the current balance. - For a
HISTORY
operation, print the count of successful deposit and withdrawal transactions. - If an error occurs in
DEPOSIT
orWITHDRAW
, print the error message exactly as specified.
4
CHECK
DEPOSIT 100.0
WITHDRAW 50.0
HISTORY
0.0
100.0
50.0
2
</p>