Spring Sale Special Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: buysanta

Exact2Pass Menu

C++ Certified Professional Programmer

Last Update 10 hours ago Total Questions : 228

The C++ Certified Professional Programmer content is now fully updated, with all current exam questions added 10 hours ago. Deciding to include CPP practice exam questions in your study plan goes far beyond basic test preparation.

You'll find that our CPP exam questions frequently feature detailed scenarios and practical problem-solving exercises that directly mirror industry challenges. Engaging with these CPP sample sets allows you to effectively manage your time and pace yourself, giving you the ability to finish any C++ Certified Professional Programmer practice test comfortably within the allotted time.

Question # 31

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

#include < list >

#include < deque >

#include < iostream >

using namespace std;

template < class T >

void print(T start, T end) {

while (start != end) {

std::cout < < *start < < " "; start++;

}

}

int main()

{

int t1[] = { 1, 7, 8, 4, 5 };

list < int > l1(t1, t1 + 5);

int t2[] = { 3, 2, 6, 9, 0 };

deque < int > d1(t2, t2 + 5);

l1.sort();

d1.sort();

l1.merge(d1);

print(l1.begin(), l1.end());

print(d1.begin(), d2.end()); cout < < endl;

return 0;

}

A.

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

B.

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

C.

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

D.

compilation error

Question # 32

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

#include < vector >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

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

struct Add {

int operator()(int & a, int & b) {

return a+b;

}

};

int main() {

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

vector < int > v1(t, t+10);

vector < int > v2(10);

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

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

return 0;

}

Program outputs:

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

Question # 33

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

#include < deque >

#include < vector >

#include < iostream >

using namespace std;

class A

{

int a;

public:

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

~A() { c??;}

static int c;

};

int A::c(0);

int main ()

{

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

vector < A > v1(t, t+10);

deque < A > d1(v1.begin(), v1.end());

deque < A > d2;

d2 = d1;

cout < < A::c < < endl;

return 0;

}

How many objects of type A will be created:

A.

10

B.

20

C.

30

D.

40

Question # 34

What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?

#include < iostream >

#include < fstream >

#include < string >

#include < list >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

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

int main (){

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

fstream f("test.out");

list < int > l(t, t+10);

for_each(l.begin(), l.end(), Out < int > (f));

f.close();

return 0;

}

A.

file test.out will be created and opened for writing

B.

file test.out will be created and opened for reading

C.

no file will be created nor opened

D.

file test.out will contain sequence 1 2 3 4 5 6 7 8 9 10

E.

compilation error

Question # 35

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

#include < iostream >

#include < set >

#include < vector >

using namespace std;

int main(){

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

multiset < int > s1(t,t+10);

s1.insert(s1.find(7), 3);

for(multiset < int > ::iterator i=s1.begin();i!= s1.end(); i++) {

cout < < *i < < " ";

}

return 0;

}

A.

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

B.

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

C.

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

D.

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

E.

runtime exception

Question # 36

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

#include < vector >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

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

struct Add {

int operator()(int & a, int & b) {

return a+b;

}

};

int main() {

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

vector < int > v1(t, t+10);

vector < int > v2(10);

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

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

return 0;

}

Program outputs:

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

Question # 37

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

#include < iostream >

#include < algorithm >

#include < vector >

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

bool operator==(A & b) { return a == b.a; }

};

struct Compare{

bool operator()(const A & a, const A & b) {return a.getA()==b.getA();};

};

int main () {

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

vector < A > v (t,t+10);

vector < A > ::iterator it;

A m1[] = {A(1), A(2), A(3)};

it = find_end (v.begin(), v.end(), m1, m1+3, Compare());

cout < < "Found at position: " < < it?v.begin() < < endl;

return 0;

}

A.

program outputs: Found at position: 5

B.

program outputs: Found at position: 0

C.

program outputs: Found at position: 7

D.

compilation error

E.

program outputs: Found at position: 10

***/

Question # 38

Which changes introduced independently will allow code to compile and display 0 1 8 9 (choose all that apply)

#include < iostream >

#include < set >

#include < vector >

using namespace std;

class A {

int a;

public:

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

int getA() const { return a;}

/* Insert Code Here 1 */

};

/* Insert Code Here 2 */

int main(){

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

vector < A > v(t, t+10);

set < A > s1(v.begin(),v.end());

s1.insert(v.begin(),v.end());

s1.erase(s1.lower_bound(2),s1.upper_bound(7));

for(set < A > ::iterator i=s1.begin();i!= s1.end(); i++) {

cout < < i? > getA() < < " ";

}

cout < < endl;

return 0;

}

A.

operator int() const { return a;} inserted at Place 1

B.

bool operator < (const A & b) const { return a < b.a;} inserted at Place 1

C.

bool operator < (const A & b) const { return b.a < a;} inserted at Place 1

D.

bool operator < (const A & a, const A & b) { return a.getA() < b.getA();} inserted at Place 2

Question # 39

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

#include < iostream >

#include < algorithm >

#include < vector >

using namespace std;

void myfunction(int i) {

cout < < " " < < i;

}

int main() {

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

vector < int > v1(t, t + 10);

copy_backward(t, t+10, v1.rend());

for_each(v1.begin(), v1.end(), myfunction);

return 0;

}

Program outputs:

A.

10 5 9 6 2 4 7 8 3 1

B.

1 3 8 7 4 2 6 9 5 10 10 5 9 6 2 4 7 8 3 1

C.

1 3 8 7 4 2 6 9 5 10

D.

runtime exception/segmentation fault

E.

compilation error

Question # 40

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

#include < iostream >

#include < map >

using namespace std;

int main() {

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

string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};

map < int, string > m;

for (int i = 0; i < 10; i++) {

m.insert(pair < int, string > (t[i], s[i] ));

}

if (m.count(3) == 2) {

m.erase(3);

}

for (map < int, string > ::iterator i = m.begin(); i != m.end(); i++) {

cout < < i? > first < < " ";

}

return 0;

}

A.

program outputs: 1 2 3 4 5

B.

program outputs: 1 2 4 5

C.

program outputs: 1 1 2 2 3 4 4 5 5

D.

program outputs: 1 1 2 3 3 4 4 5 5

E.

program outputs: one two three four five

Go to page: