Chapter 10: Problem 37
How does inheritance support code reuse and make code easier to main\(\operatorname{tain} ?\)
Chapter 10: Problem 37
How does inheritance support code reuse and make code easier to main\(\operatorname{tain} ?\)
All the tools & learning materials you need for study success - in one app.
Get started for freeGive a definition for the function with the following function declaration. The class BankAccount is defined in Display 10.5 double difference(BankAccount account1, BankAccount account2); / / Precondition: account1 and account2 have been given values // (that is, their member variables have been given values). // Returns the balance in account1 minus the balance in account2.
Give a definition for the function with the following function declaration. The class BankAccount is defined in Display 10.5 BankAccount new_account(BankAccount old_account); //Precondition: old_account has previously been given a value // (that is, its member variables have been given values). //Returns the value for a new account that has a balance of zero / / and the same interest rate as the old_account. For example, after this function is defined, a program could contain the following: BankAccount account3, account4; account3.set(999, 99, 5.5) ; account4 \(=\) new_account(account 3) account4.output(cout); This would produce the following output:
Consider the following type definition: struct ShoeType \\{ char style double price \\}; Given this structure type definition, what will be the output produced by the following code? ShoeType shoe1, shoe2; shoe1.style \(=^{\prime} A^{\prime}\) shoe1.price \(=9.99\) cout \( < < \) shoe \(1 .\) style \( < < " \$^{\prime \prime} < < \) shoe1.price \( < < \) endl shoe \(2=\) shoe 1 shoe2.price \(=\) shoe \(2 .\) price \(/ 9\) cout \( < < \) shoe \(2 .\) style \( < < " \$ " < < \) shoe \(2 .\) price \( < < \) end 1;
When you define an ADT as a C++ class, should you make the member variables public or private? Should you make the member functions public or private?
Suppose your program contains the following class definition (along with definitions of the member functions): class Yourclass \\{ public: YourClass(int new_info, char more_new_info); Yourclass(); void do_stuff( \()\) private: int information; char more_information; \\} Which of the following are legal? YourClass an_object(42, 'A'); YourClass another_object; YourClass yet_another_object() \\[ \begin{array}{l} a n_{-} \text {object }=\text { Yourclass }\left(99, \quad^{\prime} B^{\prime}\right) ; \\ a n_{-} \text {object }=\text { Yourclass }() ; \\ \text { an_object }=\text { YourClass } \end{array} \\]
What do you think about this solution?
We value your feedback to improve our textbook solutions.