Easter Special Sale - Limited Time 60% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: 575363r9

Welcome To DumpsPedia

CPP Sample Questions Answers

Questions 4

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

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

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

s1.erase(3);

}

for(multiset::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 2 3 3 4 4 5 5

E.

compilation error

Buy Now
Questions 5

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<

}

};

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<

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 6

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

#include

#include

#include

using namespace std;

int main ()

{

string s;

getline(cin, s);

stringstream input(s);

stringstream output;

for( ; !input.fail() ; )

{

int i;

input>>i;

output<

}

cout<

return 0;

}

Program will output:

Options:

A.

1 2 3

B.

1 2 3 3

C.

0x1 0x2 0x3

D.

0x1 0x2 0x3 0x3

E.

program runs forever without output

Buy Now
Questions 7

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

#include

#include

#include

using namespace std;

int main(){

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

vectorv(t, t+10);

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

multiset > s2(v.begin(), v.end());

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

cout<<*i<<" ";

}

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

cout<<*i<<" ";

}

cout<

return 0;

}

The output will be:

Options:

A.

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

B.

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

C.

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

D.

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

Buy Now
Questions 8

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

#include

#include

#include

using namespace std;

int main ()

{

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

dequed1(t, t+10);

vectorv1(t, t+10);

cout<

cout<

d1.resize(12); v1.resize(12);

cout<

cout<

d1.reserve(20);v1.reserve(20);

cout<

cout<

return 0;

}

Options:

A.

the output is 10 10 10 10 12 12 12 12 20 20

B.

reserve and resize means exactly the same

C.

there are compilation errors

D.

capacity is always smaller then size

Buy Now
Questions 9

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

#include

#include

#include

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

};

struct Even {

bool operator ()(const A & a, const A &b) {

return (a.getA() % 2)==b.getA() % 2;

}

};

int main () {

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

deque d (t,t+15);

deque::iterator it = search_n(d.begin(), d.end(), 3, 2, Even());

cout<< it?d.begin()<

return 0;

}

Program outputs:

Options:

A.

compilation error

B.

12

C.

3

D.

1

E.

15

Buy Now
Questions 10

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

B operator +(const B &b )const { return B(val + b.val);} };

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

templatestruct Out {

ostream & out;

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

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

B Add(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(), bind2nd(ptr_fun(Add),1));

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

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

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

set s1(t, t+10);

vector v1(s1.rbegin(), s1.rend());

swap(s1, v1);

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

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

return 0;

}

Program outputs:

Options:

A.

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

B.

compilation error

C.

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

D.

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

Buy Now
Questions 12

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

#include

#include

using namespace std;

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

template

void print(T start, T end) {

while (start != end) {

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

}

}

int main()

{

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

list l1(t1, t1 + 5);

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

list 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<

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 13

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

B operator ?(const B &b )const { return B(val ? b.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 t1[]={1,2,3,4,5,6,7,8,9,10};

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

vector v1(t1, t1+10);

vector v2(t2, t2+10);

vector v3(10);

transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus());

for_each(v3.rbegin(), v3.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

A.

9 7 5 3 1 ?1 ?3 ?5 ?7 ?9

B.

?1 ?3 ?5 ?7 ?9 9 7 5 3 1

C.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

D.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

E.

?9 ?7 ?5 ?3 ?1 1 3 5 7 9

Buy Now
Questions 14

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

#include

#include

#include

using namespace std;

int main () {

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

vector v (t,t+10);

vector::iterator it = v.begin();

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

cout<

}

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 15

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

#include

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

void operator()(const T & val ) {

out<

}

};

struct Sequence {

int start;

Sequence(int start):start(start){}

int operator()() {

return start++ ;

}

};

int main() {

vector v1(5);

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

set s1(v1.rbegin(), v1.rend());

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

for_each(s1.begin(), s1.end(), Out(cout) );

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

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 16

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

#include

#include

using namespace std;

int main ()

{

float f = 10.126;

cout<

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 17

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<

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

vector v2(10);

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

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

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 18

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 add (int a, int b) { return a+b; }

int main() {

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

vector v1(t, t+10);

set s1(t, t+10);

deque d1;

d1.resize(s1.size());

transform(s1.begin(), s1.end(), v1.begin(), d1.begin(), add);

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

return 0;

}

Program outputs:

Options:

A.

0 0 0 0 0 0 0 0 0 0

B.

11 7 12 10 7 10 14 16 12 11

C.

compilation error

D.

runtime exception

E.

20 10 18 12 4 8 14 16 6 2

Buy Now
Questions 19

Which are NOT valid instantiations of priority_queue object:

#include

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;list mylist; vector myvector;

priority_queue first;//line I

priority_queue > second;//line II

priority_queue third(first);//line III

priority_queue > fourth(third);//line IV

priority_queue > 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 20

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

#include

using namespace std;

template

class A {

T_v;

public:

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

T getV() { return _v; }

};

int main()

{

A a(1);

cout << a.getV() <

return 0;

}

Options:

A.

program will display:1

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Buy Now
Questions 21

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

#include

#include

#include

using namespace std;

int main(){

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

vectorv(t, t+10);

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

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

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

range = s1.equal_range(6);

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

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 22

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<

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 23

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):val(v){}

int getV() const {return val;} bool operator < (const B & v) 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[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

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

deque d1(t, t+10);

set s1(t, t+10);

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

cout<

<

return 0;

}

Program outputs:

Options:

A.

1 1

B.

1 0

C.

0 1

D.

0 0

E.

compilation error

Buy Now
Questions 24

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

#include

#include

#include

#include

#include

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

};

struct display { void operator() (const A & a) {cout << " " << a.getA();} };

struct add10

{

void operator() (A & a) { a.setA(a.getA()+10) ;}

};

int main() {

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

vector v1(t, t + 10);

set s1(t, t + 10);

for_each(v1.begin(), v1.end(), add10()); for_each(v1.begin(), v1.end(), display());

for_each(s1.begin(), s1.end(), add10()); for_each(s1.begin(), s1.end(), display());

return 0;

}

Options:

A.

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

B.

program outputs: 20 15 19 16 12 14 17 18 13 11 1 2 3 4 5 6 7 8 9 10

C.

program outputs: 20 15 19 16 12 14 17 18 13 11 11 12 13 14 15 16 17 18 19 20

D.

compilation error

Questions 25

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<

return 0;

}

Program outputs:

Options:

A.

10 10

B.

10.0 10.123

C.

compilation error

D.

10 10.123

Buy Now
Questions 26

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

#include

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

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

char s[]={"qwerty"};

char t1[]={"ert"};

char t2[]={"ERT"};

sort(s, s+6);

cout<

return 0;

}

Program outputs:

Options:

A.

0 0

B.

0 1

C.

1 0

D.

1 1

Buy Now
Questions 28

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

#include

#include

int main ()

{

std::vectorv1;

for(int i = 0; i<10; i++) {v1.push_back(i); }

std::vector v2(v1.begin()+2, v1.end()?2);

std::vector::iterator it = v2.begin();

for( ; it != v2.end(); it++) {std::cout<<*it++<<" "; }std::cout<

return 0;

}

Options:

A.

compilation error

B.

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

C.

program outputs 2 3 4 5 6 7

D.

program outputs 2 4 6

Buy Now
Questions 29

Which lines of the code below contain proper instantiation of queue objects?

#include

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;

list mylist;

vector myvector;

queue first; // line I

queue second(mydeck);// line II

queue third(second);// line III

queue fourth(mylist);// line IV

queue fifth(myvector);// line V

return 0;

}

Options:

A.

line I

B.

line II

C.

line III

D.

line IV

E.

line V

Buy Now
Questions 30

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

#include

#include

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

{

vectorv;

A a;

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

v.push_back(a);

cout<

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

Questions 31

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

#include

#include

#include

using namespace std;

template

void print(T start, T end) {

while (start != end) {

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

}

}

int main()

{

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

list l1(t1, t1 + 5);

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

deque d1(t2, t2 + 5);

l1.sort();

d1.sort();

l1.merge(d1);

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

print(d1.begin(), d2.end()); cout<

return 0;

}

Options:

A.

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

B.

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

C.

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

D.

compilation error

Buy Now
Questions 32

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

#include

using namespace std;

class C {

public:

int _c;

C():_c(0){}

C(int c) { _c = c;}

C operator+=(C & b) {

C tmp;

tmp._c = _c+b._c;

return tmp;

}

};

template

class A {

T_v;

public:

A() {}

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

T getV() { return _v; }

void add(T & a) { _v+=a; }

};

int main()

{

A b(2);

Aa (5);

Cc;

a.add(c);

cout << a.getV() <

return 0;

}

Options:

A.

program will display:2

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Buy Now
Questions 33

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

#include

#include

using namespace std;

template

void print(T start, T end) {

while (start != end) {

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

}

}

int main()

{

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

list l1(t1, t1 + 5);

l1.remove(2);

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

return 0;

}

Options:

A.

program outputs: 1 2 4 5

B.

program outputs: 3 4 5

C.

program outputs: 1 3 4 5

D.

program outputs: 4 5

Buy Now
Questions 34

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<

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<

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 35

What will happen when you attempt to compile and run the code below, assuming that file test.out do not exist before the program execution?

#include

#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[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};

fstream f("test.out");

list l(t, t+10);

for_each(l.begin(), l.end(), Out(f));

f.close();

return 0;

}

Options:

A.

file test.out will be created and opened for writing

B.

file test.out will be created and opened for reading

C.

no file will be created nor opened

D.

file test.out will contain sequence 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

#include

#include

#include

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

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

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

deque d1(t, t+10);

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

set s1(t,t+10);

cout<

return 0;

}

Program outputs:

Options:

A.

1 0

B.

1 1

C.

0 0

D.

0 1

E.

compilation error

Buy Now
Questions 37

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<

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

vector v2(10);

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

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

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 38

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

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

set s1(t, t+10);

vector v1(s1.rbegin(), s1.rend());

swap_ranges(s1.begin(), s1.end(), v1.begin());

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

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

return 0;

}

Program outputs:

Options:

A.

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

B.

compilation error

C.

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

D.

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

E.

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

Buy Now
Questions 39

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

#include

using namespace std;

int main()

{

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

cout<<100<<" ";

cout.flags(ios::showbase);

cout<<100<<" ";

return 0;

}

Program outputs:

Options:

A.

64 64

B.

64 0x64

C.

0x64 0x64

D.

64 100

E.

compilation error

Buy Now
Questions 40

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

#include

#include

#include

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

operator int() const {return a;}

};

int main () {

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

set s (t,t+15);

cout<

return 0;

}

Program outputs:

Options:

A.

true

B.

false

C.

1

D.

0

E.

compilation error

Questions 41

What will happen when you attempt to compile and run the code below, assuming that file test.in contains the following sequence: 1 2 3?

#include

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main () {

ifstream f("test.in");

list l;

for( ; !f.fail() ; ) {

int i;

f>>i;

l.push_back(i);

}

f.close();

for_each(l.begin(), l.end(), Out(cout));

return 0;

}

Programwill output:

Options:

A.

1 2 3

B.

1 2 3 3

C.

no output

D.

compilation error

E.

program runs forever without output

Buy Now
Questions 42

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):val(v){}

int getV() const {return val;} bool operator < (const B & v) 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() {

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

deque d1(t, t+10);

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

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

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

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 43

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<

int main() {

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

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

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

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 44

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(1,Add()));

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<

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 45

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: one two three?

#include

#include

using namespace std;

int main ()

{

string a;

cin>>a;

cout<

return 0;

}

Program will output:

Options:

A.

one

B.

one two three

C.

runtime exception

D.

compilation error

E.

the result is unspecified

Buy Now
Questions 46

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):val(v){}

int getV() const {return val;} bool operator < (const B & v) 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() {

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

deque d1(t, t+10);

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

deque::iterator it = upper_bound(d1.begin(), d1.end(), B(4), greater());

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

return 0;

}

Program outputs:

Options:

A.

5 6 7 8 9 10

B.

4 5 6 7 8 9 10

C.

compilation error

D.

1 2 3 4 5

E.

1 2 3 4

Buy Now
Questions 47

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<

}

};

struct Sequence {

int start;

Sequence(int start):start(start){}

int operator()() {

return start++ ; }};

int main() {

vector v1(10);

generate(v1.rbegin(), v1.rend(), Sequence(1));

rotate(v1.begin(),v1.begin() + 1, v1.end() );

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

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.

9 8 7 6 5 4 3 2 1 10

D.

1 10 9 8 7 6 5 4 3 2

Buy Now
Questions 48

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

#include

#include

#include

using namespace std;

int main ()

{

vectorv1;

dequed1;

for(int i=0; i<5; i++)

{

v1.push_back(i);v1.push_front(i);

d1.push_back(i);d1.push_front(i);

}

for(int i=0; i

{

cout<

}

cout<

return 0;

}

What will be its output:

Options:

A.

4 4 3 3 2 2 1 1 0 0 0 0 1 1 2 2 3 3 4 4

B.

runtime exception

C.

compilation error due to line 11

D.

compilation error due to line 12

Buy Now
Questions 49

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[]={8, 10, 5, 1, 4, 6, 2, 7, 9, 3};

deque d1(t, t+10);

set s1(t,t+10);

cout<

return 0;

}

Choose all possible outputs (all that apply):

Options:

A.

1 0

B.

1 1

C.

true true

D.

false false

E.

compilation error

Buy Now
Questions 50

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

Buy Now
Questions 51

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

#include

using namespace std;

int main()

{

cout<

return 0;

}

Program outputs:

Options:

A.

true false

B.

1 0

C.

1 false

D.

true 0

E.

compilation error

Buy Now
Questions 52

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

#include

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

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

T getV() { return _v; }

void add(T & a) { _v+=a; }

void add(string & a) {

_v.insert(0, a);

}

};

int main()

{

Aa("Hello");

string s(" world!");

a.add(s);

cout << a.getV() <

return 0;

}

Options:

A.

program will display: Hello world!

B.

compilation error

C.

program will display: world!Hello

D.

program will run without any output

Buy Now
Questions 53

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

map m;

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

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

}

m[0]="ten";

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

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

cout<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 54

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<

int main() {

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

deque d1(t, t+10);

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

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

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 55

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<

};

bool Compare(char a, char b) { return tolower(a) < tolower(b);}

int main() {

char s[]={"qwerty"};

char t1[]={"ert"};

char t2[]={"ERT"};

sort(s, s+6);

cout<

return 0;

}

Program outputs:

Options:

A.

0 0

B.

0 1

C.

1 0

D.

1 1

Buy Now
Questions 56

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

map m;

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

m.push_back(pair(t[i], s[i]));

}

for (map::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 57

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

#include

#include

using namespace std;

int main ()

{

bool a,b;

cin>>boolalpha>>a>>b;

cout<

return 0;

}

Program will output:

Options:

A.

truefalse

B.

true0;

C.

1false

D.

10

E.

none of these

Buy Now
Questions 58

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

#include

#include

#include

#include

#include

using namespace std;

class compare {

bool reverse;

public:

compare(bool revparam = false){ reverse = revparam;}

bool operator()(int lhs, int rhs) const{

if (reverse)return (lhs > rhs);

elsereturn (lhs < rhs);

}

};

int main(){

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

priority_queue > first(myints, myints + 10);

priority_queue, compare> second(myints, myints + 10,

compare(false));

while (first.size() > 0){

cout << first.top() << " "; first.pop();

}

while (second.size() > 0) {

cout << second.top() << " ";second.pop();

}

return 0;

}

Options:

A.

compilation error

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

D.

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

Buy Now
Questions 59

Which sentence is correct about the code below?

#include

#include

#include

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

/* Insert Code Here */

};

struct add10 { void operator()(A & a) { a.setA(a.getA() + 10); } };

int main() {

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

vector v1(t, t + 10);

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

vector::iterator it = find(v1.begin(), v1.end(), A(7));

cout << it?>getA() << endl;

return 0;

}

Options:

A.

it will compile and print 7

B.

it will not compile

C.

it will compile but the program result is unpredictable

D.

adding code:

bool operator !=(const A & b) const {

if (this?>a != b.a) { return true; } return false; }

at Place 1 will allow the program to compile

Questions 60

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):val(v){}

int getV() const {return val;} bool operator < (const B & v) 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() {

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

vector v1(t, t+10);

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

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

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 61

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main ()

{

list l;

for( ; !cin.bad() ; )

{

int i;

cin>>i;

l.push_back(i);

}

for_each(l.begin(), l.end(), Out(cout));

return 0;

}

Program will output:

Options:

A.

1 2 3

B.

1 2 3 end

C.

1

D.

compilation error

E.

program runs forever without output

Buy Now
Questions 62

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

#include

#include

#include

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

multimap m;/* Replace Code Here 3 */

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

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

}

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

multimap::iterator i=m.begin();/* Replace Code Here 4 */

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

cout<second<<" ";

}

cout<

return 0;

}

Options:

A.

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

B.

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

C.

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

D.

struct R { bool operator ()(const A & a, const A & b) { return a.getA()

replacing line marked 3 with multimap m;

replacong line marked 4 with multimap::iterator i=m.begin();

Buy Now
Questions 63

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 t1[]={1,2,3,4,5,6,7,8,9,10};

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

vector v1(t1, t1+10);

vector v2(t2, t2+10);

vector v3(10);

transform(v1.begin(), v1.end(), v2.rbegin(), v3.begin(), minus());

for_each(v3.rbegin(), v3.rend(), Out(cout));cout<

return 0;

}

Program outputs:

Options:

A.

9 7 5 3 1 ?1 ?3 ?5 ?7 ?9

B.

?1 ?3 ?5 ?7 ?9 9 7 5 3 1

C.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

D.

1 3 5 7 9 ?1 ?3 ?5 ?7 ?9

E.

?9 ?7 ?5 ?3 ?1 1 3 5 7 9

Buy Now
Questions 64

Which stack initialization (line numbers) are correct? Choose all that apply.

#include

#include

#include

#include

#include

using namespace std;

int main()

{

deque mydeck;

list mylist;

vector myvector;

stack first;// Line I

stack second(mydeck);// Line II

stack third(second);// Line III

stack > fourth(mylist);// Line IV

stack > fifth(myvector);// Line V

return 0;

}

Options:

A.

line I

B.

line II

C.

line III

D.

line IV

E.

line V

Buy Now
Questions 66

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

#include

#include

#include

using namespace std;

int main() {

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

map m;

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

m[i]=t[i];

}

map::iterator it = find(m.begin(), m.end(), 5);

cout<first;

return 0;

}

Program outputs:

Options:

A.

5

B.

4

C.

10

D.

compilation error

Buy Now
Questions 67

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

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

#include

#include

#include

#include

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

deque d1(u, u + 15);

pair::iterator, vector::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
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: May 15, 2024
Questions: 228
$64  $159.99
$48  $119.99
$40  $99.99
buy now CPP