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

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

#include < iostream >

using namespace std;

template < class A >

void f(A a)

{

cout < < 1 < < endl;

}

void f(int a)

{

cout < < 2 < < endl;

}

int main()

{

int a = 1;

f < float > (a);

return 0;

}

A.

program displays: 1

B.

program displays: 2

C.

compilation error

D.

runtime exception

Question # 62

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

int main() {

vector < int > v1(10);

generate(v1.rbegin(), v1.rend(), Sequence(1));

rotate(v1.begin(),v1.begin() + 1, v1.end() );

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.

10 9 8 7 6 5 4 3 2 1

C.

9 8 7 6 5 4 3 2 1 10

D.

1 10 9 8 7 6 5 4 3 2

Question # 63

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

#include < deque >

#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() {

int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};

deque < B > d1(t, t+10);

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

pair < deque < B > ::iterator, deque < B > ::iterator > result = equal_range(d1.begin(), d1.end(), B(20));

for_each(result.first, result.second, Out < B > (cout));cout < < endl;

return 0;

}

Program outputs:

A.

10 10 10 20 20 20 20 30 30 30

B.

20 20 20 20

C.

10 20 20 20 20

D.

20 20 20 20 30

E.

10 20 20 20 20 30

Question # 64

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[]={5,6,8,2,1};

vector < B > v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

A.

compilation error

B.

1 2 3 4 5 6 8 0 0 0

C.

1 2 3 4 5 6 8 2 1 0

D.

5 2 1 0 0 0 0 0 0 0

E.

1 2 5 0 0 0 0 0 0 0

Question # 65

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

#include < iostream >

#include < map >

#include < vector >

#include < string >

using namespace std;

int main(){

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

string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","zero"};

map < int,string > m;

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

m.insert(pair < int,string > (second[i],first[i] ));

}

m[0]="ten";

m.insert(pair < int,string > (1,"eleven"));

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

cout < < i? > second < < " ";

}

return 0;

}

A.

program outputs: zero one two three four five six seven eight nine

B.

program outputs: ten one two three four five six seven eight nine

C.

program outputs: zero eleven two three four five six seven eight nine

D.

program outputs: ten eleven two three four five six seven eight nine

E.

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

Question # 66

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

#include < iostream >

#include < map >

#include < vector >

#include < sstream >

#include < string >

using namespace std;

int main(){

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

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

multimap < int,string > m;

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

stringstream s; s < < *i < < *i; m.insert(pair < int,string > (*i,s.str()));

}

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

cout < < *i < < " ";

}

return 0;

}

A.

program outputs: 3 4 2 1 0 1 2 3 4 0

B.

program outputs: 00 11 22 33 44

C.

program outputs: 0 0 1 1 2 2 3 3 4 4

D.

program outputs: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4

E.

compilation error

Question # 67

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

#include < vector >

#include < set >

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

int main() {

vector < int > v1(10);

generate_n(v1.begin(), 10, Sequence(1));

random_shuffle(v1.rbegin(), v1.rend());

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

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

return 0;

}

Program outputs:

A.

8 10 5 1 4 6 2 7 9 3

B.

1 2 3 4 5 6 7 8 9 10

C.

compilation error

D.

10 9 8 7 6 5 4 3 2 1

Question # 68

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

#include < iostream >

#include < string >

using namespace std;

int main ()

{

int a,b,c;

cin > > a > > b > > c;

cout < < a < < b < < c < < endl;

return 0;

}

Program will output:

A.

123

B.

1 2 3

C.

1.12.23.3

D.

1.1 2.2 3.3

E.

none of these

Go to page: