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

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

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

struct Add {

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

int main() {

B 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(), bind2nd(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 # 42

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

#include < iostream >

#include < deque >

#include < list >

#include < queue >

#include < vector >

using namespace std;

int main()

{

deque < int > mydeck; list < int > mylist; vector < int > myvector;

queue < int > first; queue < int > second(mydeck);

queue < int > third(second); queue < int, list < int > > fourth(mylist);

fourth.push(10);fourth.push(11);fourth.push(12);

queue < int, vector < int > > fifth(myvector);

fifth.push(10);fifth.push(11);fifth.push(12); // Line I

while(!fifth.empty())

{

cout < < fifth.front() < < " "; // Line II

fifth.pop(); // Line III

}

while (!fourth.empty())

{

cout < < fourth.front() < < " ";

fourth.pop(); // Line IV

}

return 0;

}

A.

program outputs: 10 11 12 10 11 12

B.

compilation error in line I

C.

compilation error in line II

D.

compilation error in line III

E.

compilation error in line IV

Question # 43

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

#include < iostream >

#include < algorithm >

#include < vector >

#include < set >

#include < deque >

using namespace std;

void myfunction(int i) {

cout < < " " < < i;

}

int add (int a, int b) { return a+b; }

int main() {

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

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

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

deque < int > d1;

d1.resize(s1.size());

transform(s1.begin(), s1.end(), v1.begin(), d1.begin(), add);

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

return 0;

}

Program outputs:

A.

0 0 0 0 0 0 0 0 0 0

B.

11 7 12 10 7 10 14 16 12 11

C.

compilation error

D.

runtime exception

E.

20 10 18 12 4 8 14 16 6 2

Question # 44

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

#include < deque >

#include < vector >

#include < iostream >

using namespace std;

template < typename T >

int calculate(T start, T end)

{

int s = 0;

while (start != end)

s+= *start; start++; return s;

}

int main ()

{

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

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

deque < int > d1(t+5, t+10);

cout < < calculate(t,t+10) < < " ";

cout < < calculate(v1.begin()+1,v1.end()?2) < < " ";

cout < < calculate(d1.rbegin()+1,d1.rend()?2) < < " ";

cout < < calculate(t[0],t[10] ) < < " ";

cout < < endl;

return 0;

}

A.

compilation error

B.

runtime exception

C.

program outputs 55 5 17 55

D.

program outputs 55 5 17 0

Question # 45

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

#include < iostream >

#include < deque >

#include < list >

#include < stack >

#include < vector >

using namespace std;

int main()

{

deque < int > mydeck; list < int > mylist; vector < int > myvector;

stack < int > first;

stack < int > second(mydeck);

stack < int > third(second);

stack < int, list < int > > fourth(mylist);

fourth.push(10);fourth.push(11);fourth.push(12);

stack < int, vector < int > > fifth(myvector);

fifth.push(10);fifth.push(11);fifth.push(12);

while(!fifth.empty())

{

cout < < fifth.top() < < " ";

fifth.pop();

}

while (!fourth.empty())

{

cout < < fourth.front() < < " ";

fourth.pop();

}

return 0;

}

A.

program outputs: 12 11 10 12 11 10

B.

compilation error

C.

program outputs: 10 11 12 10 11 12

D.

runtime exception

Question # 46

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

#include < vector >

#include < iostream >

using namespace std;

class A

{

int a,b;

public:

A & operator =(const A & c) { a = c.a; return *this;}

A():a(0),b(0){}

void setA(int a) {this? > a = a;} void setB(int b) {this? > b = b;}

int getA() {return a;} int getB() {return b;}

};

int main ()

{

vector < A > v;

A a;

a.setA(10); a.setB(11);

v.push_back(a);

A b = v.front(); v.pop_back();

cout < < b.getB() < < " " < < b.getA() < < endl;

return 0;

}

A.

program outputs 11 10

B.

compilation error

C.

program outputs 0 10

D.

program outputs 10 0

E.

program outputs 11 0

Question # 47

Which changes introduced independently will allow the code to compile and display 0 0 1 1 8 8 9 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 };

set < A > s(t, t+10); /* Replace Code Here 3 */

multiset < A > s1(s.begin(),s.end()); /* Replace Code Here 4 */

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

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

multiset < A > ::iterator i=s1.begin(); /* Replace Code Here 5 */

for( ;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.

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

replacing line marked 3 with set < A, R > s(t, t+10);

replacing line marked 4 with multiset < A,R > s1(s.begin(),s.end());

replacing line marked 5 with multiset < A,R > ::iterator i=s1.begin();

Question # 48

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

#include < iostream >

#include < string >

using namespace std;

int main ()

{

bool a,b;

cin > > boolalpha > > a > > b;

cout < < a < < b < < endl;

return 0;

}

Program will output:

A.

truefalse

B.

true0;

C.

1false

D.

10

E.

none of these

Question # 49

What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?

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

ifstream f("test.in");

list < int > l;

for( ; f.good() ; ) {

int i;

f > > i;

l.push_back(i);

}

f.close();

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

return 0;

}

Program will output:

A.

1 2 3

B.

1 2 3 3

C.

no output

D.

compilation error

E.

program runs forever without output

Question # 50

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

#include < iostream >

#include < deque >

#include < list >

#include < queue >

#include < vector >

using namespace std;

class compare {

bool reverse;

public:

compare(bool revparam = false) { reverse = revparam; }

bool operator()(int lhs, int rhs) const {

if (reverse) return (lhs > rhs);

else return (lhs < rhs);

}

};

int main(){

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

priority_queue < int, deque < int > > first(myints, myints + 10);

priority_queue < int, vector < int > , compare > second(myints, myints + 10,

compare(false));

while (first.size() > 0){

cout < < first.top() < < " "; first.pop();

}

while (second.size() > 0) {

cout < < second.top() < < " "; second.pop();

}

return 0;

}

A.

compilation error

B.

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

C.

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

D.

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

Go to page: