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

Ace Your CPP C++ Certified Professional Programmer Exam

Page: 3 / 8
Question 12

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

Question 13

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

Question 14

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

Question 15

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

#include

using namespace std;

int main()

{

cout.setf(ios::hex, ios::basefield);

cout<<100<<" ";

cout.unsetf(ios::hex);

cout<<100<<" ";

return 0;

}

Program outputs:

Options:

A.

64 64

B.

100 0x64

C.

0x64 0x64

D.

64 100

E.

compilation error

Page: 3 / 8
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: Nov 23, 2024
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