Weekend Special Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code = simple70

Pass the C++ Institute C++ Certified Professional Programmer CPP Questions and answers with ExamsMirror

Practice at least 50% of the questions to maximize your chances of passing.
Exam CPP Premium Access

View all detail and faqs for the CPP exam


395 Students Passed

92% Average Score

92% Same Questions
Viewing page 1 out of 7 pages
Viewing questions 1-10 out of questions
Questions # 1:

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

#include

using namespace std;

template

void f(A &a)

{

cout<<1<

}

void f(int &a)

{

cout<<2<

}

int main()

{

int a = 1;

f(a);

return 0;

}

Options:

A.

program displays: 1

B.

program displays: 2

C.

compilation error

D.

runtime exception

Questions # 2:

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

#include

using namespace std;

class C {};

template

class A {

T_v;

public:

A() {}

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

T getV() { return _v; }

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

};

int main()

{

A b;

Aa;

a.add(C());

cout << b.getV() <

return 0;

}

Options:

A.

program will display:0

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Questions # 3:

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

#include

#include

#include <algorithm>

using namespace std;

templatestruct Out {

ostream & out;

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

void operator()(const T & val ) {

out<

}

};

struct Sequence {

int start;

Sequence(int start):start(start){}

int operator()() { return 10*(1+(start++ %3)); }

};

int main() {

vector v1(10);

generate(v1.begin(), v1.end(), Sequence(1));

unique(v1.begin(),v1.end());

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

return 0;

}

Program outputs:

Options:

A.

20 30 10 20 30 10 20 30 10 20

B.

20 30 10

C.

30 10 20

D.

compilation error

Questions # 4:

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

#include

#include

#include

#include

#include

using namespace std;

int main() {

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

vector v(t, t + 10);

map m;

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

stringstream s;s << *i << *i;

m.insert(pair(*i, s.str()));

}

pair::iterator, map::iterator> range;

range = m.equal_range(6);

for (map::iterator i = range.first; i != range.second; i++) {

cout << i?>first << " ";

}

return 0;

}

Options:

A.

program outputs: 6

B.

program outputs: 5 7

C.

program outputs: 6 7

D.

program outputs: 1 5

E.

program outputs: 6 5

Questions # 5:

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

#include

#include <algorithm>

#include

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

int multiply (int a) {

return a*2;

}

int main() {

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

vector v1(t, t+10);

set s1(t, t+10);

transform(s1.begin(), s1.end(), v1.begin(), multiply);

transform(v1.begin(), v1.end(), s1.begin(), multiply);

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

return 0;

}

Program outputs:

Options:

A.

20 10 18 12 4 8 14 16 6 2

B.

2 4 6 8 10 12 14 16 18 20

C.

4 8 12 16 20 24 28 32 36 40

D.

compilation error

Questions # 6:

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

#include

#include

using namespace std;

template void print(T start, T end) {

while (start != end) {

std::cout << *start << " "; start++;

}

}

class A {

int a;

public:

A(int a):a(a){}

operator int () const { return a;}int getA() const { return a;}

};

int main() {

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

list l1(t1, t1 + 10);

list l2(l1);

l2.reverse(); l1.splice(l1.end(),l2);

l1.pop_back();l1.unique();

print(l1.begin(), l1.end()); cout<

return 0;

}

Options:

A.

compilation error

B.

runtime exception

C.

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

D.

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

E.

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

Questions # 7:

Which lines of the code below contain proper instantiation of queue objects?

#include

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;

list mylist;

vector myvector;

queue first; // line I

queue second(mydeck);// line II

queue third(second);// line III

queue fourth(mylist);// line IV

queue fifth(myvector);// line V

return 0;

}

Options:

A.

line I

B.

line II

C.

line III

D.

line IV

E.

line V

Questions # 8:

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

#include

#include <algorithm>

#include

#include

using namespace std;

int main() {

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

vector v1(t, t + 15);

set s1(t, t + 15);

pair::iterator, vector::iterator > resultSet = equal(s1.begin(), s1.end(), v1.begin());

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

return 0;

}

Program outputs:

Options:

A.

2 4

B.

4 2

C.

0 5

D.

compilation error

Questions # 9:

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

#include

#include

#include <algorithm>

using namespace std;

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<

int main() {

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

deque d1(t, t+10);

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

deque::iterator it = upper_bound(d1.begin(), d1.end(), 4);

for_each(it, d1.end(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

A.

5 6 7 8 9 10

B.

4 5 6 7 8 9 10

C.

1 2 3 4 5 6 7 8 9 10

D.

1 2 3 4 5

E.

1 2 3 4

Questions # 10:

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: one two three?

#include

#include

using namespace std;

int main ()

{

string a;

cin.getline(a);

cout<<a<

return 0;

}

Program will output:

Options:

A.

one

B.

one two three

C.

runtime exception

D.

compilation error

E.

the result is unspecified

Viewing page 1 out of 7 pages
Viewing questions 1-10 out of questions
TOP CODES

TOP CODES

Top selling exam codes in the certification world, popular, in demand and updated to help you pass on the first try.