Programs

Question 11 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    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 IndiaParinam::count = 0; 
int main()
{
    IndiaParinam :: First();
    IndiaParinam :: Second(5);
    IndiaParinam :: Display();
    return 0; 
}


A). 0
B). 5
C). 10
D). 15
E). The program will report compile time error.
Answer : Option D

Question 12 :

What will be the output of the following program?

#include < iostream . h > 
class ParinamBase
{
    public:
        float x; 
}; 
class ParinamDerived : public ParinamBase
{
    public: 
        char ch; 
        void Process()
        {
            ch = (int)((x=12.0)/3.0);
        }
        void Display()
        {
            cout<< (int)ch;
        } 
}; 
int main()
{
    class ParinamDerived  *objDev = new ParinamDerived;
    objDev->Process();
    objDev->Display();
    return 0; 
}


A). The program will print the output 4.
B). The program will print the ASCII value of 4.
C). The program will print the output 0.
D). The program will print the output garbage.
Answer : Option A

Question 13 :

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

#include < iostream . h >
#include < process . h > 
class IndiaParinam
{
    static int x; 
    public:
    IndiaParinam()
    {
        if(x == 1)
            exit(0); 
        else
            x++;
    }
    void Display()
    {
        cout<< x << " ";
    }
};
int IndiaParinam::x = 0; 
int main()
{
    IndiaParinam objParinam1; 
    objParinam1.Display(); 
    IndiaParinam objParinam2; 
    objParinam2.Display(); 
    return 0; 
}


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

Question 14 :

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
{
    private:
        ParinamBase objBase; 
    public:
    ParinamDerived(int xx, int yy) : objBase(xx, 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 Garbage-value.
D). The program will report compile time error.
Answer : Option B

Question 15 :

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.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 Garbage-value.
D). The program will report compile time error.
Answer : Option A