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

Questions 71

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

#include <iostream>

using namespace std;

class complex{

double re;

double im;

public:

complex() : re(0),im(0) {}

complex(double x) { re=x,im=x;};

complex(double x,double y) { re=x,im=y;}

void print() { cout << re << " " << im;}

};

int main(){

complex c1;

c1 = 3.0;

c1.print();

return 0;

}

Options:
A.

It prints: 0 0

B.

It prints: 1 1

C.

It prints: 3 3

D.

Compilation error

Questions 72

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

#include <iostream>

using namespace std;

int main () {

int c;

cin >> c;

try

{

switch (c)

{

case 1:

throw 20;

case 2:

throw 5.2f;

}

}

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. 20

C.

It prints: An exception occurred

D.

It prints: float exception. Exception Nr. 5.2

Questions 73

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 : public A {

string name;

public:

void set() {

y = 2;

z = 3;

}

void Print() { cout << y << z; }

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

Options:
A.

It prints: 123

B.

It prints: 000

C.

It prints: 23

D.

It prints: 12

Questions 74

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

#include <iostream>

using namespace std;

class Test {

float i,j;

};

class Add {

public:

int x,y;

Add (int a=3, int b=3) { x=a; y=b; }

int result() { return x+y;}

};

int main () {

Test test;

Add * padd;

padd = &test;

cout << padd?>result();

return 0;

}

Options:
A.

It prints: 6

B.

It prints: 9

C.

Compilation error

D.

It prints: 33

Questions 75

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

#include <iostream>

using namespace std;

int main()

{

int x=20;

int *ptr;

ptr = &x;

cout<<*ptr;

return 0;

}

Options:
A.

It prints: 20

B.

It prints: 0

C.

It prints address of ptr

D.

It prints: 2

Questions 76

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

#include <iostream>

using namespace std;

class A

{

public:

virtual void Print(){ cout<<"A";}

};

class B:public A

{

public:

void Print(){ cout<< "B";}

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

Options:
A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

Questions 77

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

#include <iostream>

#include <string>

using namespace std;

const int size = 3;

class A {

public:

string name;

A() { name = "Bob";}

A(string s) { name = s;}

A(A &a) { name = a.name;}

};

class B : public A {

public:

B() { }

B(string s) : A(s) { }

void Print() {

cout << name;

}

};

int main () {

B b1("Alan");

b1.Print();

return 0;

}

Options:
A.

It prints: 111Alan

B.

It prints: Bob

C.

It prints: Alan

D.

It prints: 0