Answer to Question #203313 in C++ for Ali Hassan

Question #203313
class baseClass
{
    public:
        void print();
        int getX();
        baseClass(int a = 0);
    protected:
        int x;
};
class derivedClass: public baseClass
{
    public:
        void print();
        int getResult();
        derivedClass(int a = 0, int b = 0);
    private:
        int y;
};
void baseClass::print()
{
   cout<<"In base: x= "<< x <<endl;
}
baseClass::baseClass(int a)
{
    x = a;
}
int baseClass::getX()
{
   return x;
}
void derivedClass::print()
{
   cout<<"In derived: x= "<< x <<", y= "<< y 
       <<"; x + y = "<< x + y <<endl;
}
int derivedClass::getResult()
{
   return x + y;
}
derivedClass::derivedClass(int a, int b): baseClass(a)
{
    y = b;
}

What is the output of the following function main?

int main()
{
    baseClass baseObject(7);
    derivedClass derivedObject(3, 8);
    baseObject.print();
    derivedObject.print();
    cout<<"****"<<baseObject.getX()<<endl;
    cout<<"####"<<derivedObject.getResult()<<endl;
    return 0;
}
1
Expert's answer
2021-06-05T02:13:48-0400

The output the function main is:

In base: x= 7

In derived: x= 3, y= 8; x + y = 11

****7

####11


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog