โ Back to Classes
Question 152
BankAccount Withdraw Exception
BankAccount Withdraw Exception
Create a classBankAccountwith a privatedouble balance. Requirements: 1. ConstructorBankAccount(double initialBalance): throwsstd::invalid_argumentwith"Initial balance cannot be negative"ifinitialBalance < 0. Otherwise sets balance. 2.void deposit(double amount): throwsstd::invalid_argumentwith"Deposit amount must be positive"ifamount <= 0. Otherwise adds to balance. 3.void withdraw(double amount): throwsstd::invalid_argumentwith"Withdraw amount must be positive"ifamount <= 0; throwsstd::runtime_errorwith"Insufficient funds"ifamount > balance. Otherwise subtracts from balance. 4.double getBalance() const: returns the current balance. Do NOT write a main function.
Expected Output:
150
Topics:
ClassesExceptions
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.