Chapter 15: Problem 8
A base class pointer needs a(n) _________ to be assigned to a derived class pointer.
Chapter 15: Problem 8
A base class pointer needs a(n) _________ to be assigned to a derived class pointer.
All the tools & learning materials you need for study success - in one app.
Get started for freeIf every C1 class object can be used as a C2 class object, the relationship between the two classes should be implemented using _________.
Suppose that you need to have a class that can sort an array in ascending order or descending order upon request. If an array is already sorted in ascending or descending order, you can easily sort it the other way by reversing it. Now suppose you have two different classes that encapsulate arrays. One provides a member function to reverse its array, while the other provides a member function to sort its array. Can you use multiple inheritance to obtain a quick solution to your problem? Should you? Write a couple of paragraphs explaining whether using multiple inheritance will or will not work to solve this problem, and, if it can, whether this is a good way to solve the problem.
Write a C++ class that has an array of integers as a member variable, a pure virtual member function bool compare(int \(x, \text { int } y)=0\) that compares its two parameters and returns a boolean value, and a member function void sort () that uses the comparison defined by the compare virtual function to sort the array. The sort function will swap a pair of array elements a \([\mathrm{k}]\) and a \([\text { j }]\) if \\[ \text { compare }(a[k], a[j]) \\] returns true. Explain how you can use this class to produce classes that sort arrays in ascending order and descending order.
The ability of code to execute differently depending on the type of data is called _________.
Suppose that the classes Dog and cat derive from Animal, which in turn derives from Creature. Suppose further that pDog, pCat, pAnimal, and pCreature are pointers to the respective classes. Suppose that Animal and creature are both abstract classes. Will the statement pAnimal \(=\) new Cat compile?
What do you think about this solution?
We value your feedback to improve our textbook solutions.