The Account class Recall the Account class: class Account {public: void setName
ID: 3841198 • Letter: T
Question
The Account class Recall the Account class: class Account {public: void setName (std:: string accountName); std::string getName ();//get account balance int getBalance ();//withdraw/deposit valid amount from/to balance int withdraw (int withdrawAmount); void deposit (int depositAmount); private: std::string m_name;//account holder's name int m_balance {0};//account balance}; Declare a prototype for the Account class' constructor that takes as input the account holder's name and the account's initial balance. Indicate whether the constructor should be a public or private member function. Write a main() function that opens an account in your name with an initial balance of $0, deposits $500, and then withdraws $100. You may assume that the constructor from Problem 3.1 is available for you to use. Consider the following implementation of the Account:: setName function: void Account:: setName (std:: string accountName) {m_name = accountName;} Rewrite this function using the this keyword. Suppose that acct has been defined as an Account object in main(). Which of the following are legal statements (circle all of the correct answers). (a) acct. deposit (100); (b) acct. get Balance (); (c) acct. m_name;Explanation / Answer
1. COnstructors are usually public so always declare constructors public unless you have some special case.
Account(std::string name, int bal)
{
m_name=name;
balance= bal;
}
2. int main()
{
Account acc("ASif Khan", 0);
acc.deposit(500);
acc.withdraw(100);
}
3. void Account::setName(std::string m_name)
{
this->m_name= m_name;
}
4. a) is correct
b) is correct
c) Incorrect because m_name is private and cannot be accecced from outside
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.