Question
Below, suppose that you have the following classes: classA and classB. Write the class into a header that is called from main. Be sure to
Below, suppose that you have the following classes: classA and classB. Write the class into a header that is called from main. Be sure to #include
class classA { public: virtual void print() const; void doubleNum(); classA(int a = 0);
private: int x; };
void classA::print() const { cout << "ClassA x: " << x << endl; }
void classA::doubleNum() { x = 2 * x; }
classA::classA(int a) { x = a; }
class classB: public classA { public: void print() const; void doubleNum(); classB(int a = 0, int b = 0);
private: int y; };
void classB::print() const { classA::print(); cout << "ClassB y: " << y << endl; }
void classB::doubleNum() { classA::doubleNum();
y = 2 * y; }
classB::classB(int a, int b) : classA(a) { y = b; }
What is the output of the following function main?
int main() { classA *ptrA; classA objectA(2);
classB objectB(3, 5);
ptrA = &objectA; ptrA->doubleNum(); ptrA->print(); cout << endl;
ptrA = &objectB;
ptrA ->doubleNum(); ptrA->print(); cout << endl;
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started