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 | Set: 4

Questions 31

If there is one, point out an error in the program

#include <iostream>

using namespace std;

int main()

{

int c = 'a';

switch(i)

{

case '2':

cout<<"OK";

case '1':

cout<<"Error";

default:

break;

}

return 0;

}

Options:
A.

No Error

B.

Use of undeclared identifier 'i'

C.

Illegal use of 'continue'

D.

Illegal use of 'break'

Questions 32

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

#include <iostream>

#include <string>

using namespace std;

class A {

protected:

int y;

public:

int x;

int z;

A() { x=1; y=2; z=3; }

A(int a, int b) : x(a), y(b) { z = x * y;}

void Print() {

cout << z;

}

};

int main () {

A a(2,5);

a.Print();

return 0;

}

Options:
A.

It prints: 10

B.

It prints: 2

C.

It prints: 6

D.

It prints: 5

Questions 33

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

#include <iostream>

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

Questions 34

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

#include <iostream>

using namespace std;

void fun(int*);

int main()

{

int *x;

int i=2;

x=&i;

fun(x);

cout<<i;

return 0;

}

void fun(int *i)

{

*i = *i * *i;

}

Options:
A.

It prints: 2

B.

It prints: 4

C.

It prints: 0

D.

It prints: 1

Questions 35

What is the output of the program?

#include <iostream>

using namespace std;

class BaseC

{

int i;

public:

BaseC() { i=?1;}

BaseC(int i) { i=i; }

void seti(int a) { i = a; };

void Print() { cout << i; }

};

int main()

{

BaseC *o = new BaseC();

o?>seti(10);

o?>Print();

}

Options:
A.

It prints: 10

B.

It prints: ?1

C.

It prints: 0

D.

Compilation error

Questions 36

What is not inherited from the base class?

Options:
A.

constructor

B.

destructor

C.

operator=()

D.

operator+()

Questions 37

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

CPA-21-02 Question 37

Options:
A.

It prints: AAABDD

B.

It pints: AABD

C.

It prints: AABDD

D.

It causes a compilation error

Questions 38

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

#include <iostream>

using namespace std;

int main()

{

long int x,y=10;

double d;

d = 3.99;

x=(int) d;

cout << x <<", ";

d=float (y);

cout << d;

return 0;

}

Options:
A.

It prints: 3, 10

B.

It prints: 3.99, 10

C.

It prints: 4, 10.0

D.

It prints: 4, 10

Questions 39

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

#include <iostream>

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

Questions 40

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