Weekend Sale Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: bigdisc65

Helping Hand Questions for CPP

Page: 2 / 8
Question 8

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

}

};

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

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

for_each(v1.begin(), v1.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.

8 2 4 9 5 7 10 6 1 3

D.

compilation error

Question 9

What will be output of the program when you attempt to compile and run the following code?

#include

#include

#include

#include

using namespace std;

int main(){

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

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

multimap m;

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

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

}

m[0]="ten";

m.insert(pair(1,"eleven"));

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

cout<<i?>second<<" ";

}

return 0;

}

Options:

A.

zero one two three four five six seven eight nine

B.

ten one two three four five six seven eight nine

C.

zero eleven two three four five six seven eight nine

D.

ten eleven two three four five six seven eight nine

E.

compilation error

Question 10

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 11

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

Page: 2 / 8
Exam Code: CPP
Exam Name: C++ Certified Professional Programmer
Last Update: May 18, 2024
Questions: 228
CPP pdf

CPP PDF

$28  $80
CPP Engine

CPP Testing Engine

$33.25  $95
CPP PDF + Engine

CPP PDF + Testing Engine

$45.5  $130