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

Free and Premium C++ Institute CPP Dumps Questions Answers

Page: 1 / 9
Total 228 questions

C++ Certified Professional Programmer Questions and Answers

Question 2

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

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

cout<<*min_element(v1.begin(), v1.end());

return 0;

}

Program outputs:

Options:

A.

3

B.

1

C.

6

D.

10

E.

compilation error

Question 3

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;

class B { int val;

public:

B(int v=0):val(v){}

int getV() const {return val;}

operator int() const { return val; };};

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

}

f.close();

return 0;

}

Options:

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

Question 4

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

B t2[]={5,6,8,2,1};

vector v1(10,0);

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

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.

5 2 1 0 0 0 0 0 0 0

E.

1 2 5 0 0 0 0 0 0 0

Question 5

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

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

list l2(t2, t2 + 5);

l1.sort();

list::iterator it = l2.begin();

it++; it++;

l1.splice(l1.end(),l2, it, l2.end());

print(l1.begin(), l1.end()); cout<<"Size:"<

print(l2.begin(), l2.end()); cout<<"Size:"<

return 0;

}

Options:

A.

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

B.

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

C.

compilation error

D.

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

E.

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

Question 6

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

#include

#include

#include

#include

#include

using namespace std;

int main() {

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

vector v(t, t + 10);

multimap m;

for (vector::iterator i = v.begin(); i != v.end(); i++) {

stringstream s;s << *i << *i;

m.insert(pair(*i, s.str()));

}

pair::iterator, multimap::iterator> range;

range = m.equal_range(2);

for (multimap::iterator i = range.first; i != range.second; i++) {

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

}

return 0;

}

The output will be:

Options:

A.

2 2

B.

1 2

C.

1 3

D.

2

E.

0 2

Question 7

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;

}

Options:

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

Question 8

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

int getV() 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);

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

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

return 0;

}

Program outputs:

Options:

A.

8 10 5 1 4 6 2 7 9 3

B.

4 5 6 7 8 9 10

C.

1 2 3 4 5 6 7 8 9 10

D.

compilation error

E.

1 2 3 4

Question 9

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

int main() {

vector v1(10);

vector v2(10);

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

reverse_copy(v1.begin(),v1.end(), v2.rbegin());

sort(v2.begin(), v2.end(), less_equal());

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

return 0;

}

Program outputs:

Options:

A.

1 2 3 4 5 6 7 8 9 10

B.

10 9 8 7 6 5 4 3 2 1

C.

no output

D.

compilation error

Question 10

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

Question 11

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

Question 12

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

int t2[]={5,6,8,2,1};

vector v1(10,0);

sort(t1, t1+5);

sort(t2, t2+5);

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

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

return 0;

}

Program outputs:

Options:

A.

3 2 4 1 5 6 8 2 1 0

B.

1 2 3 4 5 6 8 2 1 0

C.

1 1 2 2 3 4 5 5 6 8

D.

1 2 3 4 5 6 8 0 0 0

E.

compilation error

Question 13

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

#include

using namespace std;

void g(int a)

{

cout<<a?1<

}

template

void g(A a)

{

cout<<a+1<

}

int main()

{

int a = 1;

g(a);

return 0;

}

Options:

A.

program displays: 0

B.

program displays: 2

C.

compilation error

D.

runtime exception

Question 14

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

return 0;

}

Program outputs:

Options:

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

Question 15

What will happen when you attempt to compile and run the code below, assuming you enter the following sequence: 1 2 3?

#include

using namespace std;

int main ()

{

int a,b,c;

cin>>a>>b>>c;

cout<<a<

return 0;

}

Program will output:

Options:

A.

123

B.

1 2 3

C.

321

D.

compilation error

E.

the result is unspecified

Question 16

What will happen when you attempt to compile and run the code below, assuming that you enter the following sequence: 1 2 3 end?

#include

#include

#include

#include

using namespace std;

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) {out<

int main ()

{

list l;

for( ; !cin.bad() ; )

{

int i;

cin>>i;

l.push_back(i);

}

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

return 0;

}

Program will output:

Options:

A.

1 2 3

B.

1 2 3 end

C.

1

D.

compilation error

E.

program runs forever without output

Question 17

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

Question 18

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

#include

using namespace std;

class B {};

template

class A {

T_v;

public:

A() {}

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

T getV() { return _v; }

void add(T a) { _v+=a; }

};

int main()

{

A a(1);

Ab;

a.add(10);

cout << a.getV() <

return 0;

}

Options:

A.

program will display:11

B.

program will not compile

C.

program will compile

D.

program will cause runtime exception

Question 19

Which keywords can be used to define template type parameters? Choose all possible answers:

Options:

A.

class

B.

typedef

C.

typename

D.

static

E.

volatile

Question 20

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

#include

#include

using namespace std;

template

class A {

T_v;

public:

A() {}

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

T getV() { return _v; }

void add(T & a) { _v+=a; }

};

int main()

{

Aa("Hello");

string s(" world!");

a.add(s);

cout << a.getV() <

return 0;

}

Options:

A.

program will display: Hello world!

B.

program will not compile

C.

program will display: Hello

D.

program will run without any output

Question 21

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

};

struct Even {

bool operator ()(const A & a, const A &b) {

return (a.getA() % 2)==b.getA() % 2;

}

};

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

deque::iterator it = search_n(d.begin(), d.end(), 3, 2, Even());

cout<< it?d.begin()<

return 0;

}

Program outputs:

Options:

A.

compilation error

B.

12

C.

3

D.

1

E.

15

Question 22

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

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

set s1(t,t+10);

cout<<binary_search(s1.begin(),s1.end(), B(4))<<" "<

return 0;

}

Program outputs:

Options:

A.

1 0

B.

1 1

C.

0 0

D.

0 1

E.

compilation error

Question 23

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, 6 , 7, 8 , 9, 10};

vectorv1(t, t+10);

dequed1(t, t+10);

d1.empty();

v1.empty();

if (v1.isempty())

{

cout<<"I am empty ";

}

else

{

cout<<"I am not empty ";

}

cout<<v1.size()<<" "<

return 0;

}

Options:

A.

program outputs: I am empty 0 0

B.

program outputs: I am not empty 0 0

C.

compilation error

D.

program outputs: I am not empty 10 10

Question 24

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<<v1.back()?>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

Question 25

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

#include

#include

#include

using namespace std;

templateclass B { T val;

public:

B(T v):val(v){}

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

bool Less(const B &a, const B &b) { return int(a.getV())

int main() {

float t[]={2.28, 1.66, 1.32, 3.94, 3.64, 2.3, 2.98, 1.96, 2.62, 1.13};

vector > v1; v1.assign(t, t+10);

stable_sort(v1.begin(), v1.end(), Less);

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

return 0;

}

Program outputs:

Options:

A.

1.66 1.32 1.96 1.13 2.28 2.3 2.98 2.62 3.94 3.64

B.

1.13 1.32 1.66 1.96 2.28 2.3 2.62 2.98 3.64 3.94

C.

compilation error

D.

3.94 3.64 2.98 2.62 2.3 2.28 1.96 1.66 1.32 1.13

E.

the exact output is impossible to determine

Question 26

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

#include

#include

using namespace std;

int main ()

{

float f = 10.126;

cout.unsetf(ios::floatfield);

cout<<scientific<

return 0;

}

What will be a mantissa part of the numbers displayed:

Options:

A.

1.0126 1.013

B.

1.012600 10.013

C.

10.01260 10.013

D.

1.012600 1.013

E.

1.0126 1.01

Question 27

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

return 0;

}

Program outputs:

Options:

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

Question 28

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=0):val(v){}

int getV() const {return val;}

operator int () const { return val;} };

templatestruct Out {

ostream & out;

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

void operator() (const T & val ) { out<

struct Add {

B operator()(B & a, B & 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(Add(),1));

for_each(v2.rbegin(), v2.rend(), Out(cout));cout<<endl;

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

Question 29

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;

}

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

Question 30

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

#include

using namespace std;

int main ()

{

float f1 = 10.0;

float f2 = 10.123;

cout<<noshowpoint<

return 0;

}

Program outputs:

Options:

A.

10 10

B.

10.0 10.123

C.

compilation error

D.

10 10.123

Question 31

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

#include

#include

#include

using namespace std;

template

int calculate(T start, T end)

{

int s = 0;

while (start != end)

s+= *start; start++;return s;

}

int main ()

{

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

vectorv1(t, t+5);

dequed1(t+5, t+10);

cout<<calculate(t,t+10)<<" ";

cout<<calculate(v1.begin()+1,v1.end()?2)<<" ";

cout<<calculate(d1.rbegin()+1,d1.rend()?2)<<" ";

cout<<calculate(t[0],t[10])<<" ";

cout<<endl;

return 0;

}

Options:

A.

compilation error

B.

runtime exception

C.

program outputs 55 5 17 55

D.

program outputs 55 5 17 0

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[]={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<<endl;

return 0;

}

Program outputs:

Options:

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

Question 33

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

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

deque d1(t, t+10);

set s1(t, t+10);

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

cout<<includes(s1.begin(),s1.end(), t1,t1+4)<<" "<

<

return 0;

}

Program outputs:

Options:

A.

1 1

B.

1 0

C.

0 1

D.

0 0

Question 34

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

Page: 1 / 9
Total 228 questions