New Year Special Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: cramtick70

CPP C++ Certified Professional Programmer Questions and Answers

Questions 4

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

#include

#include

#include

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

templatestruct Out {

ostream & out;

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

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

int main() {

B t1[]={3,2,4,1,5};

B t2[]={5,6,8,2,1};

vector v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 8 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.

1 2 5 0 0 0 0 0 0 0

Buy Now
Questions 5

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

#include

#include

#include

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

int main() {

vector v1(10);

vector v2(10);

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

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

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 7 8 9 10

B.

10 9 8 7 6 5 4 3 2 1

C.

8 2 4 9 5 7 10 6 1 3

D.

compilation error

Buy Now
Questions 6

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

#include

#include

#include

#include

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<

templatestruct Out {

ostream & out;

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

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

int main() {

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

vector v1(t, t+10);

transform(v1.begin(), v1.end(), v1.begin(), bind2nd(plus(), 1));

for_each(v1.rbegin(), v1.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

A.

3 2 4 1 5 6 10 8 7 9

B.

4 3 5 2 6 7 11 9 8 10

C.

9 7 8 10 6 5 1 4 2 3

D.

10 8 9 11 7 6 2 5 3 4

E.

compilation error

Buy Now
Questions 7

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?

#include

#include

using namespace std;

int main ()

{

int a,b,c;

cin>>a>>b>>c;

cout<

return 0;

}

Program will output:

Options:

A.

123

B.

1 2 3

C.

1.12.23.3

D.

1.1 2.2 3.3

E.

none of these

Buy Now
Questions 8

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

struct Add {

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

return a+b;

}

};

int main() {

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

vector v1(t, t+10);

vector v2(10);

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

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 9

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

#include

#include

#include

using namespace std;

int main(){

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

vectorv(myints, myints+10);

set s1(v.begin(),v.end());

set > s2(v.begin(), v.end());

for(set::iterator i=s1.begin();i!= s1.end(); i++) {

cout<<*i<<" ";

}

for(set >::iterator i=s2.begin();i!= s2.end(); i++) {

cout<<*i<<" ";

}

cout<

return 0;

}

Options:

A.

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

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: 0 1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 0

D.

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

Buy Now
Questions 10

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

struct Add : public binary_function {

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

deque d2(10);

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

for_each(d2.rbegin(), d2.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 11

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

Buy Now
Questions 12

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

#include

#include

#include

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

int main() {

vector v1(10);

vector v2(10);

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

reverse_copy(v1.begin(),v1.end(), v2.rbegin());

sort(v2.begin(), v2.end(), less_equal());

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 7 8 9 10

B.

10 9 8 7 6 5 4 3 2 1

C.

no output

D.

compilation error

Buy Now
Questions 13

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

#include

#include

#include

using namespace std;

class B { int val;

public:

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

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

ostream & operator <<(ostream & out, const B & v) { out<

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

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

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

return 0;

}

Program outputs:

Options:

A.

8 10 5 1 4 6 2 7 9 3

B.

4 5 6 7 8 9 10

C.

1 2 3 4 5 6 7 8 9 10

D.

compilation error

E.

1 2 3 4

Buy Now
Questions 14

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

}

}

int main()

{

int t1[] ={ 1, 7, 8, 4, 5 };

list l1(t1, t1 + 5);

int t2[] ={ 3, 2, 6, 9, 0 };

list l2(t2, t2 + 5);

l1.sort();

list::iterator it = l2.begin();

it++; it++;

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

print(l1.begin(), l1.end()); cout<<"Size:"<

print(l2.begin(), l2.end()); cout<<"Size:"<

return 0;

}

Options:

A.

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

B.

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

C.

compilation error

D.

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

E.

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

Buy Now
Questions 15

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

#include

#include

#include

using namespace std;

int main() {

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

map m;

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

m[i]=t[i];

}

map::iterator it = find(m.begin(), m.end(), 5);

cout<first;

return 0;

}

Program outputs:

Options:

A.

5

B.

4

C.

10

D.

compilation error

Buy Now
Questions 16

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

#include

#include

int main ()

{

std::vectorv1;

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

{

v1.push_back(i);

}

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

int sum = 0;

while(it != v1.end())

{

sum+=it++;

}

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

return 0;

}

Options:

A.

program outputs 3 55

B.

compilation error

C.

program outputs 3 45

D.

program outputs 7 55

Buy Now
Questions 17

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main() {

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

int t2[]={6,10,8,7,9};

vector v1(10);

sort(t1, t1+5); sort(t2, t2+5);

copy(t1,t1+5,v1.begin());

copy(t2,t2+5,v1.begin()+5);

merge(v1.begin(), v1.begin()+5,v1.end());

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 10 8 7 9

B.

3 2 4 1 5 6 7 8 9 10

C.

3 2 4 1 5 6 10 8 7 9

D.

1 2 3 4 5 6 7 8 9 10

E.

compilation error

Buy Now
Questions 18

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

#include

#include

int main ()

{

std::vectorv1;

for(int i = 0; i<10; i++) {v1.push_back(i); }

v1.resize(4);

std::vector::iterator it = v1.end();

v1.insert(v1.end()?1, 4);

for(int i=0 ; i<= v1.size(); i++) {std::cout<

return 0;

}

Options:

A.

compilation error

B.

program outputs 0 1 2 3 4

C.

program outputs 0 2 4 8 6 and exception

D.

program outputs 0 2 4 6 8

E.

program outputs 0 2 4 8 6

Buy Now
Questions 19

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

#include

#include

#include

using namespace std;

int main ()

{

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

vectorv1(t, t+5);

dequed1;

d1.assign(v1.end(), v1.begin());

for(int i=0; i

{

cout<

}

cout<

return 0;

}

Options:

A.

program outputs 5 4 3 2 1

B.

program outputs 1 2 3 4 5

C.

compilation error in line 8

D.

compilation error in line 10

E.

segmentation fault runtime exception

Buy Now
Questions 20

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

#include

#include

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

int main() {

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

vector v1(t, t + 10);

copy(t, t+10, v1.end());

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

return 0;

}

Program outputs:

Options:

A.

10 5 9 6 2 4 7 8 3 1

B.

10 5 9 6 2 4 7 8 3 1 10 5 9 6 2 4 7 8 3 1

C.

compilation error

D.

runtime exception/segmentation fault

Buy Now
Questions 21

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

#include

using namespace std;

class C {

public:

int _c;

C():_c(0){}

C(int c) { _c = c;}

C operator+=(C & b) {

C tmp; tmp._c = _c+b._c;

return tmp;

} };

ostream & operator<<(ostream & c, const C & v) {

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(2);

Aa (5);

a.add(C());

cout << a.getV() <

return 0;

}

Options:

A.

program will display:5

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Buy Now
Questions 22

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

#include

#include

#include

using namespace std;

int main () {

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

vector v (t,t+10);

vector::iterator it;

int m1[] = {1, 2, 3};

it = search (v.begin(), v.end(), m1, m1+3);

cout << "found at position: " << it?v.begin() << endl;

return 0;

}

Program outputs:

Options:

A.

found at position: 5

B.

found at position: 0

C.

found at position: 6

D.

found at position: 1

E.

found at position: 10

Buy Now
Questions 23

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

#include

#include

#include

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

ostream & operator <<(ostream & out, const B & v) { out<

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

set s1(t, t+10);

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

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

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 24

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

struct Add {

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

return a+b;

}

};

int main() {

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

vector v1(t, t+10);

vector v2(10);

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

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 25

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

bool Greater(int v1, int v2) { return v1

int main() {

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

vector v1(t, t+10);

sort(v1.begin(), v1.end(), Greater);

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

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 26

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

#include

#include

#include

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

int main() {

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

set s1(t, t+10);

vector v1(s1.rbegin(), s1.rend());

swap_ranges(s1.begin(), s1.end(), v1.begin());

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

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

return 0;

}

Program outputs:

Options:

A.

10 9 8 7 6 5 4 3 2 1 1 2 3 4 5 6 7 8 9 10

B.

compilation error

C.

1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10

D.

1 2 3 4 5 6 7 8 9 10 10 9 8 7 6 5 4 3 2 1

E.

10 9 8 7 6 5 4 3 2 1 10 9 8 7 6 5 4 3 2 1

Buy Now
Questions 27

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

#include

#include

#include

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

deque d1(10);

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

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

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

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

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 28

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

cout<

return 0;

}

Program will output:

Options:

A.

one

B.

one two three

C.

runtime exception

D.

compilation error

E.

the result is unspecified

Buy Now
Questions 29

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

#include

#include

#include

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

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

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

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

int main() {

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

deque d1(t, t+10);

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

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

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

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 30

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

struct Add : public binary_function {

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

vector v1(t, t+10);

vector v2(10);

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

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 31

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

#include

#include

#include

#include

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

};

ostream & operator <<(ostream & out, const B & v) { out<

templatestruct Out {

ostream & out;

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

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

};

int main() {

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

B t1[]={B(1),B(2),B(3),B(4)};

deque d1(t, t+10);

set s1(t, t+10);

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

cout<

<

return 0;

}

Program outputs:

Options:

A.

1 1

B.

1 0

C.

0 1

D.

0 0

E.

compilation error

Buy Now
Questions 32

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

#include

#include

#include

using namespace std;

int main ()

{

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

vectorv1(t, t+5);

listl1;

l1.assign(v1.end(), v1.begin());

for(int i=0; i

{

cout<

}

cout<

return 0;

}

Options:

A.

program displays 5 4 3 2 1

B.

program displays 1 2 3 4 5

C.

compilation error

D.

segmentation fault runtime exception

Buy Now
Questions 33

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main() {

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

vector v1(t, t+10);

for_each(v1.begin(), v1.end(), bind2nd(plus(), 1));

for_each(v1.rbegin(), v1.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

A.

3 2 4 1 5 6 10 8 7 9

B.

4 3 5 2 6 7 11 9 8 10

C.

9 7 8 10 6 5 1 4 2 3

D.

10 8 9 11 7 6 2 5 3 4

E.

compilation error

Buy Now
Questions 34

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

#include

#include

#include

using namespace std;

int main(){

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

listv(t, t+10);

set s1(v.begin(),v.end());

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

s1.erase(3);

}

for(set::iterator i=s1.begin();i!= s1.end(); i++) {

cout<<*i<<" ";

}

return 0;

}

Options:

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

E.

compilation error

Buy Now
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Dec 25, 2024
Questions: 228
CPP pdf

CPP PDF

$25.5  $84.99
CPP Engine

CPP Testing Engine

$30  $99.99
CPP PDF + Engine

CPP PDF + Testing Engine

$40.5  $134.99