IT-Prüfungen Exam CPP Schulungsunterlagen

IT-Prüfungen Exam CPP  Schulungsunterlagen www.it-pruefungen.ch C++ Certified Professional Programmer

QUESTION NO: 1

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

#include

#include

#include

using namespace std;

int main(){int t[] ={ 3, 4, 2, 1, 6, 5, 7, 9, 8, 0 };

vectorv(t, t+10);

multisets1(v.begin(),v.end());

s1.insert(v.begin(),v.end());

pair<multiset::iterator,multiset::iterator> range;

range = s1.equal_range(6);

while (range.first != range.second) {cout<<*range.first<<” “; range.first++;}return 0;}

A. program outputs: 6 6
B. program outputs: 5 7
C. program outputs: 5 5 6 6 7 7
D. program outputs: 5 5 7 7
E. program outputs: 1 1 6 6 5 5

Answer: A

QUESTION NO: 2

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() {vectorv1(10);

generate(v1.rbegin(), v1.rend(), Sequence(1));

rotate(v1.begin(),v1.begin() + 1, v1.end() );

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

return 0;}

Program outputs:

A. 1 2 3 4 5 6 7 8 9 10
B. 10 9 8 7 6 5 4 3 2 1
C. 9 8 7 6 5 4 3 2 1 10
D. 1 10 9 8 7 6 5 4 3 2

Answer: C

QUESTION NO: 3

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

#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<<setw(3)<<hex<

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

B i;

f>>i;

cout<<i<<” “;

}

f.close();

return 0;}

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. compilation error
E. program will display sequence 1 2 3 4 5 6 7 8 9 10

Answer: D

CPP Prüfungsfragen, CPP Examensfragen C++ Certified Professional Programmer (ICND2 v3.0) www.it-pruefungen.ch

QUESTION NO: 4

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

cout<<a<<endl;

return 0;}

Program will output:

A. one
B. one two three
C. runtime exception
D. compilation error
E. the result is unspecified

Answer: A

QUESTION NO: 5

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

vectorv(t, t + 10);

multimapm;

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

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

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

}

pair<multimap::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:

A. 2 2
B. 1 2
C. 1 3
D. 2
E. 0 2

Answer: A

Prüfungsvorbereitung Studienmaterial CPP deutsch C++ Certified Professional Programmer www.it-pruefungen.ch

QUESTION NO: 6

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 <

templatestruct Out {

ostream & out;

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

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

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:

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

Answer: D

Prüfungsvorbereitung Exam CPA Studienmaterialien

Prüfungsvorbereitung Exam CPA Studienmaterialien C++ Certified Associate Programmer www.it-pruefungen.ch

QUESTION NO: 1
What will the variable “age” be in class B?
class A {
int x;
protected:
int y;
public:
int age;
A () { age=5; };
};
class B : public A {
string name;
public:
B () { name=”Bob”; };
void Print() {
cout << name << age;
}
};

A. public
B. private
C. protected
D. None of these

Answer: A

QUESTION NO: 2
What happens when you attempt to compile and run the following code?
#include
#include
using namespace std;
class complex{
double re, im;
public:
complex() : re(1),im(0.4) {}
complex operator?(complex &t);
void Print() { cout << re << ” ” << im; } }; complex complex::operator? (complex &t){ complex temp; temp.re = this?>re ? t.re;
temp.im = this?>im ? t.im;
return temp;
}
int main(){
complex c1,c2,c3;
c3 = c1 ? c2;
c3.Print();
}

A. It prints: 1 0.4
B. It prints: 2 0.8
C. It prints: 0 0
D. It prints: 1 0.8

Answer: C

IT-Prüfungen CPA C++ Certified Associate Programmer www.it-pruefungen.ch

QUESTION NO: 3
What happens when you attempt to compile and run the following code?
#include
using namespace std;
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double x) { re=x,im=x;};
complex(double x,double y) { re=x,im=y;}
void print() { cout << re << ” ” << im;}
};
int main(){
complex c1;
c1 = 3.0;
c1.print();
return 0;
}

A. It prints: 0 0
B. It prints: 1 1
C. It prints: 3 3
D. Compilation error

Answer: C

QUESTION NO: 4
What happens when you attempt to compile and run the following code?
#include
using namespace std;
void fun(int);
int main()
{
int a=0;
fun(a);
return 0;
}
void fun(int n)
{
if(n < 2)
{
fun(++n);
cout << n;
}
}

A. It prints: 21
B. It prints: 012
C. It prints: 0
D. None of these

Answer: A

CPA Prüfungsfragen, CPA Examensfragen C++ Certified Associate Programmer (ICND2 v3.0) www.it-pruefungen.ch

QUESTION NO: 5
What happens when you attempt to compile and run the following code?
#include
using namespace std;
int s(int n);
int main()
{
int a;
a = 3;
cout << s(a);
return 0;
}
int s(int n)
{
if(n == 0) return 1;
return s(n?1)*n;
}

A. It prints: 4
B. It prints: 6
C. It prints: 3
D. It prints: 0

Answer: B