C++ Programming - Objects and Classes

Exercise : Objects and Classes - Programs
11.
What will be the output of the following program?
#include<iostream.h> 
class IndiaBix
{
    static int count; 
    public:
    static void First(void)
    {
        count = 10;
    }
    static void Second(int x)
    {
        count = count + x; 
    }
    static void Display(void)
    {
        cout<< count << endl;
    } 
};
int IndiaBix::count = 0; 
int main()
{
    IndiaBix :: First();
    IndiaBix :: Second(5);
    IndiaBix :: Display();
    return 0; 
}
0  
5
10
15
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

12.
What will be the output of the following program?
#include<iostream.h> 
class BixBase
{
    public:
        float x; 
}; 
class BixDerived : public BixBase
{
    public: 
        char ch; 
        void Process()
        {
            ch = (int)((x=12.0)/3.0);
        }
        void Display()
        {
            cout<< (int)ch;
        } 
}; 
int main()
{
    class BixDerived  *objDev = new BixDerived;
    objDev->Process();
    objDev->Display();
    return 0; 
}
The program will print the output 4.
The program will print the ASCII value of 4.
The program will print the output 0.
The program will print the output garbage.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

13.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<process.h> 
class IndiaBix
{
    static int x; 
    public:
    IndiaBix()
    {
        if(x == 1)
            exit(0); 
        else
            x++;
    }
    void Display()
    {
        cout<< x << " ";
    }
};
int IndiaBix::x = 0; 
int main()
{
    IndiaBix objBix1; 
    objBix1.Display(); 
    IndiaBix objBix2; 
    objBix2.Display(); 
    return 0; 
}
The program will print the output 1 2.
The program will print the output 0 1.
The program will print the output 1 1.
The program will print the output 1.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

14.
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
{
    private:
        BixBase objBase; 
    public:
    BixDerived(int xx, int yy) : objBase(xx, 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 Garbage-value.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

15.
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.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 Garbage-value.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.