Weekend Sale - Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: dpm65

CPP C++ Certified Professional Programmer Questions and Answers

Questions 4

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

#include

#include

using namespace std;

int main ()

{

bool a,b;

cin>>a>>b;

cout<

return 0;

}

Program will output:

Options:

A.

truetrue

B.

falsefalse

C.

11

D.

00

E.

none of these

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 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 6

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

}

for(map::iterator i=m.begin();i!= m.end(); i++) {

cout<<*i<<" ";

}

return 0;

}

Options:

A.

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

B.

program outputs: 00 11 22 33 44 55 66 77 88 99

C.

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

D.

program outputs: 0 00 1 11 2 22 3 33 4 44 5 55 6 66 7 77 8 88 9 99

E.

compilation error

Buy Now
Questions 7

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

#include

#include

#include

using namespace std;

int main ()

{

vectorv1;

dequed1;

for(int i=0; i<5; i++)

{

v1.push_back(i);v1.push_front(i);

d1.push_back(i);d1.push_front(i);

}

for(int i=0; i

{

cout<

}

cout<

return 0;

}

What will be its output:

Options:

A.

4 4 3 3 2 2 1 1 0 0 0 0 1 1 2 2 3 3 4 4

B.

runtime exception

C.

compilation error due to line 11

D.

compilation error due to line 12

Buy Now
Questions 8

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

#include

#include

using namespace std;

int main() {

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

string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};

map m;

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

m.push_back(pair(t[i], s[i]));

}

for (map::iterator i = m.begin(); i != m.end(); i++) {

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

}

return 0;

}

Options:

A.

program outputs: 1 2 3 4 5

B.

compilation error

C.

program outputs: 1 1 2 2 3 3 4 4 5 5

D.

program outputs: one two three four five

E.

program outputs: one one two two three three four four five five

Buy Now
Questions 9

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;

}

bool classifier(int v) {

return v%2==0;

}

int main() {

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

vector v1(t, t+10);

set s1(t, t+10);

replace(v1.begin(), v1.end(),classifier, 10);

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

return 0;

}

Program outputs:

Options:

A.

1 5 10 5 10 10 10 3 3 1

B.

1 5 2 5 2 4 4 3 3 1

C.

compilation error

D.

10 10 2 10 2 4 4 10 10 10

Buy Now
Questions 10

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

#include

#include

#include

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

map m;/* Replace Code Here 3 */

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

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

}

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

map::iterator i=m.begin(); /* Replace Code Here 4 */

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

cout<second<<" ";

}

cout<

return 0;

}

Options:

A.

operator int() const { return a;} inserted at Place 1

B.

bool operator < (const A & b) const { return a

C.

bool operator < (const A & b) const { return b.a

D.

struct R { bool operator ()(const A & a, const A & b) { return a.getA()

replacing line marked 3 with map m;

replacing line marked 4 with map::iterator i=m.begin();

Buy Now
Questions 11

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

#include

#include

using namespace std;

int main ()

{

bool a,b;

cin>>boolalpha>>a>>b;

cout<

return 0;

}

Program will output:

Options:

A.

truefalse

B.

true0;

C.

1false

D.

10

E.

none of these

Buy Now
Questions 12

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 13

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

vector v (t,t+15);

vector::iterator it = search_n(v.begin(), v.end(), 4, 2);

cout<< it?v.begin()<

return 0;

}

Program outputs:

Options:

A.

10

B.

3

C.

1

D.

15

E.

compilation error

Buy Now
Questions 14

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 15

Which sentence is correct about the code below?

#include

#include

#include

using namespace std;

class A {

int a;

public:

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

int getA() const { return a; }

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

/* Insert Code Here */

};

struct add10 { void operator()(A & a) { a.setA(a.getA() + 10); } };

int main() {

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

vector v1(t, t + 10);

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

vector::iterator it = find(v1.begin(), v1.end(), A(7));

cout << it?>getA() << endl;

return 0;

}

Options:

A.

it will compile and print 7

B.

it will not compile

C.

it will compile but the program result is unpredictable

D.

adding code:

bool operator !=(const A & b) const {

if (this?>a != b.a) { return true; } return false; }

at Place 1 will allow the program to compile

Questions 16

What will happen when you attempt to compile and run the code below, assuming you enter the following sequence: 1 2 3?

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

321

D.

compilation error

E.

the result is unspecified

Buy Now
Questions 17

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

#include

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

};

struct R {

int val;

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

bool operator ()(const A & a) { return a>val;} };

int main() {

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

list l1(t1, t1 + 10);

R r(4);l1.remove_if(r);

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

return 0;

}

Options:

A.

program outputs: 1 2 3 4

B.

program outputs: 5 6 7 8 9 10

C.

program outputs: 1 2 3 4 5

D.

program outputs: 6 7 8 9 10

Questions 18

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main () {

ifstream f("test.in");

list l;

for( ; f.good() ; ) {

int i;

f>>i;

l.push_back(i);

}

f.close();

for_each(l.begin(), l.end(), Out(cout));

return 0;

}

Program will output:

Options:

A.

1 2 3

B.

1 2 3 3

C.

no output

D.

compilation error

E.

program runs forever without output

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[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };

vectorv(t, t+10);

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

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

pair::iterator,multiset::iterator> range;

range = s1.equal_range(6);

while (range.first != range.second) {

cout<<*range.first<<" "; range.first++;

}

return 0;

}

Options:

A.

program outputs: 6 6

B.

program outputs: 5 7

C.

program outputs: 5 5 6 6 7 7

D.

program outputs: 5 5 7 7

E.

program outputs: 1 1 6 6 5 5

Buy Now
Questions 20

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

list l1(t1, t1 + 5);

l1.remove(2);

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

return 0;

}

Options:

A.

program outputs: 1 2 4 5

B.

program outputs: 3 4 5

C.

program outputs: 1 3 4 5

D.

program outputs: 4 5

Buy Now
Questions 21

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 22

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>v.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(), greater());

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

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

return 0;

}

Program outputs:

Options:

A.

30 30 30 20 20 20 20 10 10 10

B.

20 20 20 20

C.

30 20 20 20 10

D.

20 20 20 20 10

E.

30 20 20 20 20 10

Buy Now
Questions 23

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

class B {

int val;

public:

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

operator int() { return val;}

};

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

bool predicate(int v) { return v%2==0; }

int main() {

vector v1(10);

generate_n(v1.begin(), 10, Sequence(1));

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

return 0;}

Program outputs:

Options:

A.

1 3 5 7 9 6 7 8 9 10

B.

1 3 5 7 9

C.

2 4 6 8 10

D.

compilation error

E.

no output

Buy Now
Questions 26

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

char s[]={"qwerty"};

char t1[]={"ert"};

char t2[]={"ERT"};

sort(s, s+6);

cout<

return 0;

}

Program outputs:

Options:

A.

0 0

B.

0 1

C.

1 0

D.

1 1

Buy Now
Questions 27

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

#include

#include

using namespace std;

int main() {

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

string s[] = { "one", "one", "two", "two", "three","three", "four", "four", "five", "five"};

multimap m;

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

m.insert(pair(t[i], s[i]));

}

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

m.erase(3);

}

for (multimap::iterator i = m.begin(); i != m.end(); i++) {

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

}

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

E.

program outputs: one two three four five

Buy Now
Questions 28

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=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<

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 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 29

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 30

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[]={5,6,8,2,1};

vector v1(10);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

Options:

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

Buy Now
Questions 31

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

#include

using namespace std;

class B {};

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 a(1);

Ab;

a.add(10);

cout << a.getV() <

return 0;

}

Options:

A.

program will display:11

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Buy Now
Questions 32

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

B operator ?(const B &b )const { return B(val ? b.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 t1[]={1,2,3,4,5,6,7,8,9,10};

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

vector v1(t1, t1+10);

vector v2(t2, t2+10);

vector v3(10);

transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus());

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

return 0;

}

Program outputs:

Options:

A.

9 7 5 3 1 ?1 ?3 ?5 ?7 ?9

B.

?1 ?3 ?5 ?7 ?9 9 7 5 3 1

C.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

D.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

E.

?9 ?7 ?5 ?3 ?1 1 3 5 7 9

Buy Now
Questions 33

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

#include

#include

#include

using namespace std;

class A

{

int a;

public:

A(int a) {this?>a = a; c++;}

~A() { c??;}

static int c;

};

int A::c(0);

int main ()

{

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

vectorv1(t, t+10);

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

deque d2;

d2 = d1;

cout<

return 0;

}

How many objects of type A will be created:

Options:

A.

10

B.

20

C.

30

D.

40

Questions 34

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

#include

#include

int main ()

{

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

std::vectorv1(t,t+5);

std::vectorv2(v1);

v1.resize(10);

v2.reserve(10);

std::vector::iterator i = v1.begin();int ii = 0;

while (i != v1.end()) { std::cout<

i = v2.begin();ii=0;

while (i != v2.end()) { std::cout<

return 0;

}

Options:

A.

program outputs 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

B.

compilation error

C.

program outputs 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5

D.

program outputs 1 2 3 4 5 0 0 0 0 0 1 2 3 4 5 0 0 0 0 0

Buy Now
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: May 16, 2024
Questions: 228

PDF + Testing Engine

$56  $159.99

Testing Engine

$42  $119.99
buy now CPP testing engine

PDF (Q&A)

$35  $99.99
buy now CPP pdf
dumpsmate guaranteed to pass
24/7 Customer Support

DumpsMate's team of experts is always available to respond your queries on exam preparation. Get professional answers on any topic of the certification syllabus. Our experts will thoroughly satisfy you.

Site Secure

mcafee secure

TESTED 19 May 2024