Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 , using namespace std; and any additions such as #include "pch.h" are present.

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

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions