Special Summer Sale 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: Board70

CPP Exam Dumps - C++ Institute C++ Certified Professional Programmer Questions and Answers

Question # 4

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

int getV() const {return val;} bool operator > (const B & v) const { return val>v.val;} };

ostream & operator <<(ostream & out, const B & v) { out<<v.getV(); return out;}

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<<val<<" "; } };

int main() {

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

deque d1(t, t+10);

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

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

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

return 0;

}

Program outputs:

Options:

A.

4 3 2 1

B.

3 2 1

C.

5 4 3 2 1

D.

compilation error

E.

1 2 3 4

Buy Now
Question # 5

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

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
Question # 6

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

#include

#include

using namespace std;

int main ()

{

vectorv1(10, 3);

v1.push_back(3);

cout<<v1.capacity()<<" "<< v1.size()<<endl;

return 0;

}

Options:

A.

program displays 4 4

B.

program displays 10 3

C.

size of vector v1 is 11

D.

all elements of vector v1 are of the same value

Buy Now
Question # 7

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.getline(a);

cout<<a<<endl;

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
Question # 8

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

};

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

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

cout<< number<<endl;

return 0;

}

Program outputs:

Options:

A.

4

B.

3

C.

2

D.

0

E.

compilation error

Buy Now
Question # 10

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

return 0;

}

B.

program will display: 1

C.

program will not compile

D.

program will compile

E.

program will cause runtime exception

Buy Now
Question # 11

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

Question # 12

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<<v[0].getB()<<" "<<v[0].getA()<<endl;

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

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;

}

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
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Mar 31, 2025
Questions: 228
CPP pdf

CPP PDF

$25.5  $84.99
CPP Engine

CPP Testing Engine

$28.5  $94.99
CPP PDF + Engine

CPP PDF + Testing Engine

$40.5  $134.99