C++ Programming - Functions

Exercise : Functions - Programs
31.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
    int x, y, z; 
    public:
    IndiaBix(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; 
    IndiaBix objBix(x, y, z); 
    return 0; 
}
The program will print the output 1 0 3.
The program will print the output 1 0 4.
The program will print the output 1 1 3.
The program will print the output 1 1 4.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

32.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BixArray
{
    int array[3][3];
    public:
    BixArray(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()
{
    BixArray objBA;
    objBA.Display();
    return 0; 
}
The program will report error on compilation.
The program will display 9 garbage values.
The program will display NULL 9 times.
The program will display 0 1 2 1 2 3 2 3 4.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

33.
What will be the output of the following program?
#include<iostream.h> 
struct IndiaBix
{
    int arr[5]; 
    public:
    void BixFunction(void);
    void Display(void);
};
void IndiaBix::Display(void)
{
    for(int i = 0; i < 5; i++) 
        cout<< arr[i] << " " ;
}
void IndiaBix::BixFunction(void)
{
    static int i = 0, j = 4; 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp   ; 
    i++;
    j--;
    if(j != i) BixFunction();
}
int main()
{
    IndiaBix objBix = {{ 5, 6, 3, 9, 0 }};
    objBix.BixFunction();
    objBix.Display();
    return 0; 
}
0 9 3 6 5
9 3 6 5 0
5 6 3 9 0
5 9 3 6 0
Answer: Option
Explanation:
No answer description is available. Let's discuss.

34.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x; 
    float y; 
    public:
    IndiaBix(int x)
    {
        x = x;
    }
    IndiaBix(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; 
    IndiaBix objBix(val); 
    IndiaBix objTmp();
    objBix.SetValue(val, 3.14f); 
    objBix.Display(); 
    return 0; 
}
The program will print the output 2.
The program will print the output 12.
The program will report run time error.
The program will not compile successfully.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

35.
What will be the output of the following program?
#include<iostream.h> 
struct BixArray
{
    int arr[5]; 
    public:
    void BixFunction();
    void Display();
};
void BixArray::BixFunction()
{
    static int i = 0, j = 4; 
    i++;
    j--;
    if(j > 0)
        BixFunction(); 
    int tmp = arr[i]; 
    arr[i]  = arr[j]; 
    arr[j]  = tmp; 
    i--;
    j++;
}
void BixArray::Display()
{
    for(int i = 0; i < 5; i++)
        cout<< arr[i] << " ";
} 
int main()
{
    BixArray objArr = {{5, 6, 3, 9, 0}};
    objArr.BixFunction();
    objArr.Display();
    return 0; 
}
5 6 3 9 0
0 9 3 6 5
0 5 6 3 9
0 6 3 9 5
None of these
Answer: Option
Explanation:
No answer description is available. Let's discuss.