Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ Suppose that you have the following classes: classA and classB: class classA { public: virtual void print() const; void doubleNum(); classA(int a =

In c++ Suppose that you have the following classes: classA and classB:

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

LO1 Summarize the organizations strategic planning process.

Answered: 1 week ago