C++ Programming - Functions
Exercise : Functions - Programs
- Functions - General Questions
- Functions - Programs
41.
Which of the following statement is correct about the program given below?
#include<iostream.h>
static int Result;
class India
{
public:
void Change(int x = 10, int y = 20, int z = 30)
{
cout<< x + y + z;
}
void Display(int x = 40, float y = 50.00)
{
Result = x % x;
cout<< Result;
}
};
class Bix
{
int x, y;
public:
void Change(int x, int y = 50)
{
cout<< x + y;
}
};
class IndiaBix: public India, public Bix
{
public:
void Display(int x = 10, int xx = 100, int xxx = 1000)
{
Result = x + xx % x * x;
cout<< Result ;
}
};
int main()
{
IndiaBix objBix;
objBix.India::Display(10, 20.00);
return 0;
}
42.
Which of the following statement is correct about the program given below?
#include<iostream.h>
class IndiaBix
{
int x;
float y;
public:
void BixFunction(int = 0, float = 0.00f, char = 'A');
void BixFunction(float, int = 10.00, char = 'Z');
void BixFunction(char, char, char);
};
int main()
{
IndiaBix objBix;
objBix.BixFunction(10 * 1.0, int(56.0));
return 0;
}
void IndiaBix::BixFunction(int xx, float yy, char zz)
{
x = xx + int(yy);
cout<< "x = " << x << endl;
}
void IndiaBix::BixFunction(float xx, int yy, char zz)
{
x = zz + zz;
y = xx + yy;
cout<< " x = " << x << endl;
}
void IndiaBix::BixFunction(char xx, char yy, char zz)
{
x = xx + yy + zz;
y = float(xx * 2);
cout<< " x = " << x << endl;
}
43.
Which of the following statement is correct about the program given below?
#include<iostream.h>
static double gDouble;
static float gFloat;
static double gChar;
static double gSum = 0;
class BaseOne
{
public:
void Display(double x = 0.0, float y = 0.0, char z = 'A')
{
gDouble = x;
gFloat = y;
gChar = int(z);
gSum = gDouble + gFloat + gChar;
cout << gSum;
}
};
class BaseTwo
{
public:
void Display(int x = 1, float y = 0.0, char z = 'A')
{
gDouble = x;
gFloat = y;
gChar = int(z);
gSum = gDouble + gFloat + gChar;
cout << gSum;
}
};
class Derived : public BaseOne, BaseTwo
{
void Show()
{
cout << gSum;
}
};
int main()
{
Derived objDev;
objDev.BaseTwo::Display(10, 20, 'Z');
return 0;
}
44.
What will be the output of the following program?
#include<iostream.h>
class Base
{
public:
int S, A, M;
Base(int x, int y)
{
S = y - y;
A = x + x;
M = x * x;
}
Base(int, int y = 'A', int z = 'B')
{
S = y;
A = y + 1 - 1;
M = z - 1;
}
void Display(void)
{
cout<< S << " " << A << " " << M << endl;
}
};
class Derived : public Base
{
int x, y, z;
public:
Derived(int xx = 65, int yy = 66, int zz = 67): Base(x)
{
x = xx;
y = yy;
z = zz;
}
void Display(int n)
{
if(n)
Base::Display();
else
cout<< x << " " << y << " " << z << endl;
}
};
int main()
{
Derived objDev;
objDev.Display(-1);
return 0;
}
45.
What will be the output of the following program?
#include<iostream.h>
class Base
{
public:
char S, A, M;
Base(char x, char y)
{
S = y - y;
A = x + x;
M = x * x;
}
Base(char, char y = 'A', char z = 'B')
{
S = y;
A = y + 1 - 1;
M = z - 1;
}
void Display(void)
{
cout<< S << " " << A << " " << M << endl;
}
};
class Derived : public Base
{
char x, y, z;
public:
Derived(char xx = 65, char yy = 66, char zz = 65): Base(x)
{
x = xx;
y = yy;
z = zz;
}
void Display(int n)
{
if(n)
Base::Display();
else
cout<< x << " " << y << " " << z << endl;
}
};
int main()
{
Derived objDev;
objDev.Display(0-1);
return 0;
}
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers