What is the output of the following C++ code? class A { public: A(int a = 4);
Fantastic news! We've Found the answer you've been seeking!
Question:
What is the output of the following C++ code?
Transcribed Image Text:
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; 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;
Expert Answer:
Answer rating: 100% (QA)
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... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
What is global investment outlook for US Large Cap Market, the mutual fund Akre Focus Instl-AKRIX?
-
CASE STUDY. Case Study Chapters 1 and 2. Please post both case studies in Assignment Drop Box as one MS Word apa formate document. Note: See template provided for case study papers. Chapter 1 - Listo...
-
Assume in 2008, General Mills has to decide how to spend millions of dollars to try and expand its cereal and yogurt businesses. To allocate this money between these two businesses, what information...
-
Bradley Corporation sold bonds to Flood Company in 20X2 at 90. At the end of 20X4, Century Corporation purchased the bonds from Flood at 105. Bradley then retired the full bond issue on December 31,...
-
Give a superclass for the following three classes: car, airplane, tank.
-
Contrast simulation to other risk analysis tools. What are its advantages and disadvantages? If you were to do an important risk analysis, which tool would you prefer?
-
A stock price is currently trading at $100. Over the next two 6 month periods it will be with up 10% or down 10%. The risk-free interest rate is 8% per annum with continous compunding. What is the...
-
There is an array A made of N integers. Your task is to choose as many integers from A as possible so that, when they are put in ascending order, all of the differences between all pairs of...
-
Solve the following initial value problem. 1 -1 X + -1 X' X(0) = 2 3
-
What are the potential costs associated with enterprise AI programs?
-
What are the key success factors in designing and implementing these two research techniques?
-
What are the potential challenges of deploying enterprise AI programs?
-
Should leaders rely on quantitative research methods alone? What happens if there are only a few customers available to research?
-
What could be some of the key differences between digital pricing transformations taken up by B2B versus B2C organizations?
-
Miguel, a calendar year taxpayer, files his 2013 Federal income tax return on April 1, 2017. The returnshowed $2,500 of tax due and Miguel pays that amount with the return. On March 1, 2019,...
-
Solve each equation or inequality. |6x8-4 = 0
-
Write a code fragment that asks the user to enter a positive integer and then creates a dynamic array of that many ints. Do this by using new, then again using a vector object.
-
The CandyBar structure contains three members.The first member holds the brand name of a candy bar.The second member holds the weight (which may have a fractional part) of the candy bar, and the...
-
Consider the two C++ statements that follow: char grade = 65; char grade = 'A'; Are they equivalent?
-
Can you name five types of channels of communication?
-
How would you define your own leadership style? Do you have examples you can share with others on how you lead when called on?
-
Revisit the definition of strategic communication and then review the vignette at the beginning of the chapter. Match the different terms in the definition to the different entities in the vignette.
Study smarter with the SolutionInn App