C++ Programming - Objects and Classes

Exercise : Objects and Classes - Programs
16.
What will be the output of the following program?
#include<iostream.h> 
class A
{
    public:
    void BixFunction(void)
    {
        cout<< "Class A" << endl;
    }
};
class B: public A
{
    public:
    void BixFunction(void)
    {
        cout<< "Class B" << endl;
    } 
};
class C : public B
{
    public:
    void BixFunction(void)
    {
        cout<< "Class C" << endl;
    } 
};
int main()
{
    A *ptr;
    B objB;
    ptr = &objB;
    ptr = new C();
    ptr->BixFunction();
    return 0; 
}
Class A.
Class B.
Class C.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

17.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BixBase
{
    int x, y; 
    public:
    BixBase(int xx = 10, int yy = 10)
    {
        x = xx;
        y = yy;
    }
    void Show()
    {
        cout<< x * y << endl;
    }
};
class BixDerived : public BixBase
{
    private:
        BixBase objBase; 
    public:
    BixDerived(int xx, int yy) : BixBase(xx, yy), objBase(yy, yy)
    {
        objBase.Show();
    }
};
int main()
{
    BixDerived objDev(10, 20);
    return 0; 
}
The program will print the output 100.
The program will print the output 200.
The program will print the output 400.
The program will print the output Garbage-value.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

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; 
}
1 2
10 20
11 22
Garbage Garbage
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

19.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class IndiaBix
{
    char str[50]; 
    char tmp[50]; 
    public:
    IndiaBix(char *s)
    {
        strcpy(str, s);
    }
    int BixFunction()
    {
        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 IndiaBix.com!";
    IndiaBix objBix(txt); 
    cout<< objBix.BixFunction();
    return 0;
}
1
2
24
25
Answer: Option
Explanation:
No answer description is available. Let's discuss.