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

CPP Exam Dumps - C++ Certified Professional Programmer

Question # 4

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

#include

#include

#include

using namespace std;

int main(){

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

vectorv(myints, myints+10);

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

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

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

cout<<*i<<" ";

}

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

cout<<*i<<" ";

}

cout<

return 0;

}

A.

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

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

D.

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

Full Access
Question # 5

What will happen 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(){

vectorv;

set s;

for(int i=10; i>0; i??) {

v.push_back(i);

s.push_back(i);

}

print(v.begin(), v.end()); print(s.begin(), s.end());cout<

return 0;

}

The output will be:

A.

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

B.

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

C.

10 9 8 7 6 5 4 3 2 1 and unpredictable sequence of number range 1 to 10

D.

compilation error

Full Access
Question # 6

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

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

vector v1(t, t+10);

transform(v1.begin(), v1.end(), v1.begin(), bind2nd(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 # 7

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;

}

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

Question # 8

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

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

return 0;

}

Program outputs:

A.

10 5 9 6 2 4 7 8 3 1

B.

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

C.

compilation error

D.

runtime exception/segmentation fault

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

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:

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

Full Access
Question # 18

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

#include

#include

#include

using namespace std;

int main(){

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

vectorv(myints, myints+10);

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

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

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

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

cout<<*i<<" ";

}

return 0;

}

A.

program outputs: 0 1 8 9

B.

program outputs: 2 3 4 5 6 7

C.

program outputs: 1 6 5 7

D.

program outputs: 3 4 9 8 0

Full Access
Question # 19

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

multimap m;

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

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

}

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

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

}

return 0;

}

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

Full Access
Question # 20

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:

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

Full Access
Question # 21

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 multiply (int a) {

return a*2;

}

int main() {

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

vector v1(t, t+10);

set s1(t, t+10);

transform(s1.begin(), s1.end(), v1.begin(), multiply);

transform(v1.begin(), v1.end(), s1.begin(), multiply);

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

return 0;

}

Program outputs:

A.

20 10 18 12 4 8 14 16 6 2

B.

2 4 6 8 10 12 14 16 18 20

C.

4 8 12 16 20 24 28 32 36 40

D.

compilation error

Full Access
Question # 22

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:

A.

144 0144

B.

144 0x64

C.

0x144 0144

D.

0144 100

E.

compilation error

Full Access
Question # 23

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

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

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

vector v1(10,0);

sort(t1, t1+5); sort(t2, t2+5);

copy(t1,t1+5,v1.begin());

copy(t2,t2+5,v1.begin()+5);

inplace_merge(v1.begin(), v1.begin()+5,v1.end());

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

return 0;

}

Program outputs:

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

Full Access
Question # 24

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;

}

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

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[]={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 # 26

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

#include

#include

int main ()

{

std::vectorv1;

for(int i = 10; i>0; i??)

{

v1.push_back(i);

}

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

int sum = 0;

while(it != v1.end())

{

sum+=it++;

}

std::cout<<*v1.erase(v1.begin(),v1.end()?3)<<" "<

return 0;

}

A.

program outputs 3 55

B.

compilation error

C.

program outputs 3 45

D.

program outputs 7 55

Full Access
Question # 27

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

#include

#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", ios::trunc|ios::out);

list l(t, t+10);

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

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

for( ; f.good() ; ) {

int i; f>>i;

cout<

}

f.close();

return 0;

}

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

Full Access
Question # 28

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

#include

#include

#include

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<

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

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

return 0;

}

A.

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

B.

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

Full Access
Question # 29

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

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

}

pair p(5,5);

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

if (it != m.end())

{

cout<first<

}

else

{

cout<<"Not found!\n";

}

return 0;

}

Program outputs:

A.

5

B.

Not found!

C.

10

D.

compilation error

Full Access
Question # 31

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

copy(t1,t1+5,v1.begin());

copy(t2,t2+5,v1.begin()+5);

merge(v1.begin(), v1.begin()+5,v1.end());

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

return 0;

}

Program outputs:

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

Full Access
Question # 32

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

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

#include

#include

int main ()

{

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

std::vectorv1(t,t+5);

std::vectorv2(v1);

v1.resize(10);

v2.reserve(10);

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

while (i != v1.end()) { std::cout<

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

while (i != v2.end()) { std::cout<

return 0;

}

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

Full Access
Question # 34

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

vector v1(10);

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

return 0;

}

Program outputs:

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

Full Access