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

C++ Certified Professional Programmer CPA Dumps PDF

Page: 6 / 8
Total 220 questions

C++ Certified Associate Programmer Questions and Answers

Question 21

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

#include

using namespace std;

class BaseC

{

public:

int *ptr;

BaseC() { ptr = new int(10);}

BaseC(int i) { ptr = new int(i); }

~BaseC() { delete ptr; }

};

void fun(BaseC x);

int main()

{

BaseC *o = new BaseC(5);

fun(*o);

}

void fun(BaseC x) {

cout << "Hello:"<<*x.ptr;

}

Options:

A.

It prints: Hello:50

B.

It prints: Hello:10

C.

It prints: Hello:5

D.

Compilation error

Question 22

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

#include

#include

using namespace std;

struct Person {

string name;

int age;

};

class First

{

Person *person;

public:

First() {person = new Person;

person?>name = "John";

person?>age = 30;

}

void Print(){

cout<<person?>name << " "<< person?>age;

}

};

int main()

{

First t;

t.Print();

}

Options:

A.

It prints: 30

B.

It prints: John

C.

It prints: John 30

D.

It prints: John 30John 30

Question 23

Which code, inserted at line 10, generate the output "50"?

#include

using namespace std;

class Base {

int age;

public:

Base () {

age=5;

};

//insert code here

void Print() { cout << age;}

};

void setAge(Base &ob) {ob.age = 0;}

int main () {

Base a;

a.Print();

setAge(a);

a.Print();

return 0;

}

Options:

A.

friend void setAge(Base ob);

B.

friend void setAge(Base *ob);

C.

friend void setAge(Base &ob);

D.

None of these

Question 24

What is the output of the program if character 3 is supplied as input?

#include

using namespace std;

int main () {

int c;

cin >> c;

try

{

switch (c)

{

case 1:

throw 20;

case 2:

throw 5.2f;

case 3:

throw 'a';

}

}

catch (int e)

{ cout << "int exception. Exception Nr. " << e; }

catch (float e)

{ cout << "float exception. Exception Nr. " << e; }

catch (...)

{ cout << "An exception occurred."; }

return 0;

}

Options:

A.

It prints: float exception. Exception Nr.

B.

It prints: int exception. Exception Nr.

C.

It prints: An exception occurred.

D.

It prints: float exception. Exception Nr.

Page: 6 / 8
Total 220 questions