Cpp Programming Quiz 135 – Which of the following statements is correct?
[B]. Both data and functions can be either private or public.[C]. Member functions of a class must be private.
[D]. Constructor of a class cannot be private.
Answer: Option B
Answer: Option B
#include
class Base
{
int x, y, z;
public:
Base()
{
x = y = z = 0;
}
Base(int xx, int yy = 'A', int zz = 'B')
{
x = xx;
y = x + yy;
z = x + y;
}
void Display(void)
{
cout<< x << " " << y << " " << z << endl;
}
};
class Derived : public Base
{
int x, y;
public:
Derived(int xx = 65, int yy = 66) : Base(xx, yy)
{
y = xx;
x = yy;
}
void Display(void)
{
cout<< x << " " << y << " ";
Display();
}
};
int main()
{
Derived objD;
objD.Display();
return 0;
}
[A].The program will report compilation error.
[B].The program will run successfully giving the output 66 65.
[C].The program will run successfully giving the output 65 66.
[D].The program will run successfully giving the output 66 65 65 131 196.
Answer: Option C
#include
void Tester(float xx, float yy = 5.0);
class IndiaBix
{
float x;
float y;
public:
void Tester(float xx, float yy = 5.0)
{
x = xx;
y = yy;
cout<< ++x % --y;
}
};
int main()
{
IndiaBix objBix;
objBix.Tester(5.0, 5.0);
return 0;
}
[A].The program will print the output 0.
[B].The program will print the output 1.
[C].The program will print the output 2.
[D].The program will print the output garbage value.
Answer: Option E
Answer: Option C
Answer: Option C
#include
class IndiaBix
{
int x, y;
public:
IndiaBix()
{
x = 0;
y = 0;
}
IndiaBix(int xx, int yy)
{
x = xx;
y = yy;
}
IndiaBix(IndiaBix *objB)
{
x = objB->x;
y = objB->y;
}
void Display()
{
cout<< x << " " << y;
}
};
int main()
{
IndiaBix objBix( new IndiaBix(20, 40) );
objBix.Display();
return 0;
}
[A].The program will print the output 0 0 .
[B].The program will print the output 20 40 .
[C].The program will print the output Garbage Garbage .
[D].The program will report compile time error.
Answer: Option B
Answer: Option D