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

CPA VCE Exam Download

Page: 8 / 8
Total 220 questions

C++ Certified Associate Programmer Questions and Answers

Question 29

What will the variable "y" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

};

class B : protected A {

string name;

public:

void Print() {

cout << name << age;

}

};

Options:

A.

public

B.

private

C.

protected

D.

None of these

Question 30

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

#include

using namespace std;

class A {

public :

void print() {

cout << "A ";

}

};

class B {

public :

void print() {

cout << "B ";

}

};

int main() {

B sc[2];

B *bc = (B*)sc;

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

(bc++)->print();

return 0;

}

Options:

A.

It prints: A A

B.

It prints: B B

C.

It prints: A B

D.

It prints: B A

Question 31

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

#include

using namespace std;

int main()

{

long int x,y=10;

double d;

d = 3.99;

x=(int) d;

cout << x <<", ";

d=float (y);

cout << d;

return 0;

}

Options:

A.

It prints: 3, 10

B.

It prints: 3.99, 10

C.

It prints: 4, 10.0

D.

It prints: 4, 10

Question 32

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

#include

#include

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

A() { x=1; y=2; z=3; }

};

class B : public A {

string z;

public:

void set() { y = 4; z = "John"; }

void Print() { cout << y << A::z; }

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:

A.

It prints: 4John

B.

It prints: 2John

C.

It prints: 23

D.

It prints: 43

Page: 8 / 8
Total 220 questions