Programs (Set - 3)

Question 1 :

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

#include < iostream . h >
class IndiaParinam
{
    int x, y, z; 
    public:
    IndiaParinam(int x = 100, int y = 30, int z = 0)
    {
        this->x = x; 
        this->y = y;
        this->z = z; 
        Display();
    }
    void Display()
    {
        cout<< x << " " << y << " " << z;
    }
};
int main()
{
    int a = 0, b = 1, c = 2; 
    int &x = ++a; 
    int &y = --b; 
    int z = c + b - -c; 
    IndiaParinam objParinam(x, y, z); 
    return 0; 
}


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

Question 2 :

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

#include < iostream . h > 
class ParinamArray
{
    int array[3][3];
    public:
    ParinamArray(int arr[3][3] = NULL)
    { 
        if(arr != NULL)
        for(int i = 0; i < 3; i++) 
            for(int j = 0; j < 3; j++) 
                array[i][j] = i+j; 
    } 
    void Display(void)
    {
        for(int i = 0; i < 3; i++) 
            for(int j = 0; j < 3; j++)
                cout<< array[i][j] << " "; 
    }
};
int main()
{
    ParinamArray objBA;
    objBA.Display();
    return 0; 
}


A). The program will report error on compilation.
B). The program will display 9 garbage values.
C). The program will display NULL 9 times.
D). The program will display 0 1 2 1 2 3 2 3 4.
Answer : Option B

Question 3 :

What will be the output of the following program?

#include < iostream . h > 
struct IndiaParinam
{
    int arr[5]; 
    public:
    void ParinamFunction(void);
    void Display(void);
};
void IndiaParinam::Display(void)
{
    for(int i = 0; i < 5; i++) 
        cout<< arr[i] << " " ;
}
void IndiaParinam::ParinamFunction(void)
{
    static int i = 0, j = 4; 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp   ; 
    i++;
    j--;
    if(j != i) ParinamFunction();
}
int main()
{
    IndiaParinam objParinam = {{ 5, 6, 3, 9, 0 }};
    objParinam.ParinamFunction();
    objParinam.Display();
    return 0; 
}


A). 0 9 3 6 5
B). 9 3 6 5 0
C). 5 6 3 9 0
D). 5 9 3 6 0
Answer : Option A

Question 4 :

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

#include < iostream . h > 
class IndiaParinam
{
    int x; 
    float y; 
    public:
    IndiaParinam(int x)
    {
        x = x;
    }
    IndiaParinam(int p = 0, int q = 10)
    {
        x = p += 2; 
        y = q * 1.0f;
    }
    void SetValue(int &y, float z)
    {
        x = y;
        y = (int)z;
    }
    void Display(void)
    {
        cout<< x;
    }
};
int main()
{
    int val = 12; 
    IndiaParinam objParinam(val); 
    IndiaParinam objTmp();
    objParinam.SetValue(val, 3.14f); 
    objParinam.Display(); 
    return 0; 
}


A). The program will print the output 2.
B). The program will print the output 12.
C). The program will report run time error.
D). The program will not compile successfully.
Answer : Option D

Question 5 :

What will be the output of the following program?

#include < iostream . h > 
struct ParinamArray
{
    int arr[5]; 
    public:
    void ParinamFunction();
    void Display();
};
void ParinamArray::ParinamFunction()
{
    static int i = 0, j = 4; 
    i++;
    j--;
    if(j > 0)
        ParinamFunction(); 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp; 
    i--;
    j++;
}
void ParinamArray::Display()
{
    for(int i = 0; i < 5; i++)
        cout<< arr[i] << " ";
} 
int main()
{
    ParinamArray objArr = {{5, 6, 3, 9, 0}};
    objArr.ParinamFunction();
    objArr.Display();
    return 0; 
}


A). 5 6 3 9 0
B). 0 9 3 6 5
C). 0 5 6 3 9
D). 0 6 3 9 5
E). None of these
Answer : Option D