C++ Programming - Functions
Exercise : Functions - Programs
- Functions - General Questions
- 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;
}
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;
}
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;
}
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;
}
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;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers