Programs (Set - 3)

Question 11 :

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

#include < iostream . h > 
static int Result;
class India
{
    public:
    void Change(int x = 10, int y = 20, int z = 30)
    {
        cout<< x + y + z;
    }
    void Display(int x = 40, float y = 50.00)
    {
        Result = x % x; 
        cout<< Result;
    }
};
class Parinam
{
    int x, y; 
    public:
    void Change(int x, int y = 50)
    {
        cout<< x + y;
    }
};
class IndiaParinam: public India, public Parinam
{
    public:
    void Display(int x = 10, int xx = 100, int xxx = 1000)
    {
        Result = x + xx % x * x;
        cout<< Result ; 
    }
};
int main()
{
    IndiaParinam objParinam;
    objParinam.India::Display(10, 20.00);
    return 0; 
}


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

Question 12 :

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

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    float y; 
    public:
    void ParinamFunction(int = 0, float = 0.00f, char = 'A');
    void ParinamFunction(float, int = 10.00, char = 'Z');
    void ParinamFunction(char, char, char);
};
int main()
{
    IndiaParinam objParinam;
    objParinam.ParinamFunction(10 * 1.0, int(56.0)); 
    return 0;
}
void IndiaParinam::ParinamFunction(int xx, float yy, char zz)
{
    x = xx + int(yy);
    cout<< "x = " << x << endl;
}
void IndiaParinam::ParinamFunction(float xx, int yy, char zz)
{
    x = zz + zz;
    y = xx + yy;
    cout<< " x = " << x << endl;
}
void IndiaParinam::ParinamFunction(char xx, char yy, char zz)
{
    x = xx + yy + zz; 
    y = float(xx * 2); 
    cout<< " x = " << x << endl;
}


A). The program will print the output x = 65.
B). The program will print the output x = 66.
C). The program will print the output x = 130.
D). The program will print the output x = 180.
E). The program will not compile successfully.
Answer : Option D

Question 13 :

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

#include < iostream . h > 
static double gDouble; 
static float  gFloat; 
static double gChar; 
static double gSum = 0; 
class BaseOne
{
    public:
    void Display(double x = 0.0, float y = 0.0, char z = 'A')
    {
        gDouble = x;
        gFloat  = y;
        gChar   = int(z);
        gSum    = gDouble + gFloat + gChar;
        cout << gSum; 
    }
};
class BaseTwo
{
    public: 
    void Display(int x = 1, float y = 0.0, char z = 'A')
    {
        gDouble = x;
        gFloat  = y;
        gChar   = int(z); 
        gSum    = gDouble + gFloat + gChar;
        cout << gSum;
    }
};
class Derived : public BaseOne, BaseTwo
{
    void Show()
    {
        cout << gSum;
    } 
}; 
int main()
{
    Derived objDev;
    objDev.BaseTwo::Display(10, 20, 'Z');
    return 0; 
}


A). The program will print the output 0.
B). The program will print the output 120.
C). The program will report run-time error.
D). The program will report compile-time error.
E). The program will print the output garbage value.
Answer : Option D

Question 14 :

What will be the output of the following program?

#include < iostream . h > 
class Base
{
    public:
    int S, A, M; 
    Base(int x, int y)
    {
        S = y - y;
        A = x + x; 
        M = x * x;
    }
    Base(int, int y = 'A', int z = 'B')
    {
        S = y;
        A = y + 1 - 1; 
        M = z - 1;
    }
    void Display(void)
    {
        cout<< S << " " << A << " " << M << endl;
    }
};
class Derived : public Base
{
    int x, y, z; 
    public:
    Derived(int xx = 65, int yy = 66, int zz = 67): Base(x)
    {
        x = xx; 
        y = yy;
        z = zz;
    }
    void Display(int n)
    {
        if(n)
            Base::Display(); 
        else
            cout<< x << " " << y << " " << z << endl; 
    }
};
int main()
{
    Derived objDev; 
    objDev.Display(-1); 
    return 0;
}


A). 65 65 65
B). 65 66 67
C). A A A
D). A B C
E). The program will report compile time error.
Answer : Option A

Question 15 :

What will be the output of the following program?

#include < iostream . h > 
class Base
{
    public:
    char S, A, M; 
    Base(char x, char y)
    {
        S = y - y;
        A = x + x; 
        M = x * x;
    }
    Base(char, char y = 'A', char z = 'B')
    {
        S = y;
        A = y + 1 - 1; 
        M = z - 1;
    }
    void Display(void)
    {
        cout<< S << " " << A << " " << M << endl;
    }
};
class Derived : public Base
{
    char x, y, z; 
    public:
    Derived(char xx = 65, char yy = 66, char zz = 65): Base(x)
    {
        x = xx; 
        y = yy;
        z = zz;
    }
    void Display(int n)
    {
        if(n)
            Base::Display(); 
        else
            cout<< x << " " << y << " " << z << endl; 
    }
};
int main()
{
    Derived objDev; 
    objDev.Display(0-1); 
    return 0;
}


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