Special Summer Sale 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: Board70

CPP Exam Dumps - C++ Institute C++ Certified Professional Programmer Questions and Answers

Question # 24

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

#include

#include

#include

using namespace std;

struct Compare {

bool operator ()(int a) {

if (a >5) return true;

return false;

}

};

int main () {

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

vector v (t,t+15);

int number = count(v.begin(), v.end(), Compare());

cout<< number<<endl;

return 0;

}

Program outputs:

Options:

A.

4

B.

3

C.

2

D.

0

E.

compilation error

Buy Now
Question # 25

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

int main() {

int t1[]={3,2,4,1,5};

int t2[]={6,10,8,7,9};

vector v1(10);

sort(t1, t1+5);

sort(t2, t2+5);

merge(t1,t1+5,t2,t2+5,v1.begin());

for_each(v1.begin(), v1.end(), Out(cout));cout<<endl;

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 10 8 7 9

B.

3 2 4 1 5 6 7 8 9 10

C.

3 2 4 1 5 6 10 8 7 9

D.

1 2 3 4 5 6 7 8 9 10

E.

compilation error

Buy Now
Question # 26

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

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

friend ostream & operator<<(ostream & c, const A & v);

};

template

ostream & operator<<(ostream & c, const A & v) {

c<<v._v;return c; }

int main()

{

Aa(10);

cout<<a<<endl;

return 0;

}

Options:

A.

program will display:10

B.

program will not compile

C.

program will compile

D.

program will run without output

Buy Now
Question # 27

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

#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<<v.getV(); return out;}

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

int main() {

B t1[]={3,2,4,1,5};

int t2[]={5,6,8,2,1};

vector v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

set_union(t1,t1+5,t2,t2+5,v1.begin());

for_each(v1.begin(), v1.end(), Out(cout));cout<<endl;

return 0;

}

Program outputs:

Options:

A.

3 2 4 1 5 6 8 2 1 0

B.

1 2 3 4 5 6 8 2 1 0

C.

1 1 2 2 3 4 5 5 6 8

D.

1 2 3 4 5 6 8 0 0 0

E.

compilation error

Buy Now
Question # 28

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

#include

#include

#include

using namespace std;

class B { int val;

public:

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

int getV() const {return val;}

operator int () const { return val;} };

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

struct Add {

B operator()(B & a, B & b) { return a+b; } };

int main() {

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

vector v1(t, t+10);

vector v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind2nd(Add(),1));

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<<endl;

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 7 8 9 10

B.

2 3 4 5 6 7 8 9 10 11

C.

10 9 8 7 6 5 4 3 2 1

D.

11 10 9 8 7 6 5 4 3 2

E.

compilation error

Buy Now
Question # 29

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

#include

using namespace std;

int main()

{

cout.setf(ios::hex, ios::basefield);

cout<<100<<" ";

cout.unsetf(ios::hex);

cout<<100<<" ";

return 0;

}

Program outputs:

Options:

A.

64 64

B.

100 0x64

C.

0x64 0x64

D.

64 100

E.

compilation error

Buy Now
Question # 30

What happens when you attempt to compile and run the following code? Choose all that apply.

#include

#include

#include

using namespace std;

class A

{

int a;

public:

A(int a) {this?>a = a; c++;}

A(const A & a) {this?>a = a.a; c++;}

~A() { c??;}

static int c;

};

int A::c(0);

int main ()

{

A* t[] = {new A(1), new A(2), new A(3),new A(4), new A(5)};

vectorv1(t, t+10);

dequed1(v1.begin(), v1.end());

d1.clear();

v1.clear();

cout<<A::c<< endl;

return 0;

}

Options:

A.

there are 15 A objects created,

B.

there are 5 A objects created,

C.

for all object A the destructor is called

D.

program will display 5

Buy Now
Question # 31

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

#include

#include

#include

#include

#include

using namespace std;

struct display {

void operator() (int i) {cout << " " << i;}

};

int main() {

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

vector v1(t, t + 10);

deque d1(t, t + 10);

set s1(t, t + 10);

for_each(v1.begin(), v1.end(), display); //Line I

for_each(d1.begin(), d1.end(), *(new display())); // Line II

for_each(s1.begin(), s1.end(), display()); // Line III

return 0;

}

Options:

A.

program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 1 2 3 4 5 6 7 8 9 10

B.

program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1

C.

compilation error in line I

D.

compilation error in line II

E.

compilation error in line III

Buy Now
Question # 32

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

#include

#include

#include

#include

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

int main() {

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

vector v1(t, t + 10);

deque d1(t, t + 10);

set s1(t, t + 10);

for_each(v1.begin(), v1.end(), myfunction); // Line I

for_each(d1.begin(), d1.end(), myfunction); // Line II

for_each(s1.begin(), s1.end(), myfunction); // Line III

return 0;

}

Options:

A.

program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 1 2 3 4 5 6 7 8 9 10

B.

program outputs: 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1

C.

program outputs: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

D.

compilation error in line I

E.

compilation error in line III

Buy Now
Question # 33

Which sentence is correct about the code below? Choose all that apply.

#include

#include

#include

using namespace std;

class F {

int val;

public:

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

bool operator() (int v) {

if (v == val) return true;

return false;

}

};

int main() {

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

vector v1(t, t + 10);

if (find(v1.begin(), v1.end(), 6) == find(v1.begin(), v1.end(), F(6))) {

cout<<"Found!\n";

} else {

cout<<"Not found!\n";

}

return 0;

}

Options:

A.

it will compile successfully

B.

it will display Found!

C.

it will display Not found!

D.

it will not compile successfully

Buy Now
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Apr 1, 2025
Questions: 228
CPP pdf

CPP PDF

$25.5  $84.99
CPP Engine

CPP Testing Engine

$28.5  $94.99
CPP PDF + Engine

CPP PDF + Testing Engine

$40.5  $134.99