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

Viewing page 3 out of 8 pages
Viewing questions 21-30 out of questions
Questions # 21:

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

Question # 21

Options:

A.

It prints: T


B.

It prints an empty line


C.

It prints: Tesc


D.

It prints: st


Expert Solution
Questions # 22:

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

#include

using namespace std;

int mul (int a, int b=2)

{

int r;

r=a*b;

return (r);

}

int main ()

{

cout << mul(1) << mul(2,4);

return 0;

}

Options:

A.

It prints: 2


B.

It prints: 28


C.

It prints: 8


D.

It prints: 6


Expert Solution
Questions # 23:

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

Question # 23

Options:

A.

It prints: 5.2110.0


B.

It prints: 5.210.0


C.

It prints: 52.10


D.

It prints: 5210


Expert Solution
Questions # 24:

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

#include

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

namespace newname = myNamespace1;

using namespace newname;

cout << x << " ";

cout << y;

return 0;

}

Options:

A.

It prints: 5 1.5


B.

It prints: 3.14 1.5


C.

It prints: 5 10


D.

It prints: 5


Expert Solution
Questions # 25:

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;

t.Print();

}

Options:

A.

It prints: 30


B.

It prints: John


C.

It prints: John 30


D.

It prints: John 30John 30


Expert Solution
Questions # 26:

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

Question # 26

Options:

A.

It prints: BAD


B.

It prints: BACD


C.

It prints: ABCD


D.

It prints: BAC


Expert Solution
Questions # 27:

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

#include

#include

using namespace std;

class A {

public:

int age;

A () { age=5; };

};

class B : private A {

string name;

public:

B () { name="Bob"; };

void Print() {

cout << name << age;

}

};

int main () {

B b,*ob;

ob = &b;

ob?>age = 10;

ob?>Print();

return 0;

}

Options:

A.

It prints: Bob55


B.

It prints: Bob1


C.

It prints: 10


D.

Compilation error


Expert Solution
Questions # 28:

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

#include

using namespace std;

int min(int a, int b);

int main()

{

int b=10;

b = min(5,20);

cout << b;

return 0;

}

int min(int a, int b)

{

if (a

return(a);

else

return(b);

}

Options:

A.

It prints: 10


B.

It prints: 20


C.

It prints: 5


D.

It prints: 0


Expert Solution
Questions # 29:

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;

}

Options:

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


Expert Solution
Questions # 30:

Which code, inserted at line 19, generates the output "23"?

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

int y;

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

void Print() {

//insert code here

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:

A.

cout << y << z;


B.

cout << y << A::z;


C.

cout << A::y << A::z;


D.

cout << B::y << B::z;


Expert Solution
Viewing page 3 out of 8 pages
Viewing questions 21-30 out of questions