Programs

Question 16 :

What will be the out of the following program?

#include < iostream . h > 
class ParinamBase
{
    protected:
    int x, y; 
    public:
    ParinamBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
    void Show()
    {
        cout<< x * this->y << endl;
    }
};
class ParinamDerived
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : objBase(xx, yy)
    {
        objBase.Show();
    } 
    ~ParinamDerived()
    { }
};
int main()
{
    ParinamDerived objDev(10, 20); 
    return 0;
}


A). 0
B). 100
C). 200
D). 400
E). The program will report compile time error.
Answer : Option C

Question 17 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    public:
        IndiaParinam()
        {
           x = 0;
        }
        IndiaParinam(int xx)
        {
            x = xx; 
        }
        IndiaParinam(IndiaParinam &objB)
        {
            x = objB.x; 
        }
        void Display()
        {
            cout<< x << " ";
        }
};
int main()
{
    IndiaParinam objA(25);
    IndiaParinam objB(objA);
    IndiaParinam objC = objA;
    objA.Display();
    objB.Display();
    objC.Display();
    return 0; 
}


A). The program will print the output 25 25 25 .
B). The program will print the output 25 Garbage 25 .
C). The program will print the output Garbage 25 25 .
D). The program will report compile time error.
Answer : Option A

Question 18 :

Which of the following statement is correct about the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
        IndiaParinam()
        {
            x = 0;
            y = 0; 
        }
        IndiaParinam(int xx, int yy)
        {
            x = xx;
            y = yy; 
        }
        IndiaParinam(IndiaParinam *objB)
        {
            x = objB->x;
            y = objB->y; 
        }
        void Display()
        {
            cout<< x << " " << y;
        }
};
int main()
{
    IndiaParinam objParinam( new IndiaParinam(20, 40) );
    objParinam.Display();
    return 0; 
}


A). The program will print the output 0 0 .
B). The program will print the output 20 40 .
C). The program will print the output Garbage Garbage .
D). The program will report compile time error.
Answer : Option B

Question 19 :

What will be the out of the following program?

#include < iostream . h > 
class ParinamBase
{
    public:
    int x, y; 
    public:
    ParinamBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class ParinamDerived : public ParinamBase
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : ParinamBase(xx), objBase(yy)
    {
        cout << this->x   << " " 
             << this->y   << " "  
             << objBase.x << " "
             << objBase.y << " ";
    } 
    ~ParinamDerived()
    { }
};
int main()
{
    ParinamDerived objDev(11, 22); 
    return 0;
}


A). 11 22 0 0
B). 11 0 0 22
C). 11 0 22 0
D). 11 22 11 22
E). The program will report compile time error.
Answer : Option C

Question 20 :

What will be the out of the following program?

#include < iostream . h > 
class ParinamBase
{
    public:
    int x, y; 
    public:
    ParinamBase(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy; 
    } 
 };
class ParinamDerived : public ParinamBase
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : ParinamBase(xx), objBase(yy)
    {
        cout << x          << " " 
             << this->x    << " "  
             << ParinamBase::x << " "     
             << this->objBase.x ;
    } 
    ~ParinamDerived()
    { }
};
int main()
{
    ParinamDerived objDev(11, 22); 
    return 0;
}


A). 11 22 0 0
B). 11 11 0 22
C). 11 11 11 0
D). 11 11 11 22
E). The program will report compile time error.
Answer : Option D