Consider this C BankAccount class with the following public
Consider this C++ BankAccount class with the following public member functions.
/* Constructs an object to represent a bank account.
*
* Parameter:
* double initial_balance -- the starting balance of the account
* /
BankAccount(double initial_balance);
/* Adds a certain amount the balance of the account.
*
* Parameter:
* double amount -- the amount to add to the balance
*
* Returns:
* nothing
*/
void deposit(double amount);
/* Subtracts a certain amount from the balance of the account.
*
* Parameter:
* double amount -- the amount to subtract from the balance
*
* Returns:
* nothing
*/
void withdraw(double amount);
/* Gets the balance of the account.
*
* Parameters:
* none
*
* Returns:
* double -- the balance of the account
*/
double get_balance();
(a) Which are the accessor function(s)?
(b) Which are the mutator function(s)?
(c) Create an object to represent a checking account with a starting balance of $1500.
(d) Provide a fragment of C++ code to perform this sequence of actions on the checking
account: deposit $100, print the balance, withdraw $250.
Solution
a) accessors
get_balance()
b) mutators
void deposit(double)
void withdraw(double)
c) BankAccount acc(1500.0);
d) acc.deposit(100.0)
acc.get_balance();
acc.withdraw(250.0)

