New Year Special Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: scxmas70

CPP Exam Dumps - C++ Certified Professional Programmer

Go to page:
Question # 9

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 # 10

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 # 11

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

#include

using namespace std;

int main ()

{

std::vectorv1;

v1.push_back(10);

return 0;

}

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

Full Access
Question # 12

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

#include

#include

#include

using namespace std;

void myfunction(int i) {

cout << " " << i;

}

void multiply (int a) {

a*2;

}

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

iter_swap(v1.begin(),t+9);

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

return 0;

}

Program outputs:

A.

1 5 9 6 2 4 7 8 3 1

B.

compilation error

C.

1 2 3 4 5 6 7 8 9 10

D.

10 9 8 7 6 5 4 3 2 1

E.

10 5 9 6 2 4 7 8 3 1

Full Access
Question # 13

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

#include

#include

#include

using namespace std;

int main ()

{

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

vector v1(t, t + 10);

deque d1(v1.begin(), v1.end());

deque d2;

d2 = d1;

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

for(int i = 0; i

{

cout<

}

return 0;

}

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

Full Access
Question # 14

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

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

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

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(), bind2nd(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 # 15

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:

A.

one

B.

one two three

C.

runtime exception

D.

compilation error

E.

the result is unspecified

Full Access
Question # 16

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;

}

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

Full Access
Go to page: