Programs

Question 16 :

What will be the output of the following program?

#include < iostream . h > 
class A
{
    public:
    void ParinamFunction(void)
    {
        cout<< "Class A" << endl;
    }
};
class B: public A
{
    public:
    void ParinamFunction(void)
    {
        cout<< "Class B" << endl;
    } 
};
class C : public B
{
    public:
    void ParinamFunction(void)
    {
        cout<< "Class C" << endl;
    } 
};
int main()
{
    A *ptr;
    B objB;
    ptr = &objB;
    ptr = new C();
    ptr->ParinamFunction();
    return 0; 
}


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

Question 17 :

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

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


A). The program will print the output 100.
B). The program will print the output 200.
C). The program will print the output 400.
D). The program will print the output Garbage-value.
E). The program will report compile time error.
Answer : Option C

Question 18 :

What will be the output of the following program?

#include < iostream . h > 
class Point
{
    int x, y; 
    public:
    Point(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    Point operator + (Point objPoint)
    {
        Point objTmp;
        objTmp.x = objPoint.x + this->x; 
        objTmp.y = objPoint.y + this->y;
        return objTmp;
    }
    void Display(void)
    {
        cout<< x << " " << y;
    }
};
int main()
{
    Point objP1;
    Point objP2(1, 2);
    Point objP3 = objP1 + objP2;
    objP3.Display(); 
    return 0; 
}


A). 1 2
B). 10 20
C). 11 22
D). Garbage Garbage
E). The program will report compile time error.
Answer : Option C

Question 19 :

What will be the output of the following program?

#include < iostream . h >
#include < string . h > 
class IndiaParinam
{
    char str[50]; 
    char tmp[50]; 
    public:
    IndiaParinam(char *s)
    {
        strcpy(str, s);
    }
    int ParinamFunction()
    {
        int i = 0, j = 0; 
        while(*(str + i))
        {
            if(*(str + i++) == ' ')
                *(tmp + j++) = *(str + i);
        }
        *(tmp + j) = 0; 
        return strlen(tmp); 
    }
};
int main()
{
    char txt[] = "Welcome to IndiaParinam.com!";
    IndiaParinam objParinam(txt); 
    cout<< objParinam.ParinamFunction();
    return 0;
}


A). 1
B). 2
C). 24
D). 25
Answer : Option B