Programs

Question 21 :

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

#include < iostream . h > 
int i, j; 
class IndiaParinam
{
    public:
    IndiaParinam(int x = 0, int y = 0)
    {
        i = x; 
        j = x; 
        Display();
    }
    void Display()
    {
        cout<< j <<" ";
    } 
}; 
int main()
{
    IndiaParinam objParinam(10, 20); 
    int &s = i; 
    int &z = j; 
    i++;
    cout<< s-- << " " << ++z; 
    return 0; 
}


A). The program will print the output 0 11 21.
B). The program will print the output 10 11 11.
C). The program will print the output 10 11 21.
D). The program will print the output 10 11 12.
E). It will result in a compile time error.
Answer : Option B

Question 22 :

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

#include < iostream . h > 
int x, y; 
class ParinamTest
{
    public:
    ParinamTest(int xx = 0, int yy = 0)
    {
        x = xx;
        y = yy;
        Display(); 
    } 
    void Display()
    {
        cout<< x << " " << y << " ";
    }
};
int main()
{
    ParinamTest objBT(10, 20); 
    int &rx = x; 
    int &ry = y; 
    ry = x;
    rx = y;
    cout<< rx--; 
    return 0; 
}


A). The program will print the output 0 0 10.
B). The program will print the output 10 20 10.
C). The program will print the output 10 20 9.
D). It will result in a compile time error.
Answer : Option B

Question 23 :

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

#include < iostream . h > 
class IndiaParinam
{
    int a, b, c; 
    public:
    void SetValue(int x, int y ,int z)
    {
        a = x;
        b = y;
        c = z;
    } 
    void Display()
    {
        cout<< a << " " << b << " " << c;
    } 
}; 
int main()
{
    IndiaParinam objParinam;
    int x  = 2;
    int &y = x;
    y = 5;
    objParinam.SetValue(x, ++y, x + y);
    objParinam.Display();
    return 0; 
}


A). The program will print the output 5 6 10.
B). The program will print the output 6 6 10.
C). The program will print the output 6 6 12.
D). It will result in a compile time error.
Answer : Option B

Question 24 :

What will be the output of the program given below?

#include < iostream . h > 
class ParinamBase
{
    int x;
    public:
    ParinamBase(int xx = 0)
    {
        x = xx; 
    }
    void Display()
    {
        cout<< x ;
    }
};
class ParinamDerived : public ParinamBase
{
    int y; 
    public:
    ParinamDerived(int yy = 0)
    {
        y = yy;
    }
    void Display()
    {
        cout<< y ;
    }
};
int main()
{
    ParinamBase objBase(10); 
    ParinamBase &objRef = objBase;

    ParinamDerived objDev(20); 
    objRef = objDev;

    objDev.Display(); 
    return 0; 
}


A). 0
B). 10
C). 20
D). Garbage-value
E). It will result in a compile-time/run-time error.
Answer : Option C

Question 25 :

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

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx = 0, int yy = 0)
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y;
    }
    IndiaParinam operator +(IndiaParinam z)
    {
        IndiaParinam objTemp;
        objTemp.x = x + z.x;
        objTemp.y = y + z.y;
        return objTemp; 
    }
};
int main()
{
    IndiaParinam objParinam1(90, 80); 
    IndiaParinam objParinam2(10, 20); 
    IndiaParinam objSum; 
    IndiaParinam &objRef = objSum; 
    objRef = objParinam1 + objParinam2; 
    objRef.Display(); 
    return 0; 
}


A). It will result in a runtime error.
B). It will result in a compile time error.
C). The program will print the output 9 4.
D). The program will print the output 100 100.
Answer : Option D