Pass the C++ Institute C++ Certified Professional Programmer CPA-21-02 Questions and answers with CertsForce

Viewing page 8 out of 8 pages
Viewing questions 71-80 out of questions
Questions # 71:

Which of the following is a logical operator?

Options:

A.

&


B.

&&


C.

||


D.

!


Expert Solution
Questions # 72:

What will be the output of the program?

#include

using namespace std;

int fun(int);

int main()

{

cout << fun(5);

return 0;

}

int fun(int i)

{

return i*i;

}

Options:

A.

25


B.

5


C.

0


D.

1


Expert Solution
Questions # 73:

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class A

{

public:

virtual void Print(){ cout<<"A";}

};

class B:public A

{

public:

void Print(){ cout<< "B";}

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

Options:

A.

It prints: AB


B.

It prints: AA


C.

It prints: BA


D.

It prints: BB


Expert Solution
Questions # 74:

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class complex{

double re, im;

public:

complex() : re(1),im(0.4) {}

complex operator+(complex &t);

void Print() { cout << re << " " << im; }

};

complex complex::operator+ (complex &t){

complex temp;

temp.re = this?>re + t.re;

temp.im = this?>im + t.im;

return temp;

}

int main(){

complex c1,c2,c3;

c3 = c1 + c2;

c3.Print();

}

Options:

A.

It prints: 1 0.4


B.

It prints: 2 0.8


C.

It prints: 0 0


D.

Garbage value


Expert Solution
Questions # 75:

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

inline float sum(float a,float b)

{

return a+b;

}

int main()

{

float a,b;

a = 1.5; b = 3.4;

cout<

return 0;

}

Options:

A.

It prints: 0


B.

It prints: 4.9


C.

It prints: 5


D.

It prints: 4


Expert Solution
Questions # 76:

What happens when you attempt to compile and run the following code?

#include

using namespace std;

class BaseC

{

int *ptr;

public:

BaseC() { ptr = new int(10);}

BaseC(int i) { ptr = new int(i); }

~BaseC() { delete ptr; }

void Print() { cout << *ptr; }

};

int main()

{

BaseC *o = new BaseC(5);

o?>Print();

}

Options:

A.

It prints: 5


B.

It prints: 10


C.

It prints: 1


D.

It prints: 0


Expert Solution
Questions # 77:

What happens when you attempt to compile and run the following code?

#include

#include

using namespace std;

class A {

public:

string s;

A(string s) { this?>s = s; }

};

class B {

public:

string s;

B (A a) { this?>s = a.s; }

void print() { cout<

};

int main()

{

A a("Hello world");

B b=a;

b.print();

}

Options:

A.

It prints: Hello world


B.

It prints: Hello


C.

Compilation error


D.

None of these


Expert Solution
Viewing page 8 out of 8 pages
Viewing questions 71-80 out of questions