Summer Sale Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: ecus65

C++ Institute CPA-21-02 - CPA - C++ Certified Associate Programmer

Page: 6 / 8
Total 257 questions

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

#include

using namespace std;

int fun(int x) {

return 2*x;

}

int main(){

int i;

i = fun(0.5) || fun(0);

cout << i;

return 0;

}

A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

Compilation error

What is the output of the program?

#include

using namespace std;

class BaseC

{

int i;

public:

BaseC() { i=?1;}

BaseC(int i) { i=i; }

void seti(int a) { i = a; };

void Print() { cout << i; }

};

int main()

{

BaseC *o = new BaseC();

o?>seti(10);

o?>Print();

}

A.

It prints: 10

B.

It prints: ?1

C.

It prints: 0

D.

Compilation error

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

A.

It prints: 33

B.

It prints: –31

C.

It prints: –1–1

D.

It prints: –13

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

#include

#include

using namespace std;

class A {

protected:

int y;

public:

int x, z;

A() : x(1), y(2), z(0) {}

A(int a, int b) : x(a), y(b) { z = x * y;}

void Print() { cout << z; }

};

class B : public A {

public:

int y;

B() : A() {}

B(int a, int b) : A(a,b) {}

void Print() { cout << z; }

};

int main () {

A b(2,5);

b.Print();

return 0;

}

A.

It prints: 10

B.

It prints: 2

C.

It prints: 5

D.

It prints: 1

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

#include

using namespace std;

class First

{

public:

void Print(){ cout<<"from First";}

};

class Second

{

public:

void Print(){ cout<< "from Second";}

};

int main()

{

Second t[2];

for (int i=0; i<2; i++)

t[i].Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Secondfrom Second

D.

It prints: from Second

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

A.

It prints: 3

B.

It prints: 4

C.

It prints: 0

D.

It prints: 6

Which code line inserted instead of the comment below will cause the program to produce the expected output?

A.

ob2.A::print();

B.

ob2 –> A::print();

C.

ob2.B::print();

D.

ob2 –> B::print();

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

#include

#include

using namespace std;

class A {

public:

A() { cout << "A no parameters";}

A(string s) { cout << "A string parameter";}

A(A &a) { cout << "A object A parameter";}

};

class B : public A {

public:

B() { cout << "B no parameters";}

B(string s) { cout << "B string parameter";}

};

int main () {

A a1;

A a2("Test");

B b1("Alan");

return 0;

}

A.

It prints: A no parametersA string parameterA no parametersB string parameter

B.

It prints: A no parametersB string parameter

C.

It prints: B string parameter

D.

It prints: B no parameter

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

A.

It prints: 1

B.

lt prints: 2

C.

It prints: 111

D.

It prints: 121

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

#include

using namespace std;

class First

{

public:

void Print(){ cout<<"from First";}

};

class Second:public First

{

public:

void Print(){ cout<< "from Second";}

};

void fun(First *obj);

int main()

{

First FirstObject;

fun(&FirstObject);

Second SecondObject;

fun(&SecondObject);

}

void fun(First *obj)

{

obj?>Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second