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

Ace Your CPP C++ Certified Professional Programmer Exam

Page: 8 / 9
Total 228 questions

C++ Certified Professional Programmer Questions and Answers

Question 29

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.push_back(pair(t[i], s[i]));

}

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.

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

Question 30

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

#include

using namespace std;

int main ()

{

float f1 = 10.0;

float f2 = 10.123;

cout<<noshowpoint<

return 0;

}

Program outputs:

Options:

A.

10 10

B.

10.0 10.123

C.

compilation error

D.

10 10.123

Question 31

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

#include

#include

#include

using namespace std;

template

int calculate(T start, T end)

{

int s = 0;

while (start != end)

s+= *start; start++;return s;

}

int main ()

{

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

vectorv1(t, t+5);

dequed1(t+5, t+10);

cout<<calculate(t,t+10)<<" ";

cout<<calculate(v1.begin()+1,v1.end()?2)<<" ";

cout<<calculate(d1.rbegin()+1,d1.rend()?2)<<" ";

cout<<calculate(t[0],t[10])<<" ";

cout<<endl;

return 0;

}

Options:

A.

compilation error

B.

runtime exception

C.

program outputs 55 5 17 55

D.

program outputs 55 5 17 0

Question 32

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(), bind1st(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

Page: 8 / 9
Total 228 questions