C++ Programming - Functions

Exercise : Functions - Programs
26.
What will be the output of the following program?
#include<iostream.h> 
class IndiaBix
{
    public: 
    int x, y;
    IndiaBix(int xx = 10, int yy = 20)
    {
        x = xx;
        y = yy; 
    }
    void Exchange(int *, int *);
};
int main()
{
    IndiaBix objA(30, 40); 
    IndiaBix objB(50); 
    objA.Exchange(&objA.x, &objB.y); 
    cout<< objA.x << " " << objB.y << endl; 
    return 0;
}
void IndiaBix::Exchange(int *x, int *y)
{
    int t;
    t  = *x;
    *x = *y;
    *y = t ; 
}
20 10
30 20
20 30
30 40
50 30
Answer: Option
Explanation:
No answer description is available. Let's discuss.

27.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class BixArray
{
    int Matrix[3][3]; 
    public:
    BixArray()
    {
        for(int i = 0; i<3; i++)
           for(int j = 0; j < 3; j++) 
              Matrix[j][i] = i + j; 
    }
    void Display(void)
    {
        for(int i = 0; i < 3; i++)
           for(int j = 0; j < 3; j++) 
              cout<< Matrix[j][i] << " "; 
    } 
}; 
int main()
{
    BixArray objBix;
    objBix.Display();
    return 0; 
}
The program will display the output 4 3 2 3 2 1 2 1 0.
The program will display the output 0 1 2 1 2 3 2 3 4.
The program will display the output 9 garbage values.
The program will report error on compilation.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

28.
What will be the output of the following program?
#include<iostream.h> 
class IndiaBix
{
    int x, y, z; 
    public:
    void Apply(int xx = 12, int yy = 21, int zz = 9)
    {
        x = xx;
        y = yy += 10;
        z = x -= 2;
    }
    void Display(void)
    {
        cout<< x << " " << y << endl; 
    } 
    void SetValue(int xx, int yy)
    {
        Apply(xx, 0, yy);
    }
};
int main()
{
    IndiaBix *pBix= new IndiaBix;
   (*pBix).SetValue(12, 20);
    pBix->Display();
    delete pBix;
    return 0; 
}
10 10
12 10
12 21
12 31
The program will report compilation error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.

29.
What will be the output of the following program?
#include<iostream.h>
#include<string.h> 
class IndiaBix
{
    char txtMsg[50]; 
    public:
    IndiaBix(char *str = NULL)
    {
    if(str != NULL)
       strcpy(txtMsg, str);
    }
    int BixFunction(char ch);
};
int IndiaBix::BixFunction(char ch)
{
    static int i = 0;
    if(txtMsg[i++] == ch)
        return strlen((txtMsg + i)) - i;
    else
        return BixFunction(ch);
}
int main()
{
    IndiaBix objBix("Welcome to IndiaBix.com!");
    cout<< objBix.BixFunction('t');
    return 0;
}
6
8
9
15
16
Answer: Option
Explanation:
No answer description is available. Let's discuss.

30.
Which of the following statement is correct about the program given below?
#include<iostream.h>
#include<string.h>
#include<malloc.h>
class BixString
{
    char txtName[20]; 
    public:
    BixString(char *txtTemp = NULL)
    {
        if(txtTemp != NULL)
        strcpy(txtName, txtTemp);
    }
    void Display(void)
    {
        cout<<txtName;
    }
};
int main()
{
    char *txtName = (char*)malloc(10);
    strcpy(txtName, "IndiaBIX");
    *txtName = 48;
    BixString objTemp(txtName);
    cout<< sizeof(txtName);
    return 0; 
}
Above program will display IndiaBIX 8.
Above program will display IndiaBIX 9.
Above program will display size of integer.
Above program will display IndiaBIX and size of integer.
Above program will display 1.
Answer: Option
Explanation:
No answer description is available. Let's discuss.