Pass the C++ Institute C++ Certified Professional Programmer CPA-21-02 Questions and answers with CertsForce

Viewing page 2 out of 8 pages
Viewing questions 11-20 out of questions
Questions # 11:

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

#include

using namespace std;

class First

{

public:

First() { cout << "Constructor";}

~First() { cout << "Destructor";}

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

};

int main()

{

First FirstObject;

FirstObject.Print();

}

Options:

A.

It prints: Constructorfrom First


B.

It prints: Constructorfrom FirstDestructor


C.

It prints: Constructorfrom FirstDestructorDestructor


D.

Compilation error at line 16


Expert Solution
Questions # 12:

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

#include

using namespace std;

int main()

{

const char *s;

char str[] = "Hello";

s = str;

while(*s) {

cout << *s++;

}

return 0;

}

Options:

A.

It prints: el


B.

It prints: Hello


C.

It prints: H


D.

It prints: o


Expert Solution
Questions # 13:

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

}

Options:

A.

It prints: from First


B.

It prints: from Firstfrom First


C.

It prints: from Firstfrom Second


D.

It prints: from Secondfrom Second


Expert Solution
Questions # 14:

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<name << " "<< person?>age;

}

};

int main()

{

First t[2];

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

t[i].Print();

}

Options:

A.

It prints: 30


B.

It prints: John


C.

It prints: John 31


D.

It prints: John 30John 30


Expert Solution
Questions # 15:

What is the output of the program?

#include

#include

using namespace std;

int main()

{

string s1[]= {"H" , "t" };

string s;

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

s = s1[i];

s.insert(1,"ow");

cout << s;

}

return( 0 );

}

Options:

A.

It prints: How


B.

It prints: Ht


C.

It prints: Hoto


D.

It prints: Howtow


Expert Solution
Questions # 16:

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;

}

Options:

A.

It prints: 0


B.

It prints: 1


C.

It prints: -1


D.

Compilation error


Expert Solution
Questions # 17:

What will be the output of the program?

#include

using namespace std;

int main()

{

int i=0;

for(; i<=5; i++)

cout << i;

return 0;

}

Options:

A.

012345


B.

0123


C.

5


D.

6


Expert Solution
Questions # 18:

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

#include

#include

using namespace std;

int fun(int);

int main()

{

int *x = new int;

*x=10;

cout << fun(*x);

return 0;

}

int fun(int i)

{

return i*i;

}

Options:

A.

It will print: 100


B.

It will print: 101


C.

It will print: 10


D.

It will print: 1


Expert Solution
Questions # 19:

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

#include

using namespace std;

class Base {

int age;

public:

class C {

int b;

void PrintC() { cout << b; }

};

Base () {age=5;};

void setAge(int a=20) {age = a;}

void Print() { cout << age;}

};

int main () {

Base a;

a.setAge(10);

a.Print();

return 0;

}

Options:

A.

It prints: 1020


B.

It prints: 105


C.

It prints: 10


D.

It prints: 20


Expert Solution
Questions # 20:

What will variable "y" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

};

class B : public A {

string name;

public:

void Print() {

cout << name << age;

}

};

Options:

A.

public


B.

private


C.

protected


D.

None of these


Expert Solution
Viewing page 2 out of 8 pages
Viewing questions 11-20 out of questions