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 # 11

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

#include < iostream >

using namespace std;

void g(int a)

{

cout < < a?1 < < endl;

}

template < class A >

void g(A a)

{

cout < < a+1 < < endl;

}

int main()

{

int a = 1;

g(a);

return 0;

}

A.

program displays: 0

B.

program displays: 2

C.

compilation error

D.

runtime exception

Question # 12

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

#include < iostream >

#include < algorithm >

#include < set >

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 < (const A & b) const { return a < b.a;}

};

struct Compare {

bool operator ()(A & a) {

if (a.getA() < 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};

set < A > d (t,t+15);

int number = count_if(d.begin(), d.end(), Compare());

cout < < number < < endl;

return 0;

}

Program outputs:

A.

12

B.

4

C.

2

D.

0

E.

compilation error

Question # 13

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

multimap < 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 (multimap < 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 2 4 4 5 5

E.

program outputs: one two three four five

Question # 14

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: one two three < enter > ?

#include < iostream >

#include < string >

using namespace std;

int main ()

{

string a;

cin.getline(a);

cout < < a < < endl;

return 0;

}

Program will output:

A.

one

B.

one two three

C.

runtime exception

D.

compilation error

E.

the result is unspecified

Question # 15

Which keywords can be used to define template type parameters? Choose all possible answers:

A.

class

B.

typedef

C.

typename

D.

static

E.

volatile

Question # 16

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

#include < iostream >

#include < algorithm >

#include < set >

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

operator int() const {return a;}

};

int main () {

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

set < A > s (t,t+15);

cout < < equal(s.begin(), s.end(), t) < < endl;

return 0;

}

Program outputs:

A.

true

B.

false

C.

1

D.

0

E.

compilation error

Question # 17

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

#include < list >

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

list < int > l2(t2, t2 + 5);

l1.sort();

list < int > ::iterator it = l2.begin();

it++; it++;

l1.splice(l1.end(),l2, it, l2.end());

print(l1.begin(), l1.end()); cout < < "Size:" < < l1.size() < < " ";

print(l2.begin(), l2.end()); cout < < "Size:" < < l2.size() < < endl;

return 0;

}

A.

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

B.

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

C.

compilation error

D.

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

E.

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

Question # 18

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

int main() {

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

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

sort(v1.begin(), v1.end(), greater < int > ());

cout < < min_element(v1.begin(), v1.end());

return 0;

}

Program outputs:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

Question # 19

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

#include < iostream >

#include < algorithm >

#include < vector >

#include < set >

using namespace std;

void myfunction(int i) { cout < < " " < < i;

}

struct sequence {

int val,inc;

sequence(int s, int i):val(s),inc(i){}

int operator()(){

int r = val; val += inc;

return r;

}

};

int main() {

vector < int > v1(10);

fill(v1.begin(), v1.end(), sequence(1,1));

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

return 0;

}

Program outputs:

A.

1 2 3 4 5 6 7 8 9 10

B.

10

C.

0 0 0 0 0 0 0 0 0 0

D.

compilation error

Question # 20

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 Sequence {

int start;

Sequence(int start):start(start){}

int operator()() { return start++; }

};

struct Odd { bool operator()(int v) { return v%2==0; } };

int main() {

vector < int > v1(10);

vector < int > v2(10);

generate(v1.begin(), v1.end(), Sequence(1));

stable_partition(v1.begin(),v1.end(), Odd());

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

return 0;

}

Program outputs:

A.

1 2 3 4 5 6 7 8 9 10

B.

5 7 3 9 1 10 2 8 4 6

C.

10 2 8 4 6 5 7 3 9 1

D.

4 6 8 10 2 7 5 3 1 9

E.

2 4 6 8 10 1 3 5 7 9

Go to page: