Question
Design BankAccount class, which lets the account owner to deposit and withdraw money using a password. The class you write should meet the following requirements:
Design BankAccount class, which lets the account owner to deposit and withdraw money using a password. The class you write should meet the following requirements:
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 wont 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.
6. You can create private member functions and variables as you wish.
A possible usage of this class looks like this:
BankAccount ba(500, 1234); // initial amount: $500, password: 1234 cout << "$" << ba.balance(1234) << endl; // prints $500.00 cout << "$" << ba.balance(2345) << endl; // prints $-1 ba.deposit(25, 1234); // deposit $25 cout << "$" << ba.balance(1234) << endl; // prints $525.00 ba.withdraw(500, 2345); // should return false ba.withdraw(1000, 1234); // should return false ba.withdraw(100, 1234); // make the withdraw cout << "$" << ba.balance(1234) << endl; // prints $425.00 ba.setPassword(1234, 2345); // change the password ba.withdraw(300, 2345); // make the withdraw
(a) Write the full class declaration here.
(b) Write the definition (implementation) of the constructor, including the header.
(c) Write the definition of balance, including the header.
(d) Write the definitions of deposit and withdraw, including the header.
(e) Write the definition of setPassword, including the header.
(f) If you used any extra private member function(s), provide the definition(s) here.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started