Weekend Sale Limited Time 70% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: xmas50

C++ Institute CPA-21-02 - CPA - C++ Certified Associate Programmer

Page: 3 / 8
Total 257 questions

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

complex() : re(1),im(0.4) {}

complex operator+(complex &t);

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

};

complex complex::operator+ (complex &t){

complex temp;

temp.re = this?>re + t.re;

temp.im = this?>im + t.im;

return temp;

}

int main(){

complex c1,c2,c3;

c3 = c1 + c2;

c3.Print();

}

A.

It prints: 1 0.4

B.

It prints: 2 0.8

C.

It prints: 0 0

D.

Garbage value

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

{

using namespace myNamespace1;

cout << x << " ";

}{

using namespace myNamespace2;

cout << y;

}

return 0;

}

A.

It prints: 5 1.5

B.

It prints: 3.14 10

C.

Compilation error

D.

None of these

What will be the output of the program?

#include

using namespace std;

int fun(int);

int main()

{

cout << fun(5);

return 0;

}

int fun(int i)

{

return i*i;

}

A.

25

B.

5

C.

0

D.

1

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

#include

#include

using namespace std;

inline float sum(float a,float b)

{

return a+b;

}

int main()

{

float a,b;

a = 1.5; b = 3.4;

cout<

return 0;

}

A.

It prints: 0

B.

It prints: 4.9

C.

It prints: 5

D.

It prints: 4

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

#include

using namespace std;

class BaseClass

{

public:

int *ptr;

BaseClass(int i) { ptr = new int(i); }

~BaseClass() { delete ptr; delete ptr;}

void Print() { cout << *ptr; }

};

void fun(BaseClass x);

int main()

{

BaseClass o(10);

fun(o);

o.Print();

}

void fun(BaseClass x) {

cout << "Hello:";

}

A.

It prints: Hello:1

B.

It prints: Hello:

C.

It prints: 10

D.

Runtime error.

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

#include

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;

}

A.

It prints: 6

B.

It prints: 9

C.

Compilation error

D.

It prints: 33

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

#include

using namespace std;

int x=5;

static int y=0;

void myFunction(int a)

{

y=++a;

}

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

{

int i=0;

myFunction(i);

cout<

}

A.

It prints: 0 5

B.

It prints: 5 1

C.

It prints: 1 5

D.

It prints: 5 0

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

#include

using namespace std;

class A {

public:

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

};

class B:public A {

public:

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

A.

It prints: BBB

B.

It prints: AAA

C.

It prints: ABC

D.

It prints: ABB

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

#include

using namespace std;

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

{

int a = 30, b = 1, c = 5, i=10;

i = b < a < c;

cout << i;

return 0;

}

A.

compilation fails

B.

It prints: 10

C.

It prints: 0

D.

It prints: 1

Which code, inserted at line 14, generates the output "3.14 10"?

#include

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

//insert code here

cout << x << " " << y;

return 0;

}

A.

using myNamespace2::y; using myNamespace1::x;

B.

using namespace myNamespace1;

C.

using namespace myNamespace1; using namespace myNamespace2;

D.

using myNamespace1::y; using myNamespace2::x;