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

CPP Exam Dumps - C++ Institute C++ Certified Professional Programmer Questions and Answers

Question # 14

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

}

};

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

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
Question # 15

What will be output of the program when you attempt to compile and run the following code?

#include

#include

#include

#include

using namespace std;

int main(){

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

string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight","zero"};

multimap m;

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

m.insert(pair(second[i],first[i]));

}

m[0]="ten";

m.insert(pair(1,"eleven"));

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

cout<<i?>second<<" ";

}

return 0;

}

Options:

A.

zero one two three four five six seven eight nine

B.

ten one two three four five six seven eight nine

C.

zero eleven two three four five six seven eight nine

D.

ten eleven two three four five six seven eight nine

E.

compilation error

Buy Now
Question # 16

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

#include

using namespace std;

int main ()

{

std::vectorv1;

v1.push_back(10);

return 0;

}

Options:

A.

compilation fails due to error in line 2

B.

compilation fails due to error in line 5

C.

exception is thrown during run time

D.

code compiles and executes successfully

Buy Now
Question # 17

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_backward(t, t+10, v1.rend());

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

return 0;

}

Program outputs:

Options:

A.

10 5 9 6 2 4 7 8 3 1

B.

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

C.

1 3 8 7 4 2 6 9 5 10

D.

runtime exception/segmentation fault

E.

compilation error

Buy Now
Question # 18

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

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

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
Question # 19

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

#include

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;list mylist; vector myvector;

queue first; queue second(mydeck);

queue third(second); queue > fourth(mylist);

fourth.push(10);fourth.push(11);fourth.push(12);

queue > fifth(myvector);

fifth.push(10);fifth.push(11);fifth.push(12); // Line I

while(!fifth.empty())

{

cout<<fifth.front()<<" "; // Line II

fifth.pop(); // Line III

}

while (!fourth.empty())

{

cout << fourth.front() << " ";

fourth.pop(); // Line IV

}

return 0;

}

Options:

A.

program outputs: 10 11 12 10 11 12

B.

compilation error in line I

C.

compilation error in line II

D.

compilation error in line III

E.

compilation error in line IV

Buy Now
Question # 20

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
Question # 21

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

#include

#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 v1(t, t + 15);

set s1(t, t + 15);

pair::iterator, vector::iterator > resultSet = mismatch(s1.begin(), s1.end(), v1.begin());

cout<<*resultSet.first<<" "<<*resultSet.second<<endl;

return 0;

}

Program outputs:

Options:

A.

2 4

B.

4 2

C.

0 5

D.

compilation error

Buy Now
Question # 22

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

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

A(T v): _v(v){}

friend ostream & operator<<(ostream & c, const A & v) {

c<<v._v;return c;

}

};

int main()

{

Aa(10);

cout<<a<<endl;

return 0;

}

Options:

A.

program will display:10

B.

program will not compile

C.

program will compile

D.

program will run without output

Buy Now
Question # 23

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

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

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

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

cout<<*i<<" ";

}

return 0;

}

Options:

A.

program outputs: 0 1 8 9

B.

program outputs: 2 3 4 5 6 7

C.

program outputs: 1 6 5 7

D.

program outputs: 3 4 9 8 0

Buy Now
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Apr 1, 2025
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