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 4 hours ago Total Questions : 228

The C++ Certified Professional Programmer content is now fully updated, with all current exam questions added 4 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 # 51

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 t1[]={3,2,4,1,5};

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

vector < int > v1(10);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

A.

1 2 3 4 5 6 8 0 0 0

B.

3 4 0 0 0 0 0 0 0 0

C.

6 8 0 0 0 0 0 0 0 0

D.

compilation error

E.

1 2 5 0 0 0 0 0 0 0

Question # 52

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

#include < iostream >

#include < algorithm >

#include < deque >

#include < vector >

using namespace std;

bool identical(int a, int b) {

return b == 2*a?true:false;

}

int main() {

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

int u[] = {2,4,6,4,6,10,2,4,14,6,4,2,20,8,8,5};

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

deque < int > d1(u, u + 15);

pair < deque < int > ::iterator, vector < int > ::iterator > result;

result = mismatch(d1.begin(), d1.end(), v1.begin(), identical); //Line I

if (result.first == d1.end() & & result.second == v1.end()) { //Line II

cout < < "Identical\n";

} else {

cout < < "Not identical\n";

}

return 0;

}

Program outputs:

A.

Identical

B.

Not identical

C.

compilation error at line marked I

D.

compilation error at line marked II

Question # 53

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

#include < iostream >

#include < algorithm >

#include < vector >

#include < set >

using namespace std;

int main() {

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

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

set < int > s1(t, t + 15);

pair < set < int > ::iterator, vector < int > ::iterator > resultSet = mismatch(s1.begin(), s1.end(), v1.begin());

cout < < *resultSet.first < < " " < < *resultSet.second < < endl;

return 0;

}

Program outputs:

A.

2 4

B.

4 2

C.

0 5

D.

compilation error

Question # 54

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

#include < iostream >

#include < algorithm >

#include < map >

using namespace std;

void myfunction(pair < int, int > i) {

cout < < " " < < i.first;

}

int main() {

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

map < int, int > m;

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

m[i]=t[i] ;

}

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

return 0;

}

Program outputs:

A.

10 5 9 6 2 4 7 8 3 1

B.

0 1 2 3 4 5 6 7 8 9

C.

9 8 7 6 5 4 3 2 1 0

D.

1 3 8 7 4 2 6 9 5 10

E.

compilation error

Question # 55

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

#include < iostream >

#include < fstream >

#include < string >

#include < list >

#include < algorithm >

#include < iomanip >

using namespace std;

class B { int val;

public:

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

int getV() const {return val;}

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

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) {out < < setw(3) < < hex < < val; } };

int main () {

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

fstream f("test.out", ios::trunc|ios::out);

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

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

f.close();

f.open("test.out");

for( ; f.good() ; ) {

B i;

f > > i;

cout < < i < < " ";

}

f.close();

return 0;

}

A.

file test.out will be opened writing

B.

file test.out will be truncated

C.

file test.out will be opened for reading

D.

compilation error

E.

program will display sequence 1 2 3 4 5 6 7 8 9 10

Question # 56

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

#include < iostream >

#include < string >

using namespace std;

template < class T >

class A {

T _v;

public:

A() {}

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

T getV() { return _v; }

void add(T & a) { _v+=a; }

void add(string & a) {

_v.insert(0, a);

}

};

int main()

{

A < string > a("Hello");

string s(" world!");

a.add(s);

cout < < a.getV() < < endl;

return 0;

}

A.

program will display: Hello world!

B.

compilation error

C.

program will display: world!Hello

D.

program will run without any output

Question # 57

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

#include < iostream >

#include < algorithm >

#include < vector >

using namespace std;

int main () {

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

vector < int > v (t,t+15);

vector < int > ::iterator it = search_n(v.begin(), v.end(), 4, 2);

cout < < it?v.begin() < < endl;

return 0;

}

Program outputs:

A.

10

B.

3

C.

1

D.

15

E.

compilation error

Question # 58

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

using namespace std;

template < class T > struct Out {

ostream & out;

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

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

int Add(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(), bind2nd(ptr_fun (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 # 59

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

#include < vector >

#include < iostream >

#include < algorithm >

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 < v.val;} };

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

template < class T > struct Out {

ostream & out;

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

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

int main() {

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

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

vector < B > 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 < B > (cout));cout < < endl;

return 0;

}

Program outputs:

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

Question # 60

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

#include < iostream >

#include < string >

#include < sstream >

#include < iomanip >

using namespace std;

int main ()

{

string s;

getline(cin, s);

stringstream input(s);

stringstream output;

for( ; !input.fail() ; )

{

int i;

input > > hex > > i;

output < < setw(4) < < i;

}

cout < < output.str();

return 0;

}

What will be the result assuming that user will enter following sequence: 64 100:

A.

64 100

B.

100 256

C.

100 256 256

D.

0x64 0x100

E.

0x100 0x256 0x256

Go to page: