Labour Day Special - Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: top65certs

Newly Released C++ Institute CPP Exam PDF

Page: 6 / 9
Total 228 questions

C++ Certified Professional Programmer Questions and Answers

Question 21

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

#include

#include

#include

using namespace std;

class A {

int a;

public:

A(int a) : a(a) {}

int getA() const { return a; } void setA(int a) { this?>a = a; }

};

struct Even {

bool operator ()(const A & a, const A &b) {

return (a.getA() % 2)==b.getA() % 2;

}

};

int main () {

int t[] = {1,2,3,2,3,5,1,2,7,3,2,1,10, 4,4,5};

deque d (t,t+15);

deque::iterator it = search_n(d.begin(), d.end(), 3, 2, Even());

cout<< it?d.begin()<

return 0;

}

Program outputs:

Options:

A.

compilation error

B.

12

C.

3

D.

1

E.

15

Question 22

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

#include

#include

#include

#include

using namespace std;

class B { int val;

public:

B(int v):val(v){}

int getV() const {return val;} bool operator < (const B & v) const { return val

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

Out(ostream & o): out(o){}

void operator() (const T & val ) { out<

int main() {

int t[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

deque d1(t, t+10);

sort(d1.begin(), d1.end());

set s1(t,t+10);

cout<<binary_search(s1.begin(),s1.end(), B(4))<<" "<

return 0;

}

Program outputs:

Options:

A.

1 0

B.

1 1

C.

0 0

D.

0 1

E.

compilation error

Question 23

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

#include

#include

#include

using namespace std;

int main ()

{

int t[] = {1, 2 ,3 ,4 ,5, 6 , 7, 8 , 9, 10};

vectorv1(t, t+10);

dequed1(t, t+10);

d1.empty();

v1.empty();

if (v1.isempty())

{

cout<<"I am empty ";

}

else

{

cout<<"I am not empty ";

}

cout<<v1.size()<<" "<

return 0;

}

Options:

A.

program outputs: I am empty 0 0

B.

program outputs: I am not empty 0 0

C.

compilation error

D.

program outputs: I am not empty 10 10

Question 24

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

#include

#include

class A {

public:

virtual int f() { return 10; }

virtual ~A(){}

};

class B: public A {

int f() {return 11; }

virtual ~B(){}

};

int main (){

std::vectorv1;

for(int i = 10; i>0; i??)

{

i%2>0?v1.push_back(new A()):v1.push_back(new B());

}

std::vector::iterator it = v1.begin();

while(it != v1.end())

{

std::cout<<v1.back()?>f()<<" ";

v1.pop_back();++it;

}

return 0;

}

Options:

A.

destructor of class A will be called

B.

destructor of class B will be called

C.

code will not compile

D.

program outputs 10 11 10 11 10

E.

program outputs 10 11 10 11 10 11 10 11 10 11

Page: 6 / 9
Total 228 questions