Programs

Question 6 :

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

#include < iostream . h > 
class IndiaParinam
{
    int *p; 
    public:
    IndiaParinam(int xx, char ch)
    {
        p  = new int(); 
        *p = xx + int(ch); 
        cout<< *p;
    }
    ~IndiaParinam() 
    {
        delete p;
    }
};
int main()
{
    IndiaParinam objParinam(10, 'B'); 
    return 0;
}


A). The program will print the output 76.
B). The program will print the output 108.
C). The program will print the output garbage value.
D). The program will report compile time error.
Answer : Option A

Question 7 :

Which of the following constructor is used in the program given below?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx = 10, int yy = 20 )
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y << endl;
    } 
    ~IndiaParinam()
    { } 
};
int main()
{
    IndiaParinam objParinam; 
    objParinam.Display(); 
    return 0;
}


A). Copy constructor
B). Simple constructor
C). Non-parameterized constructor
D). Default constructor
Answer : Option D

Question 8 :

What will be the output of the following program?

#include < iostream . h >
class ParinamBase
{   
    public:
    ParinamBase()
    {
        cout<< "Base OK. "; 
    }
};
class ParinamDerived: public ParinamBase
{
    public:
    ParinamDerived()
    { 
        cout<< "Derived OK. "; 
    }
    ~ParinamDerived()
    { 
        cout<< "Derived DEL. "; 
    }
};
int main()
{
    ParinamBase    objB;
    ParinamDerived objD;
    objD.~ParinamDerived();
    return 0;
}


A). Base OK. Derived OK. Derived DEL.
B). Base OK. Base OK. Derived OK. Derived DEL.
C). Base OK. Derived OK. Derived DEL. Derived DEL.
D). Base OK. Base OK. Derived OK. Derived DEL. Derived DEL.
E). The program will report compile time error.
Answer : Option D

Question 9 :

What will be the output of the following program?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx)
    {
        x = ++xx;
    } 
    ~IndiaParinam()
    {
        cout<< x - 1 << " ";
    }
    void Display()
    {
        cout<< --x + 1 << " ";
    } 
};
int main()
{
    IndiaParinam objParinam(5);
    objParinam.Display();
    int *p = (int*) &objParinam;
    *p = 40;
    objParinam.Display();
    return 0; 
}


A). 6 6 4
B). 6 6 5
C). 5 40 38
D). 6 40 38
E). 6 40 39
Answer : Option D

Question 10 :

What is the technical word for the function ~IndiaParinam() defined in the following program?

#include < iostream . h > 
class IndiaParinam
{
    int x, y; 
    public:
    IndiaParinam(int xx = 10, int yy = 20 )
    {
        x = xx; 
        y = yy;
    }
    void Display()
    {
        cout<< x << " " << y << endl;
    } 
    ~IndiaParinam()
    { } 
};
int main()
{
    IndiaParinam objParinam; 
    objParinam.Display(); 
    return 0;
}


A). Constructor
B). Destructor
C). Default Destructor
D). Function Template
Answer : Option B