Spring Sale Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: pass65

CPP C++ Certified Professional Programmer Questions and Answers

Questions 4

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

#include < iostream >

using namespace std;

template < class A >

void f(A & a)

{

cout < < 1 < < endl;

}

void f(int & a)

{

cout < < 2 < < endl;

}

int main()

{

int a = 1;

f(a);

return 0;

}

Options:

A.

program displays: 1

B.

program displays: 2

C.

compilation error

D.

runtime exception

Buy Now
Questions 5

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

#include < deque >

#include < iostream >

#include < algorithm >

#include < set >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; }

};

int main() {

char s[]={"qwerty"};

char t1[]={"ert"};

char t2[]={"ERT"};

sort(s, s+6);

cout < < includes(s,s+6, t1,t1+3) < < " " < < includes(s,s+6, t2,t2+3) < < endl;

return 0;

}

Program outputs:

Options:

A.

0 0

B.

0 1

C.

1 0

D.

1 1

Buy Now
Questions 6

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

#include < deque >

#include < vector >

#include < iostream >

using namespace std;

int main ()

{

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

vector < int > v1(t, t + 10);

deque < int > d1(v1.begin(), v1.end());

deque < int > d2;

d2 = d1;

d2.insert(d1.rbegin(), 10);

for(int i = 0; i < d1.size(); i++)

{

cout < < d1[i] < < " ";

}

return 0;

}

Options:

A.

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

B.

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

C.

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

D.

compilation error

Buy Now
Questions 7

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

#include < iostream >

#include < algorithm >

#include < vector >

#include < set >

using namespace std;

int main() {

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

vector < int > v1(t, t + 15);

set < int > s1(t, t + 15);

pair < set < int > ::iterator, vector < int > ::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
Questions 8

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

#include < iostream >

#include < deque >

#include < list >

#include < queue >

#include < vector >

using namespace std;

int main()

{

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

deque < int > mydeck(t, t+10); list < int > mylist(t,t+10);

queue < int > first;

queue < int > second(mydeck);

queue < int > third(second);

queue < int, list < int > > fourth(mylist);

mylist.clear(); third.clear();

cout < < third.size() < < " " < < mydeck.size() < < endl;

cout < < fourth.size() < < " " < < mylist.size() < < endl;

return 0;

}

Options:

A.

program outputs: 10 0

10 0

B.

program outputs: 0 0

0 0

C.

program outputs: 10 10

10 10

D.

program outputs: 10 0

0 10

E.

compilation error

Buy Now
Questions 9

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

#include < iostream >

#include < set >

#include < vector >

using namespace std;

int main(){

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

vector < int > v(t, t+10);

set < int > s1(v.begin(),v.end());

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

bool found = s1.find(7);

if (found){

cout < < "Element found!\n";

}else {

cout < < "Element not found!\n";

}

return 0;

}

Options:

A.

program will display "Element found!"

B.

program will display "Element not found!\n"

C.

code will not compile

D.

changing type of variable found to int will make this code compile

Buy Now
Questions 10

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int Add(int a, int b) {

return a+b;

}

int main() {

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

vector < int > v1(t, t+10);

vector < int > v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind2nd(ptr_fun (Add),1));

for_each(v2.rbegin(), v2.rend(), Out < int > (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

Buy Now
Questions 11

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

#include < iostream >

#include < map >

#include < vector >

#include < sstream >

#include < string >

using namespace std;

int main(){

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

vector < int > v(t, t+10);

multimap < int,string > m;

for(vector < int > ::iterator i=v.begin(); i!=v.end(); i++) {

stringstream s; s < < *i < < *i; m.insert(pair < int,string > (*i,s.str()));

}

for(multimap < int, string > ::iterator i=m.begin();i!= m.end(); i++) {

cout < < *i < < " ";

}

return 0;

}

Options:

A.

program outputs: 3 4 2 1 0 1 2 3 4 0

B.

program outputs: 00 11 22 33 44

C.

program outputs: 0 0 1 1 2 2 3 3 4 4

D.

program outputs: 0 0 0 1 1 1 2 2 2 3 3 3 4 4 4

E.

compilation error

Buy Now
Questions 12

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

#include < iostream >

using namespace std;

int main()

{

cout < < true < < " " < < boolalpha < < false;

return 0;

}

Program outputs:

Options:

A.

true false

B.

1 0

C.

1 false

D.

true 0

E.

compilation error

Buy Now
Questions 13

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

#include < vector >

#include < iostream >

int main ()

{

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

std::vector < int > v1(t,t+5);

std::vector < int > v2(v1);

v1.resize(10);

v2.reserve(10);

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

while (i != v1.end()) { std::cout < < i[ii] < < " ";ii??;i++; }

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

while (i != v2.end()) { std::cout < < i[ii] < < " ";ii??;i++; }

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
Questions 14

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

#include < vector >

#include < iostream >

#include < algorithm >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

vector < B > v1(t,t+10);

sort(v1.begin(), v1.end(), greater < B > ());

cout < < *min_element(v1.begin(), v1.end());

return 0;

}

Program outputs:

Options:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

Buy Now
Questions 15

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

#include < deque >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

deque < int > d1(t, t+10);

deque < int > ::iterator it = lower_bound(d1.begin(), d1.end(), 4);

for_each(it, d1.end(), Out < int > (cout));cout < < endl;

return 0;

}

Program outputs:

Options:

A.

8 10 5 1 4 6 2 7 9 3

B.

4 5 6 7 8 9 10

C.

1 2 3 4 5 6 7 8 9 10

D.

compilation error

E.

1 2 3 4

Buy Now
Questions 16

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

#include < vector >

#include < iostream >

#include < algorithm >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

B t1[]={3,2,4,1,5};

int t2[]={5,6,8,2,1};

vector < B > v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

Options:

A.

3 2 4 1 5 6 8 2 1 0

B.

1 2 3 4 5 6 8 2 1 0

C.

1 1 2 2 3 4 5 5 6 8

D.

1 2 3 4 5 6 8 0 0 0

E.

compilation error

Buy Now
Questions 17

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

#include < iostream >

#include < string >

using namespace std;

int main ()

{

bool a,b;

cin > > boolalpha > > a > > b;

cout < < a < < b < < endl;

return 0;

}

Program will output:

Options:

A.

truefalse

B.

true0;

C.

1false

D.

10

E.

none of these

Buy Now
Questions 18

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

#include < iostream >

#include < map >

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 < int, string > m;

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

m.push_back(pair < int, string > (t[i], s[i] ));

}

for (map < int, string > ::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 19

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

#include < deque >

#include < set >

#include < iostream >

#include < algorithm >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

deque < B > d1(t, t+10);

sort(d1.begin(), d1.end());

set < B > s1(t,t+10);

cout < < binary_search(s1.begin(),s1.end(), 4) < < " " < < binary_search(d1.begin(),d1.end(), 4) < < endl;

return 0;

}

Program outputs:

Options:

A.

1 0

B.

1 1

C.

true true

D.

false false

E.

compilation error

Buy Now
Questions 20

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

#include < vector >

using namespace std;

int main ()

{

std::vector < int > v1;

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
Questions 21

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

#include < deque >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct 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 10*(1+(start++ %3));}

};

int main() {

deque < int > d1(10);

generate(d1.begin(), d1.end(), Sequence(1));

sort(d1.begin(), d1.end());

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

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

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 22

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

#include < iostream >

#include < algorithm >

#include < deque >

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

};

int main () {

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

deque < int > d (t,t+15);

int number = count(d.begin(), d.end(), 2);

cout < < number < < endl;

return 0;

}

Program outputs:

Options:

A.

4

B.

3

C.

2

D.

0

E.

compilation error

Buy Now
Questions 23

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

#include < iostream >

#include < algorithm >

#include < deque >

#include < vector >

using namespace std;

bool identical(int a, int b) {

return b == 2*a?true:false;

}

int main() {

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

int u[] = {2,4,6,4,6,10,2,4,14,6,4,2,20,8,8,5};

vector < int > v1(t, t + 15);

deque < int > d1(u, u + 15);

pair < deque < int > ::iterator, vector < int > ::iterator > result;

result = mismatch(d1.begin(), d1.end(), v1.begin(), identical); //Line I

if (result.first == d1.end() & & result.second == v1.end()) { //Line II

cout < < "Identical\n";

} else {

cout < < "Not identical\n";

}

return 0;

}

Program outputs:

Options:

A.

Identical

B.

Not identical

C.

compilation error at line marked I

D.

compilation error at line marked II

Buy Now
Questions 24

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

#include < iostream >

#include < fstream >

#include < string >

#include < list >

#include < algorithm >

#include < iomanip >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) {out < < setw(3) < < hex < < val; } };

int main () {

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

fstream f("test.out", ios::trunc|ios::out);

list < int > l(t, t+10);

for_each(l.begin(), l.end(), Out < int > (f));

f.close(); f.open("test.out");

for( ; f.good() ; ) {

int i; f > > i;

cout < < i < < " ";

}

f.close();

return 0;

}

Options:

A.

file test.out will be opened writing

B.

file test.out will be truncated

C.

file test.out will be opened for reading

D.

no file will be created nor opened

E.

program will display sequence 1 2 3 4 5 6 7 8 9 10

Buy Now
Questions 25

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

#include < iostream >

#include < algorithm >

#include < map >

using namespace std;

int main() {

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

map < int, int > m;

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

m[i]=t[i] ;

}

pair < const int,int > p(5,5);

map < int, int > ::iterator it = find(m.begin(), m.end(), p);

if (it != m.end())

{

cout < < it? > first < < endl;

}

else

{

cout < < "Not found!\n";

}

return 0;

}

Program outputs:

Options:

A.

5

B.

Not found!

C.

10

D.

compilation error

Buy Now
Questions 26

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

#include < iostream >

#include < map >

#include < vector >

#include < string >

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

map < int,string > m;

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

m.insert(pair < int,string > (second[i],first[i] ));

}

m[0]="ten";

m.insert(pair < int,string > (1,"eleven"));

for(map < int, string > ::iterator i=m.begin();i!= m.end(); i++) {

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

}

return 0;

}

Options:

A.

program outputs: zero one two three four five six seven eight nine

B.

program outputs: ten one two three four five six seven eight nine

C.

program outputs: zero eleven two three four five six seven eight nine

D.

program outputs: ten eleven two three four five six seven eight nine

E.

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

Buy Now
Questions 27

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

#include < deque >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

deque < int > d1(t, t+10);

sort(d1.begin(), d1.end());

deque < int > ::iterator it = upper_bound(d1.begin(), d1.end(), 4);

for_each(it, d1.end(), Out < int > (cout));cout < < endl;

return 0;

}

Program outputs:

Options:

A.

5 6 7 8 9 10

B.

4 5 6 7 8 9 10

C.

1 2 3 4 5 6 7 8 9 10

D.

1 2 3 4 5

E.

1 2 3 4

Buy Now
Questions 28

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

#include < iostream >

using namespace std;

template < class T >

class A {

T _v;

public:

A(T v);

};

template < class T >

Options:

A.

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

int main()

{

A < int > a(2);

cout < < 1 < < endl;

return 0;

}

B.

program will display: 1

C.

program will not compile

D.

program will compile

E.

program will cause runtime exception

Buy Now
Questions 29

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

#include < iostream >

#include < map >

#include < string >

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 < A, string > m; /* Replace Code Here 3 */

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

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

}

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

map < A, string > ::iterator i=m.begin(); /* Replace Code Here 4 */

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

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

}

cout < < endl;

return 0;

}

Options:

A.

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

B.

bool operator < (const A & b) const { return a < b.a;} inserted at Place 1

C.

bool operator < (const A & b) const { return b.a < a;} inserted at Place 1

D.

struct R { bool operator ()(const A & a, const A & b) { return a.getA() < b.getA();} }; inserted at Place 2

replacing line marked 3 with map < A, string, R > m;

replacing line marked 4 with map < A, string,R > ::iterator i=m.begin();

Buy Now
Questions 30

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

vector < B > v1(t,t+10);

cout < < *max_element(v1.begin(), v1.end(), greater < B > ());

cout < < endl;

return 0;

}

Program outputs:

Options:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

Buy Now
Questions 31

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

#include < iostream >

using namespace std;

int main()

{

cout < < 100 < < " ";

cout.setf(ios::hex);

cout < < 100 < < " ";

return 0;

}

Program outputs:

Options:

A.

100 64

B.

100 0x64

C.

0x64 0x64

D.

64 0x64

E.

100 100

Buy Now
Questions 32

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

#include < list >

#include < iostream >

using namespace std;

template < class T >

void print(T start, T end) {

while (start != end) {

std::cout < < *start < < " "; start++;

}

}

int main()

{

int t1[] = { 1, 7, 8, 4, 5 };

list < int > l1(t1, t1 + 5);

int t2[] = { 3, 2, 6, 9, 0 };

list < int > l2(t2, t2 + 5);

l1.sort();

list < int > ::iterator it = l2.begin();

it++; it++;

l1.splice(l1.end(),l2, it, l2.end());

print(l1.begin(), l1.end()); cout < < "Size:" < < l1.size() < < " ";

print(l2.begin(), l2.end()); cout < < "Size:" < < l2.size() < < endl;

return 0;

}

Options:

A.

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

B.

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

C.

compilation error

D.

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

E.

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

Buy Now
Questions 33

Which method added to class B at the marked spot will allow the code below to compile? Choose all possible solutions.

#include < vector >

#include < iostream >

#include < algorithm >

using namespace std;

class B { int val;

public:

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

int getV() const {return val;}

/* Insert Code Here */

};

ostream & operator < < (ostream & out, const B & v) { out < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

vector < B > v1(t, t+10);

sort(v1.begin(), v1.end(), greater < B > ());

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

return 0;

}

Options:

A.

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

B.

bool operator > (const B & v) const { return val < v.val;}

C.

bool operator > (const B & v) const { return val > v.val;}

D.

bool operator == (const B & v) const { return val==v.val;}

E.

operator int () const { return val; }

Buy Now
Questions 34

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

#include < iostream >

#include < set >

#include < list >

using namespace std;

int main(){

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

list < int > v(t, t+10);

set < int > s1(v.begin(),v.end());

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

s1.erase(3);

}

for(set < int > ::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
Questions 35

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

#include < vector >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

int t2[]={6,10,8,7,9};

vector < int > v1(10);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 10 8 7 9

B.

3 2 4 1 5 6 7 8 9 10

C.

3 2 4 1 5 6 10 8 7 9

D.

1 2 3 4 5 6 7 8 9 10

E.

compilation error

Buy Now
Questions 36

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

#include < iostream >

#include < algorithm >

#include < vector >

#include < set >

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

set < int > 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 37

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

#include < iostream >

#include < iomanip >

using namespace std;

int main ()

{

float f = 10.126;

cout.unsetf(ios::floatfield);

cout < < showpoint < < f < < fixed < < " " < < setprecision(2) < < f < < endl;

return 0;

}

Program outputs:

Options:

A.

10.126 10

B.

10.126 10.12

C.

10.1260 10.13

D.

10.126 10.13

Buy Now
Questions 38

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

#include < vector >

#include < iostream >

using namespace std;

class A

{

int a,b;

public:

A(const A & c) { a = c.a; }

A():a(0),b(0){}

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

int getA() {return a;} int getB() {return b;}

};

int main ()

{

vector < A > v;

A a;

a.setA(10); a.setB(11);

v.push_back(a);

cout < < v[0].getB() < < " " < < v[0].getA() < < endl;

return 0;

}

Options:

A.

program outputs 10 11

B.

the result is unpredictable

C.

program outputs 10 0

D.

program outputs 11 0

E.

compilation error

Buy Now
Questions 39

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

#include < vector >

#include < iostream >

#include < algorithm >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

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

vector < B > v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind2nd(Add(),1));

for_each(v2.rbegin(), v2.rend(), Out < B > (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

Buy Now
Questions 40

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

#include < vector >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct 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++; }

};

struct Odd { bool operator()(int v) { return v%2==0; }};

int main() {

vector < int > v1(10);

generate(v1.begin(), v1.end(), Sequence(1));

partition(v1.begin(),v1.end(), Odd());

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

return 0;

}

Choose all possible outputs:

Options:

A.

1 2 3 4 5 6 7 8 9 10

B.

5 7 3 9 1 10 2 8 4 6

C.

10 2 8 4 6 5 7 3 9 1

D.

4 6 8 10 2 7 5 3 1 9

E.

2 4 6 8 10 1 3 5 7 9

Buy Now
Questions 41

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

#include < iostream >

#include < string >

#include < list >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) {out < < val < < " "; } };

int main ()

{

list < string > l;

while(cin.good())

{

string s;

cin > > s;

if (s == "quit") break;

l.push_back(s);

}

for_each(l.begin(), l.end(), Out < string > (cout));

return 0;

}

Program will output:

Options:

A.

1 2 3 4

B.

1 2 3 4 quit

C.

1

D.

program runs forever without output

Buy Now
Questions 42

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

#include < vector >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

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

vector < int > v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind1st(Add(),1));

for_each(v2.rbegin(), v2.rend(), Out < int > (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

Buy Now
Questions 43

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

#include < list >

#include < iostream >

using namespace std;

bool mycomparison (int first, int second){ return first > second;}

template < class T >

void print(T start, T end) {

while (start != end) {

std::cout < < *start < < " "; start++;

}

}

int main()

{

int t1[] = { 1, 7, 8, 4, 5 };

list < int > l1(t1, t1 + 5);

int t2[] = { 3, 2, 6, 9, 0 };

list < int > l2(t2, t2 + 5);

l1.sort(mycomparison);

l2.sort(mycomparison);

l1.merge(l2,mycomparison);

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

print(l2.begin(), l2.end()); cout < < endl;

return 0;

}

Options:

A.

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

B.

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

C.

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

D.

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

E.

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

Buy Now
Questions 44

Which are NOT valid instantiations of priority_queue object:

#include < iostream >

#include < deque >

#include < list >

#include < queue >

#include < vector >

using namespace std;

int main()

{

deque < int > mydeck; list < int > mylist; vector < int > myvector;

priority_queue < int > first; //line I

priority_queue < int, deque < int > > second; //line II

priority_queue < int > third(first); //line III

priority_queue < int, list < int > > fourth(third); //line IV

priority_queue < int, vector < int > > fifth(myvector.begin(), myvector.end()); //line V

return 0;

}

Options:

A.

line I

B.

line II

C.

line III

D.

line IV

E.

line V

Buy Now
Questions 45

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

#include < deque >

#include < iostream >

#include < algorithm >

#include < functional >

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 < < v.getV(); return out;}

template < class T > struct Out {

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

int t[]={20, 30, 10, 20, 30, 10, 20, 30, 10, 20};

deque < B > d1(t, t+10);

sort(d1.begin(), d1.end(), greater < B > ());

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

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

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 46

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

#include < iostream >

#include < algorithm >

#include < vector >

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

bool operator==(const A & b) const { return a == b.a; }

};

bool compare(const A & a, const A & b) { return a == b; }

int main () {

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

vector < A > v (t,t+10);

vector < A > ::iterator it = v.begin();

while ( (it = adjacent_find (it, v.end(), compare)) != v.end()) {

cout < < it?v.begin() < < " ";it++;

}

cout < < endl;

return 0;

}

Options:

A.

program outputs: 2 3

B.

program outputs: 2 7

C.

program outputs: 3 8

D.

compilation error

E.

program will run forever

Buy Now
Questions 47

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

vector < B > v1(t, t+10);

transform(v1.begin(), v1.end(), v1.begin(), bind2nd(plus < B > (), 1));

for_each(v1.rbegin(), v1.rend(), Out < B > (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

Buy Now
Questions 48

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

#include < vector >

#include < set >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

bool Greater(int v1, int v2) { return v1 < v2; }

int main() {

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

vector < int > v1(t, t+10);

sort(v1.begin(), v1.end(), Greater);

for_each(v1.begin(), v1.end(), Out < int > (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
Questions 49

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

#include < vector >

#include < iostream >

#include < algorithm >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

B t1[]={3,2,4,1,5};

B t2[]={5,6,8,2,1};

vector < B > v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

Options:

A.

compilation error

B.

1 2 3 4 5 6 8 0 0 0

C.

1 2 3 4 5 6 8 2 1 0

D.

5 2 1 0 0 0 0 0 0 0

E.

1 2 5 0 0 0 0 0 0 0

Buy Now
Questions 50

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

#include < iostream >

using namespace std;

int main ()

{

int a,b,c;

cin > > a > > b > > c;

cout < < a < < b < < c < < endl;

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 51

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

#include < deque >

#include < iostream >

#include < algorithm >

using namespace std;

class B { int val;

public:

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

int getV() const {return val;} };

ostream & operator < < (ostream & out, const B & v) { out < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

deque < B > d1(t, t+10);

deque < B > ::iterator it = lower_bound(d1.begin(), d1.end(), 4);

for_each(it, d1.end(), Out < B > (cout));cout < < endl;

return 0;

}

Program outputs:

Options:

A.

8 10 5 1 4 6 2 7 9 3

B.

4 5 6 7 8 9 10

C.

1 2 3 4 5 6 7 8 9 10

D.

compilation error

E.

1 2 3 4

Buy Now
Questions 52

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

#include < iostream >

#include < set >

#include < vector >

using namespace std;

int main(){

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

vector < int > v(t, t+10);

set < int > s1(v.begin(),v.end());

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

pair < set < int > ::iterator,set < int > ::iterator > range;

range = s1.equal_range(6);

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

return 0;

}

The output will be:

Options:

A.

6 6

B.

5 7

C.

6 7

D.

1 5

E.

6 5

Buy Now
Questions 53

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

#include < set >

#include < iostream >

#include < algorithm >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

set < B > s1(t, t+10);

sort(s1.begin(), s1.end());

for_each(s1.begin(), s1.end(), Out < B > (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
Questions 54

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

#include < iostream >

#include < iomanip >

using namespace std;

int main ()

{

float f = 10.126;

cout < < f < < " " < < setprecision(2) < < f < < endl;

return 0;

}

Program outputs:

Options:

A.

10.126 10

B.

10.126 10.12

C.

compilation error

D.

10.126 10.13

Buy Now
Questions 55

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

#include < vector >

#include < set >

#include < deque >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct 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 < int > v1(5);

generate(v1.begin(), v1.end(), Sequence(1));

set < int > s1(v1.rbegin(), v1.rend());

deque < int > d1(s1.rbegin(), s1.rend());

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

reverse(s1.begin(), s1.end());

reverse(d1.begin(), d1.end());

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

for_each(s1.begin(), s1.end(), Out < int > (cout) );

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

return 0;

}

Program outputs:

Options:

A.

5 4 3 2 1 1 2 3 4 5 1 2 3 4 5

B.

1 2 3 4 5 1 2 3 4 5 5 4 3 2 1

C.

no output

D.

1 2 3 4 5 5 4 3 2 1 1 2 3 4 5

E.

compilation error

Buy Now
Questions 56

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

#include < iostream >

#include < algorithm >

#include < vector >

#include < set >

using namespace std;

void myfunction(int i) { cout < < " " < < i;

}

struct sequence {

int val,inc;

sequence(int s, int i):val(s),inc(i){}

int operator()(){

int r = val; val += inc;

return r;

}

};

int main() {

vector < int > v1(10);

fill(v1.begin(), v1.end(), sequence(1,1));

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 7 8 9 10

B.

10

C.

0 0 0 0 0 0 0 0 0 0

D.

compilation error

Buy Now
Questions 57

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

#include < vector >

#include < iostream >

#include < algorithm >

using namespace std;

template < class T > struct 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 < int > v1(10);

vector < int > v2(10);

generate(v1.begin(), v1.end(), Sequence(1));

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

for_each(v1.begin(), v1.end(), Out < int > (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
Questions 58

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

#include < deque >

#include < iostream >

#include < algorithm >

#include < set >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

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

deque < int > d1(t, t+10);

set < int > s1(t, t+10);

sort(d1.begin(), d1.end());

cout < < includes(s1.begin(),s1.end(), t1,t1+4) < < " " < < includes(d1.begin(),d1.end(), t1,t1+4)

< < endl;

return 0;

}

Program outputs:

Options:

A.

1 1

B.

1 0

C.

0 1

D.

0 0

Buy Now
Questions 59

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

#include < iostream >

#include < set >

#include < vector >

using namespace std;

int main(){

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

multiset < int > s1(t,t+10);

s1.insert(s1.find(7), 3);

for(multiset < int > ::iterator i=s1.begin();i!= s1.end(); i++) {

cout < < *i < < " ";

}

return 0;

}

Options:

A.

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

B.

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

C.

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

D.

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

E.

runtime exception

Buy Now
Questions 60

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

template < typename A > struct Add : public binary_function < A, A, A > {

A operator() (const A & a, const A & b) const { return a+b; }};

int main() {

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

vector < B > v1(t, t+10);

vector < B > v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add < B > ()), 1));

for_each(v2.rbegin(), v2.rend(), Out < B > (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

Buy Now
Questions 61

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

#include < iostream >

#include < algorithm >

#include < vector >

#include < set >

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

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

};

class F {

A val;

public:

F(A & v):val(v){}

bool operator() (A & v) {

if (v.getA() == val.getA()) return true;

return false;

}

};

int main() {

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

vector < A > v1(t, t + 10);

set < A > s1(t, t + 10);

A a(6); F f(a);

find_if(s1.begin(), s1.end(), f);

if (find_if(v1.begin(), v1.end(), f) !=v1.end()) {

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

Buy Now
Questions 62

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

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 < < v.getV(); return out;}

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

B Add(B a, B b) { return a+b; }

int main() {

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

vector < B > v1(t, t+10);

vector < B > v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind2nd(ptr_fun(Add),1));

for_each(v2.rbegin(), v2.rend(), Out < B > (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

Buy Now
Questions 63

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

#include < iostream >

#include < deque >

#include < list >

#include < stack >

#include < vector >

using namespace std;

int main()

{

deque < int > mydeck; list < int > mylist; vector < int > myvector;

stack < int > first;

stack < int > second(mydeck);

stack < int > third(second);

stack < int, list < int > > fourth(mylist);

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

stack < int, vector < int > > fifth(myvector);

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

while(!fifth.empty())

{

cout < < fifth.top() < < " ";

fifth.pop();

}

while (!fourth.empty())

{

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

fourth.pop();

}

return 0;

}

Options:

A.

program outputs: 12 11 10 12 11 10

B.

compilation error

C.

program outputs: 10 11 12 10 11 12

D.

runtime exception

Buy Now
Questions 64

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

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

vector < int > v2(10);

transform(v1.begin(), v1.end(), v2.begin(), bind1st(ptr_fun (Add()), 1));

for_each(v2.rbegin(), v2.rend(), Out < int > (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

Buy Now
Questions 65

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

#include < iostream >

#include < map >

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 < int, string > m;

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

m.insert(pair < int, string > (t[i], s[i] ));

}

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

m.erase(3);

}

for (map < int, string > ::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 3 3 4 4 5 5

E.

program outputs: one two three four five

Buy Now
Questions 66

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

#include < vector >

#include < iostream >

#include < algorithm >

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

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

B t1[]={3,2,4,1,5};

B t2[]={5,6,8,2,1};

vector < B > v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 8 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.

1 2 5 0 0 0 0 0 0 0

Buy Now
Questions 67

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

#include < vector >

#include < iostream >

#include < algorithm >

#include < functional >

using namespace std;

template < class T > struct Out {

ostream & out;

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

void operator() (const T & val ) { out < < val < < " "; } };

int main() {

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

vector < int > v1(t, t+10);

for_each(v1.begin(), v1.end(), bind1st(plus < int > (), 1));

for_each(v1.rbegin(), v1.rend(), Out < int > (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

Buy Now
Questions 68

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

#include < iostream >

using namespace std;

int main()

{

cout.setf(ios::oct, ios::basefield);

cout < < 100 < < " ";

cout.setf(ios::showbase);

cout < < 100 < < " ";

return 0;

}

Program outputs:

Options:

A.

144 0144

B.

144 0x64

C.

0x144 0144

D.

0144 100

E.

compilation error

Buy Now
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Apr 30, 2026
Questions: 228

PDF + Testing Engine

$63.52  $181.49

Testing Engine

$50.57  $144.49
buy now CPP testing engine

PDF (Q&A)

$43.57  $124.49
buy now CPP pdf