Winter Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: netbudy65

CPP C++ Certified Professional Programmer Questions and Answers

Questions 4

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;

}

bool classifier(int v) {

return v%2==0;

}

int main() {

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

vector v1(t, t+10);

set 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 5

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

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.

6 7 8 9 10

D.

1 2 3 4 5

E.

1 2 3 4

Buy Now
Questions 6

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

vector::iterator it = search_n(v.begin(), v.end(), 4, 2);

cout<< it?v.begin()<

return 0;

}

Program outputs:

Options:

A.

10

B.

3

C.

1

D.

15

E.

compilation error

Buy Now
Questions 7

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;

}

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 8

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

vectorv;

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

}

Options:

A.

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

B.

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

C.

program outputs: 10 9 8 7 6 5 4 3 2 1 and unpredictable sequence of numbers range 1 to 10

D.

compilation error

Buy Now
Questions 9

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 10

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_intersection(t1,t1+5,t2,t2+5,v1.begin());

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

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.

1 1 2 2 3 4 5 5 6 8

E.

1 2 5 0 0 0 0 0 0 0

Buy Now
Questions 11

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;

}

Options:

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

Buy Now
Questions 12

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

};

template

Options:

A.

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

int main()

{

A a(2);

cout<<1<

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 13

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

vector v (t,t+10);

vector::iterator it;

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

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

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

return 0;

}

Program outputs:

Options:

A.

found at position: 5

B.

found at position: 0

C.

found at position: 6

D.

found at position: 1

E.

found at position: 10

Buy Now
Questions 14

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 15

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;

}

Options:

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

Buy Now
Questions 16

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

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

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

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:

Options:

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

Buy Now
Questions 19

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 20

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

#include

#include

#include

using namespace std;

class A

{

int a;

public:

A(int a) {this?>a = a; c++;}

~A() { c??;}

static int c;

};

int A::c(0);

int main ()

{

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

vectorv1(t, t+10);

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

deque d2;

d2 = d1;

cout<

return 0;

}

How many objects of type A will be created:

Options:

A.

10

B.

20

C.

30

D.

40

Questions 21

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

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

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

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

c<

}

};

int main()

{

Aa(10);

cout<

return 0;

}

Options:

A.

program will display:10

B.

program will not compile

C.

program will compile

D.

program will run without output

Buy Now
Questions 22

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

};

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

int main() {

vector v1(10);

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

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

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

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 23

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;

}

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 24

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

#include

#include

#include

using namespace std;

int main(){

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

string first[] = {"three", "four", "two", "one", "six","five", "seven", "nine","eight"," ten"};

map m;

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

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

}

if (m[11] == "eleven") {

cout<<"eleven ";

}

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

cout<second<<" ";

}

cout<

return 0;

}

Options:

A.

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

B.

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

C.

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

D.

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

E.

runtime exception

Buy Now
Questions 25

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

#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

};

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

set 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

Questions 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 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_symmetric_difference(t1,t1+5,t2,t2+5,v1.begin());

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

return 0;

}

Program outputs:

Options:

A.

6 8 3 4 0 0 0 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.

3 4 6 8 0 0 0 0 0 0

Buy Now
Questions 27

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

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

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

vector v1(t, t+8);

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

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

return 0;

}

Program outputs:

Options:

A.

Aaa Bbb aAa aaA aaa bBb bbB bbb

B.

Aaa aAa Bbb aaA aaa bBb bbB bbb

C.

bBb bbB bbb Aaa aAa Bbb aaA aaa

D.

Aaa aAa bBb bbB bbb Bbb aaA aaa

E.

compilation error

Buy Now
Questions 30

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

#include

#include

class A {

public:

virtual int f() { return 10; }

virtual ~A(){}

};

class B: public A {

int f() {return 11; }

virtual ~B(){}

};

int main (){

std::vectorv1;

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

{

i%2>0?v1.push_back(new A()):v1.push_back(new B());

}

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

while(it != v1.end())

{

std::cout<f()<<" ";

v1.pop_back();++it;

}

return 0;

}

Options:

A.

destructor of class A will be called

B.

destructor of class B will be called

C.

code will not compile

D.

program outputs 10 11 10 11 10

E.

program outputs 10 11 10 11 10 11 10 11 10 11

Buy Now
Questions 31

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 32

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;

}

Options:

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

Buy Now
Questions 33

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

}

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

m.erase(3);

}

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

E.

program outputs: one two three four five

Buy Now
Questions 34

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

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

vector v1(t,t+10);

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

cout<

return 0;

}

Program outputs:

Options:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

Buy Now
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Nov 21, 2024
Questions: 228

PDF + Testing Engine

$130

Testing Engine

$95

PDF (Q&A)

$80