Black Friday Special 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: Board70

C++ Certified Professional Programmer CPP Reddit Questions

Page: 5 / 8
Question 20

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

Question 21

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

#include

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

vector v1(t, t + 10);

deque d1(t, t + 10);

set s1(t, t + 10);

for_each(v1.begin(), v1.end(), myfunction); // Line I

for_each(d1.begin(), d1.end(), myfunction); // Line II

for_each(s1.begin(), s1.end(), myfunction); // Line III

return 0;

}

Options:

A.

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

B.

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

C.

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

D.

compilation error in line I

E.

compilation error in line III

Question 22

Which sentence is correct about the code below? Choose all that apply.

#include

#include

#include

using namespace std;

class F {

int val;

public:

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

bool operator() (int v) {

if (v == val) return true;

return false;

}

};

int main() {

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

vector v1(t, t + 10);

if (find(v1.begin(), v1.end(), 6) == find(v1.begin(), v1.end(), F(6))) {

cout<<"Found!\n";

} else {

cout<<"Not found!\n";

}

return 0;

}

Options:

A.

it will compile successfully

B.

it will display Found!

C.

it will display Not found!

D.

it will not compile successfully

Question 23

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

#include

#include

#include

#include

#include

using namespace std;

struct display {

void operator() (int i) {cout << " " << i;}

};

int main() {

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

vector v1(t, t + 10);

deque d1(t, t + 10);

set s1(t, t + 10);

for_each(v1.begin(), v1.end(), display); //Line I

for_each(d1.begin(), d1.end(), *(new display())); // Line II

for_each(s1.begin(), s1.end(), display()); // Line III

return 0;

}

Options:

A.

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

B.

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

C.

compilation error in line I

D.

compilation error in line II

E.

compilation error in line III

Page: 5 / 8
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Nov 23, 2024
Questions: 228
CPP pdf

CPP PDF

$25.5  $84.99
CPP Engine

CPP Testing Engine

$28.5  $94.99
CPP PDF + Engine

CPP PDF + Testing Engine

$40.5  $134.99