Labour Day Special - Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: top65certs

C++ Certified Professional Programmer CPP Passing Score

Page: 7 / 9
Total 228 questions

C++ Certified Professional Programmer Questions and Answers

Question 25

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

#include

#include

#include

using namespace std;

templateclass B { T val;

public:

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

T getV() const {return val;} bool operator < (const B & v) const { return val

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

templatestruct Out {

ostream & out;

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

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

bool Less(const B &a, const B &b) { return int(a.getV())

int main() {

float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};

vector > v1; v1.assign(t, t+10);

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

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

return 0;

}

Program outputs:

Options:

A.

1.66 1.32 1.96 1.13 2.28 2.3 2.98 2.62 3.94 3.64

B.

1.13 1.32 1.66 1.96 2.28 2.3 2.62 2.98 3.64 3.94

C.

compilation error

D.

3.94 3.64 2.98 2.62 2.3 2.28 1.96 1.66 1.32 1.13

E.

the exact output is impossible to determine

Question 26

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

#include

#include

using namespace std;

int main ()

{

float f = 10.126;

cout.unsetf(ios::floatfield);

cout<<scientific<

return 0;

}

What will be a mantissa part of the numbers displayed:

Options:

A.

1.0126 1.013

B.

1.012600 10.013

C.

10.01260 10.013

D.

1.012600 1.013

E.

1.0126 1.01

Question 27

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

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

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

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

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

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

Page: 7 / 9
Total 228 questions