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

C++ Institute CPP Online Access

Page: 7 / 8
Question 28

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

Question 29

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

Question 30

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

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

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

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

};

template

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

c<<v._v;return c; }

int main()

{

Aa(10);

cout<<a<<endl;

return 0;

}

Options:

A.

program will display:10

B.

program will not compile

C.

program will compile

D.

program will run without output

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

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

merge(t1,t1+5,t2,t2+5,v1.begin());

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

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

Page: 7 / 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