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

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,3,5,1,2,4,4,5};

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

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

while ( (it = adjacent_find (it, v.end())) != v.end()) {

cout < < it?v.begin() < < " ";it++;

}

cout < < endl;

return 0;

}

A.

program outputs: 2 3

B.

program outputs: 2 7

C.

program outputs: 3 8

D.

compilation error

E.

program will run forever

Question # 22

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

#include < vector >

#include < iostream >

using namespace std;

int main ()

{

vector < int > v1(10, 3);

v1.push_back(3);

cout < < v1.capacity() < < " " < < v1.size() < < endl;

return 0;

}

A.

program displays 4 4

B.

program displays 10 3

C.

size of vector v1 is 11

D.

all elements of vector v1 are of the same value

Question # 23

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

#include < iostream >

#include < iomanip >

using namespace std;

int main ()

{

float f = 10.126;

cout < < f < < " " < < setprecision(2) < < f < < endl;

return 0;

}

Program outputs:

A.

10.126 10

B.

10.126 10.12

C.

compilation error

D.

10.126 10.13

Question # 24

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

#include < iostream >

using namespace std;

int main ()

{

float f1 = 10.0;

float f2 = 10.123;

cout < < noshowpoint < < f1 < < " " < < f2;

return 0;

}

Program outputs:

A.

10 10

B.

10.0 10.123

C.

compilation error

D.

10 10.123

Question # 25

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

#include < iostream >

#include < map >

#include < string >

using namespace std;

int main(){

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

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

multimap < int,string > m;

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

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

}

if (m[11] == "eleven") {

cout < < "eleven ";

}

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

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

}

cout < < m.size();

return 0;

}

A.

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

B.

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

C.

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

D.

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

E.

compilation error

Question # 26

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

#include < deque >

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

struct Add : public binary_function < int, int, int > {

int operator() (const int & a, const int & b) const {

return a+b;

}

};

int main() {

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

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

deque < int > d2(10);

transform(d1.begin(), d1.end(), d2.begin(), bind2nd(Add(), 1));

for_each(d2.rbegin(), d2.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 # 27

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

#include < iostream >

using namespace std;

template < class T >

class A {

T _v;

public:

A() {}

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

friend ostream & operator < < (ostream & c, const A < T > & v) {

c < < v._v; return c;

}

};

int main()

{

A < int > a(10);

cout < < a < < endl;

return 0;

}

A.

program will display:10

B.

program will not compile

C.

program will compile

D.

program will run without output

Question # 28

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

#include < iostream >

#include < set >

#include < list >

using namespace std;

int main(){

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

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

multiset < int > s1(v.begin(),v.end());

if (s1.count(3) == 2) {

s1.erase(3);

}

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

cout < < *i < < " ";

}

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 3 3 4 4 5 5

E.

compilation error

Question # 29

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

#include < vector >

#include < iostream >

using namespace std;

class A

{

int a;

public:

A():a(0){} A(int a){ this? > a = a;}

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

int getA() {return a;}

};

ostream & operator < < (ostream & cout, A & a)

{

cout < < a.getA();

return cout;

}

int main ()

{

vector < A* > v(5, new A());

v.push_back(new A(1));

vector < A* > ::iterator it;

for(it = v.begin(); it != v.end(); it++)

{

cout < < *it < < " ";

}

cout < < endl;

return 0;

}

A.

program outputs 0 0 0 0 0 1

B.

program outputs 0 0 0 0 0 0

C.

compilation error

D.

program outputs 1 1 1 1 1 1

E.

none of these

Question # 30

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

#include < vector >

#include < string >

#include < iostream >

#include < algorithm >

#include < ctype.h >

using namespace std;

template < typename T > class B { T val;

public:

B(T v):val(v){}

T getV() const {return val;} };

template < class T > ostream & operator < < (ostream & out, const B < T > & 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 < < " "; } };

string tolower(const string & s) {

string tmp(s);

for(unsigned i = 0; i < tmp.size(); ++i){

tmp[i] = tolower(tmp[i] ); }

return tmp; }

bool Less(const B < string > & a, const B < string > & b) {

return tolower(a.getV()) < tolower(b.getV()); }

int main() {

string t[]={"aaa","bbb","Aaa", "Bbb","aAa","bBb","aaA","bbB"};

vector < B < string > > v1; v1.assign(t, t+8);

stable_sort(v1.begin(), v1.end(), Less);

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

return 0;

}

Program outputs:

A.

Aaa aaa aAa aaA bbb Bbb bBb bbB

B.

Aaa aaa aAa aaA bbb Bbb bbB bBb

C.

aaa Aaa aAa aaA bbb Bbb bBb bbB

D.

the exact output is impossible to determine

Go to page: