Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In c++ Bob defines a base class, Base, with instance method func, and declares i

ID: 3867272 • Letter: I

Question

In c++

Bob defines a base class, Base, with instance method func, and declares it to be virtual. Alicia (who has no access to Bob's source code) defines three derived classes, Der1, Der2 and Der3, of the base class and overrides func () Ying has no access to Bob or Alicia's source code and does not know anything about the derived classes, including their names or how many derived classes exist. Ying does know about the Base class and knows about its public instance function func ). She is also aware that there may be derived classes that override func () Ying uses a Base pointer, p, to loop through a list of Base object pointers. Ying is aware that the list pointers may point to Base objects or some subclass objects of Base Check all that apply Ying can call p->func) on each object in the loop and get distinct behavior as defined by the object pointed Since Ying's loop pointer, p, is type Base, no compiler error will occur Ying can call p->func) on each object in the loop and force only base class behavior of that method by using type coercion Ying can call p->func) on each object in the loop (no coercion) and will always get the Base behavior of this function

Explanation / Answer

1.

a and b are corrct answers, i.e.
Ying can call p->func () on each object in the loop and get distinct behavior as defined by the object pointed to (function of child class will be reflected).
Since Ying's loop pointer, p. is type Base, no compiler error will occur.

2. deepA = deepB will copy the address only and both pointers will point to same memory locaion, so b and c are correct
b. After this assignment, both deepA and deepB will have their respective somePointers pointing to the same exact memory.
c. This is a shallow copy: deep memory controlled by deepA is not copied and pointed to by deepB.

3. since the memory is alocated using new operator, we would need to use delete keyword to free up the memory and prevent memory leaking

so the correct answer should be main () is responsible for deleting the two objects it instantiated, either directly or by calling some method that deletes them.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote