Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is the output of the following C++ code? class A { public: A(int a = 4); void SetX(int a); int GetX(); virtual void print();

What is the output of the following C++ code?

class A { public: A(int a = 4); void SetX(int a); int Getx(); virtual void print(); int x; private: }; 

class A { public: A(int a = 4); void SetX(int a); int GetX(); virtual void print(); int x; private: }; A::A(int a ) { x = a; } void A::SetX(int a) { x = a; } int A::GetX() { return x; } void A::print() class B public A { public: B(int h 3); virtual void print (); int y; private: }; B::B(int h) { y h; { cout < < x < < endl; } A::SetX(h + 13); void B::print() { cout < < (*this).y + this->GetX() < < endl; } int main() { B bl, b2(2), *b3; A *data[4]; data[0] new B(4); data[1] = new A(5); bl.print(); b2.print(); b3 new B(3); data[2] = b3; data[0]->print(); data[1]->print(); data[2]->print(); return 0;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

After correcting some issues the code would look like this include using namespace stdclass A publicAint a 4void SetXint aint GetXvirtual void printprivateint xAAint a x a void ASetXint a x a int AGet... 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

C++ Primer Plus

Authors: Stephen Prata

6th Edition

978-0321776402, 0321776402

More Books

Students also viewed these Programming questions

Question

=+d) Can you reject the null hypothesis of part c? Explain.

Answered: 1 week ago

Question

Solve each equation or inequality. |6x8-4 = 0

Answered: 1 week ago