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

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

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

struct Add {

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

int main() {

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

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

vector < B > v2(10);

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

for_each(v2.rbegin(), v2.rend(), Out < B > (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 # 5

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_intersection(t1,t1+5,t2,t2+5,v1.begin());

for_each(v1.begin(), v1.end(), Out < int > (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.

1 1 2 2 3 4 5 5 6 8

E.

1 2 5 0 0 0 0 0 0 0

Question # 6

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

#include < vector >

#include < iostream >

int main ()

{

std::vector < int > v1;

for(int i = 10; i > 0; i??)

{

v1.push_back(i);

}

std::vector < int > ::iterator it = v1.begin();

int sum = 0;

while(it != v1.end())

{

sum+=it++;

}

std::cout < < *v1.erase(v1.begin(),v1.end()?3) < < " " < < sum < < std::endl;

return 0;

}

A.

program outputs 3 55

B.

compilation error

C.

program outputs 3 45

D.

program outputs 7 55

Question # 7

Which changes introduced independently will allow the code to compile and display “one” “eight” “nine” “ten”? Choose all that apply.

#include < iostream >

#include < map >

#include < string >

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

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

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

multimap < A,string > m; /* Replace Code Here 3 */

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

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

}

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

multimap < A, string > ::iterator i=m.begin(); /* Replace Code Here 4 */

for( ; i!= m.end(); i++) {

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

}

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.

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

replacing line marked 3 with multimap < A, string, R > m;

replacong line marked 4 with multimap < A, string, R > ::iterator i=m.begin();

Question # 8

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_symmetric_difference(t2,t2+5,t1,t1+5,v1.begin());

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

return 0;

}

Program outputs:

A.

6 8 3 4 0 0 0 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.

3 4 6 8 0 0 0 0 0 0

Question # 9

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

#include < iostream >

#include < fstream >

#include < string >

#include < list >

#include < algorithm >

#include < iomanip >

using namespace std;

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 < int > l(t, t+10);

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

f.close(); f.open("test.out");

for( ; f.good() ; ) {

int 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.

no file will be created nor opened

E.

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

Question # 10

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

#include < iostream >

using namespace std;

int main()

{

cout < < true < < " " < < boolalpha < < false;

return 0;

}

Program outputs:

A.

true false

B.

1 0

C.

1 false

D.

true 0

E.

compilation error

Go to page: