Our website is made possible by displaying online advertisements to our visitors. Please consider supporting us by whitelisting our website.

C++ Programming

Cpp Programming Quiz 198 – What is correct about the following program?

Question: What is correct about the following program?

#include
class Addition
{
int x;
public:
Addition()
{
x = 0;
}
Addition(int xx)
{
x = xx;
}
Addition operator + (int xx = 0)
{
Addition objTemp;
objTemp.x = x + xx;
return(objTemp);
}
void Display(void)
{
cout<< x << endl; } }; int main() { Addition objA(15), objB; objB = objA + 5; objB.Display(); return 0; }

[A].The program will print the output 20.
[B].The program will report run time error.
[C].The program will print the garbage value.
[D].Compilation fails due to 'operator +' cannot have default arguments. 

Answer: Option D

Cpp Programming Quiz 198 – What is correct about the following program? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 199 – What will be the output of the following program?

Question: What will be the output of the following program?

#include
class Base
{
int x, y;
public:
Base()
{
x = y = 0;
}
Base(int xx)
{
x = xx;
}
Base(int p, int q = 10)
{
x = p + q;
y = q;
}
void Display(void)
{
cout<< x << " " << y << endl; } }objDefault(1, 1); class Derived: public Base { Base obj; public: Derived(int xx, int yy): Base(xx, xx + 1) { } Derived(Base objB = objDefault) { } }; int main() { Derived objD(5, 3); Derived *ptrD = new Derived(objD); ptrD->Display();
delete ptrD;
return 0;
}

[A].3 2
[B].8 3
[C].11 6
[D].11 10 

Answer: Option C

Cpp Programming Quiz 199 – What will be the output of the following program? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 200 – Which of the following statement is correct about the program given below?

Question: Which of the following statement is correct about the program given below?

#include
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; }

[A].The program will print the output 2.
[B].The program will print the output 12.
[C].The program will report run time error.
[D].The program will not compile successfully. 

Answer: Option D

Cpp Programming Quiz 200 – Which of the following statement is correct about the program given below? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 201 – What will be the output of the following program?

Question: What will be the output of the following program?

#include
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;
}

[A].10 10
[B].12 10
[C].12 21
[D].12 31 

Answer: Option A

Cpp Programming Quiz 201 – What will be the output of the following program? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 202 – What is correct about the following program?

Question: What is correct about the following program?

#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

Cpp Programming Quiz 202 – What is correct about the following program? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 203 – What will be the output of the following program?

Question: What will be the output of the following program?

#include
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; }

[A].A A A
[B].A B A
[C].A B C
[D].Garbage Garbage Garbage 

Answer: Option A

Cpp Programming Quiz 203 – What will be the output of the following program? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 204 – Which of the following statement is correct about the program given below?

Question: Which of the following statement is correct about the program given below?

#include
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; }

[A].The program will print the output 0.
[B].The program will print the output 10.
[C].The program will print the output 30.
[D].The program will print the output 40. 

Answer: Option A

Cpp Programming Quiz 204 – Which of the following statement is correct about the program given below? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 205 – What will be the output of the following program?

Question: What will be the output of the following program?

#include
class IndiaBix
{
int K;
public:
void BixFunction(float, int , char);
void BixFunction(float, char, char);

};
int main()
{
IndiaBix objIB;
objIB.BixFunction(15.09, 'A', char('A' + 'A'));
return 0;
}
void IndiaBix::BixFunction(float, char y, char z)
{
K = int(z);
K = int(y);
K = y + z;
cout<< "K = " << K << endl; }

[A]. The program will print the output M = 130.
[B]. The program will print the output M = 195.
[C]. The program will print the output M = -21.
[D]. The program will print the output M = -61. 

Answer: Option D

Cpp Programming Quiz 205 – What will be the output of the following program? Read More »

Cpp Programming, Functions

Cpp Programming Quiz 206 – Which of the following statement is correct about the program given below?

Question: Which of the following statement is correct about the program given below?

#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

Cpp Programming Quiz 206 – Which of the following statement is correct about the program given below? Read More »

Constructors And Destructors, Cpp Programming

Cpp Programming Quiz 207 – Which of the following statement is correct about the program given below?

Question: Which of the following statement is correct about the program given below?

#include
class IndiaBix
{
int x;
public:
IndiaBix()
{
x = 0;
}
IndiaBix(int xx)
{
x = xx;
}
IndiaBix(IndiaBix &objB)
{
x = objB.x;
}
void Display()
{
cout<< x << " "; } }; int main() { IndiaBix objA(25); IndiaBix objB(objA); IndiaBix objC = objA; objA.Display(); objB.Display(); objC.Display(); return 0; }

[A].The program will print the output 25 25 25 .
[B].The program will print the output 25 Garbage 25 .
[C].The program will print the output Garbage 25 25 .
[D].The program will report compile time error. 

Answer: Option A

Cpp Programming Quiz 207 – Which of the following statement is correct about the program given below? Read More »

Constructors And Destructors, Cpp Programming