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

CPA Premium Exam Questions

Page: 3 / 8
Total 220 questions

C++ Certified Associate Programmer Questions and Answers

Question 9

Which code, inserted at line 14, generates the output "3.14 10"?

#include

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

//insert code here

cout << x << " " << y;

return 0;

}

Options:

A.

using myNamespace2::y; using myNamespace1::x;

B.

using namespace myNamespace1;

C.

using namespace myNamespace1; using namespace myNamespace2;

D.

using myNamespace1::y; using myNamespace2::x;

Question 10

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

Question 11

Which code, inserted at line 10, generates the output "Hello World"?

#include

#include

using namespace std;

string fun(string, string);

int main()

{

string s="Hello";

string *ps;

ps = &s;

//insert code here

return 0;

}

string fun(string s1, string s2)

{

return s1+s2;

}

Options:

A.

cout << fun(" World");

B.

cout << fun(*ps);

C.

cout << fun("Hello");

D.

cout << fun("Hello", " World");

Question 12

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

class A {

int x;

protected:

int y;

public:

int age;

};

class B : private A {

string name;

public:

void Print() {

cout << name << age;

}

};

Options:

A.

public

B.

private

C.

protected

D.

None of these

Page: 3 / 8
Total 220 questions