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

A client is supplied with the following declaration for a base class and a deriv

ID: 3529188 • Letter: A

Question

A client is supplied with the following declaration for a base class and a derived class: class BaseClass { public : . . . }; class DerivedClass : BaseClass { public : void NewFunction(); DerivedClass (int StartValue); . . . }; The client writes the following code to call the constructor for an object of type DerivedClass, and then print the fields in the newly created object. DerivedClass anObject (10); anObject.PrintFields(); The compiler reports an error for the second statement. What wrong? How would you fix this problem?

Explanation / Answer

Error 1: You have to define PrintFields() method in derived class. Solution: class DerivedClass : BaseClass { public : void NewFunction(); DerivedClass (int StartValue); void PrintFields(); }; void DerivedClass :: PrintFields() { } Error 2: You defined the parameterized constructor, but you didn't defined it. So you have to define it. Solution: class DerivedClass : BaseClass { public : void NewFunction(); DerivedClass (int StartValue); void PrintFields(); }; DerivedClass :: DerivedClass (int StartValue) { }

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