Answered step by step
Verified Expert Solution
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: }; 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...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