question archive Create a struct called Personal_account, which inherits the Acount struct you made in the last homework

Create a struct called Personal_account, which inherits the Acount struct you made in the last homework

Subject:Computer SciencePrice: Bought3

Create a struct called Personal_account, which inherits the Acount struct you made in the last homework.Here is an example of Acount struct.

struct Account { private: int balanceInPennies; public: Account() { balanceInPennies = 0; } Account(int a) { balanceInPennies = a; } int query() const { return balanceInPennies; } void deposit(unsigned int a) { balanceInPennies = balanceInPennies + a; } void withdraw(unsigned int a) { if (balanceInPennies < a) { cout << "5 dollar penalty charged for attempting to withdraw more than available" << endl; if (balanceInPennies < 500) { balanceInPennies = 0; } else { balanceInPennies = balanceInPennies - 500; } } else { balanceInPennies = balanceInPennies - a; } } };

Add two new private member variables, string variable 'name' and int variable 'ID'.

Constructors: 1 The first should have no parameters, and initialize accounts' balances (balanceInPennies) to be 0, ID to be 0, and name to be an empty string variable. 2 The second should have two parameters, and initialize name and ID accordingly. The balance in this case is still 0. 3 The third should have three parameters, which initialize 'name', 'ID', and balance accordingly.

(d) Declare public member functions. 1string show_name () return name.

2int show_ID() returns the ID.

Outside the struct, please define the following function. void transfer(Personal_account &A, Personal_account &B, int transfer_amount) transfers the transfer_amount pennies from Personal_account A to Personal_account B.

Inside the function transfer, please first use withdraw to deduct the amount from Personal_account A. Then use deposit to deposit the money into Personal_account B.

If the balance in A is less than transfer_amount, then A suffers the penalty after calling the function withdraw. If the remaining balance in A is not zero. Then deposit the remaining balance to B and the set balance in A to be zero. If the remaining balance in A is zero, then terminate the transfer. Suppose the balance in A is 600 and the transfer amount is 1000. After calling withdraw, the balance in A becomes 100. Then we transfer 100 from A to B.

main()

The first part in main() function is given as follows

Personal_account A0; cout << A0.query() << endl; Personal_account A1("First",1,100); Personal_account A2("Second",2); cout << A1.query() <<"  " << A2.query() << endl; transfer(A1,A2,10) cout << A1.query() <<"  " << A2.query() << endl; transfer(A1,A2,100) cout << A1.query() <<"  " << A2.query() << endl;

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE