Winter Sale Special 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: ex2p65

Exact2Pass Menu

Question # 4

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

vector v1(t,t+10);

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

cout<

return 0;

}

Program outputs:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

Full Access
Question # 5

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,2,3,5,1,2,7,3,2,1,10, 4,4,5};

vector v (t,t+15);

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

cout<< number<

return 0;

}

Program outputs:

A.

4

B.

3

C.

2

D.

0

E.

compilation error

Full Access
Question # 6

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

#include

#include

#include

using namespace std;

struct Even {

bool operator ()(int a) {

return (a % 2)==0?true:false;

}

};

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

int number = count_if(s.begin(), s.end(), Even());

cout<< number<

return 0;

}

Program outputs:

A.

4

B.

3

C.

7

D.

8

E.

compilation error

Full Access
Question # 7

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

}

}

class A {

int a;

public:

A(int a):a(a){}

operator int () const { return a;}int getA() const { return a;}

};

struct R {

int val;

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

bool operator ()(const A & a) { return a>val;} };

int main() {

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

list l1(t1, t1 + 10);

R r(4);l1.remove_if(r);

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

return 0;

}

A.

program outputs: 1 2 3 4

B.

program outputs: 5 6 7 8 9 10

C.

program outputs: 1 2 3 4 5

D.

program outputs: 6 7 8 9 10

Question # 8

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<

return 0;

}

Program outputs:

A.

2 4

B.

4 2

C.

0 5

D.

compilation error

Full Access
Question # 9

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

#include

#include

using namespace std;

int main ()

{

float f = 10.126;

cout.unsetf(ios::floatfield);

cout<

return 0;

}

Program outputs:

A.

10.126 10

B.

10.126 10.12

C.

10.1260 10.13

D.

10.126 10.13

Full Access
Question # 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):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<

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

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

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

return 0;

}

Program outputs:

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

Full Access
Question # 11

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:

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

Full Access
Question # 12

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;

}

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

Full Access
Question # 13

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

vector v1(10,1);

fill(v1.begin()+2, v1.end()?2,2);

fill_n(v1.begin()+4,2,3);

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

return 0;

}

Program outputs:

A.

1 1 2 2 3 3 2 2 1 1

B.

1 1 2 2 2 2 2 2 1 1

C.

compilation error

D.

none of these

Full Access
Question # 14

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

}

return 0;

}

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

Full Access
Question # 15

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

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

int main() {

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

vector v1(t, t+10);

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

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

return 0;

}

Program outputs:

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

Full Access
Question # 16

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

#include

#include

#include

#include

#include

using namespace std;

templateclass B { T val;

public:

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

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

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

templatestruct Out {

ostream & out;

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

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

string tolower(const string & s) {

string tmp(s);

for(unsigned i = 0; i< tmp.size(); ++i){

tmp[i] = tolower(tmp[i]); }

return tmp; }

bool Less(const B &a, const B &b) {

return tolower(a.getV())

int main() {

string t[]={"aaa","bbb","Aaa", "Bbb","aAa","bBb","aaA","bbB"};

vector > v1; v1.assign(t, t+8);

stable_sort(v1.begin(), v1.end(), Less);

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

return 0;

}

Program outputs:

A.

Aaa aaa aAa aaA bbb Bbb bBb bbB

B.

Aaa aaa aAa aaA bbb Bbb bbB bBb

C.

aaa Aaa aAa aaA bbb Bbb bBb bbB

D.

the exact output is impossible to determine

Full Access
Question # 17

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

#include

#include

using namespace std;

int main ()

{

bool a,b;

cin>>a>>b;

cout<

return 0;

}

Program will output:

A.

truetrue

B.

falsefalse

C.

11

D.

00

E.

none of these

Full Access
Question # 18

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:

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

Full Access
Question # 19

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

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

templatestruct Out {

ostream & out;

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

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

struct Add : public binary_function {

B operator() (const B & a, const B & b) const {

return a+b; } };

int main() {

B 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:

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

Full Access
Question # 20

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:

A.

1 1

B.

1 0

C.

0 1

D.

0 0

E.

compilation error

Full Access
Question # 21

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

string t1[] ={ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};

list l1(t1, t1 + 10);

list l2(l1);

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

l1.unique();

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

return 0;

}

A.

compilation error

B.

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

C.

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

D.

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

Full Access
Question # 22

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

}

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

m.erase(3);

}

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

cout << i?>first << " ";

}

return 0;

}

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

Full Access
Question # 23

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

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

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

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

};

template

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

c<

int main()

{

Aa(10);

cout<

return 0;

}

A.

program will display:10

B.

program will not compile

C.

program will compile

D.

program will run without output

Full Access
Question # 24

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

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

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

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

cout<second<<" ";

}

cout<

return 0;

}

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 map m;

replacing line marked 4 with map::iterator i=m.begin();

Full Access
Question # 25

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

A.

1 0

B.

1 1

C.

true true

D.

false false

E.

compilation error

Full Access
Question # 26

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:

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

Full Access
Question # 27

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:

A.

1 2 3

B.

1 2 3 3

C.

0x1 0x2 0x3

D.

0x1 0x2 0x3 0x3

E.

program runs forever without output

Full Access
Question # 28

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:

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

Full Access
Question # 29

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

#include

using namespace std;

template

void f(A a)

{

cout<<1<

}

void f(int a)

{

cout<<2<

}

int main()

{

int a = 1;

f(a);

return 0;

}

A.

program displays: 1

B.

program displays: 2

C.

compilation error

D.

runtime exception

Full Access
Question # 30

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

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

return 0;

}

Program outputs:

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

Full Access
Question # 31

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,4,5,1,2,3,5,4};

vector v (t,t+10);

vector::iterator it;

int m1[] = {1, 3, 2};

it = find_end (v.begin(), v.end(), m1, m1+3);

if (it != v.end())

cout << "Found at position: " << it?v.begin() << endl;

return 0;

}

A.

program outputs: Found at position: 5

B.

program outputs: Found at position: 0

C.

no output

D.

program outputs: Found at position: 10

Full Access
Question # 32

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

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

};

struct Compare {

bool operator ()(A & a) {

if (a.getA() < 5) return true;

return false;

}

};

int main () {

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

set d (t,t+15);

int number = count_if(d.begin(), d.end(), Compare());

cout<< number<

return 0;

}

Program outputs:

A.

12

B.

4

C.

2

D.

0

E.

compilation error

Question # 33

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

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

vector v1(5);

transform(t1,t1+5,t2,v1.rbegin(), plus());

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

return 0;

}

Program outputs:

A.

9 12 12 8 14

B.

14 8 12 12 9

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

Full Access
Question # 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<

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:

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

Full Access