Summer Special 60% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: bestdeal

Free C++ Institute CPA-21-02 Practice Exam with Questions & Answers

Questions 1

What is the expected result of the following program?

CPA-21-02 Question 1

Options:
A.

It prints: ABCD

B.

It prints: ACBD

C.

It prints: ACDB

D.

It prints: CABD

Questions 2

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

#include <iostream>

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

Questions 3

Analyze the code below. If it contains an error, indicate its place in the program.

CPA-21-02 Question 3

Options:
A.

Error in the for loop

B.

Error in the break statement

C.

No error

D.

Error in the if statement

Questions 4

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

#include <iostream>

#include <string>

using namespace std;

class Base

{

string s;

public:

Base() { s="Sample text";}

Base(string s) { this?>s=s; }

void Print() { cout << s; }

};

int main()

{

Base *o = new Base();

o?>Print();

}

Options:
A.

It prints: Sample text

B.

It prints: Sample

C.

It prints: text

D.

None of these

Questions 5

The following declaration:

int i = 0b10;

Options:
A.

is invalid

B.

sets variable i with an integer value equal to 10

C.

sets variable i with an integer value equal to 2 (10 binary)

D.

sets variable i with an integer value equal to 8 (10 octal)

Questions 6

What is the output of the program?

#include <iostream>

using namespace std;

#define PRINT(i) cout<<i;

int main()

{

int y=2, z=3;

PRINT(y);

PRINT(z);

return 0;

}

Options:
A.

It prints: 123

B.

It prints: 23

C.

It prints: 3

D.

It prints: 2

Questions 7

What is the output of the program given below?

#include <iostream>

using namespace std;

int main (int argc, const char * argv[])

{

enum state { ok, error, warning};

enum state s1, s2, s3, s4;

s1 = ok;

s2 = warning;

s3 = error;

s4 = ok;

cout << s1<< s2<< s3<< s4;

return 0;

}

Options:
A.

1234

B.

compilation fails

C.

0210

D.

1322

Questions 8

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

#include <iostream>

#include <string>

using namespace std;

class A {

int x;

protected:

int y;

public:

int z;

};

class B : private A {

string name;

public:

void set() {

x = 1;

}

void Print() {

cout << x;

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:
A.

It prints: 123

B.

It prints: 1

C.

It prints: ?123

D.

Compilation error

Questions 9

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

#include <iostream>

using namespace std;

int main()

{

int i = 5;

do {

i??;

cout<<i;

}

while(i >= 0);

return 0;

}

Options:
A.

It prints: 43210?1

B.

It prints: ?1

C.

It prints: 4321

D.

It prints: 1

Questions 10

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

#include <iostream>

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