Member-only story

In C++ create a BankAccount class which lets the account owner to deposit and withdraw money using a password

Marika Lam
2 min readMay 31, 2022

--

Criteria

  1. There should be no default constructor.
  2. There should be only one constructor, which takes in the initial balance in dollars, and the password. The password is an integer, most likely 4 digits, but we won’t enforce that limit here (which means it can even be negative). The initial amount, however, must not be negative, if it is negative, set it to $0.00 by default. Your BankAccount class should be able to keep track of the balance up to the last cent.
  3. It should support two operations, deposit and withdraw. Both must be Boolean functions. One must specify the amount of money he wants to deposit/withdraw, and the password. If the password is incorrect, the return value must be false. Also, for withdraw, if the requested amount exceeds the current balance or is negative, return false and do not change anything. If the deposit amount is negative, do not change the balance and return false.
  4. Add a Boolean function setPassword, which takes in two passwords — the original password and the new password. If the original password does not match, return false and do not change the password. If the original password is correct, update the password with the new password.
  5. Provide an accessor function balance, which accepts the password. If the password is correct, return the balance. If not, return -1.

--

--

No responses yet