Summer Sale Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: ecus65

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

Page: 1 / 8
Total 257 questions

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

#include

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;

double i=2;

c1 = i;

c1.print();

return 0;

}

A.

It prints: 0 0

B.

It prints: 1 1

C.

It prints: 2 0

D.

It prints: 2 2

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

#include

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;

}

A.

It prints: 0 0

B.

It prints: 1 1

C.

It prints: 3 3

D.

Compilation error

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

#include

using namespace std;

#define DEF_A 0

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

cout << DEF_A;

return 0;

}

A.

It prints: 1

B.

It prints: 0

C.

It prints: ?1

D.

Compilation error

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 a2("Test");

B b1("Alan");

B b2(b1);

return 0;

}

A.

It prints: A no parametersA no parametersB string parameter

B.

It prints: A string parameterA no parametersB string parameterA object A parameter

C.

It prints: A no parametersB string parameter

D.

It prints: A no parametersA no parameters

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:

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

};

int main()

{

A *obj;

A ob1;

obj = &ob1;

obj?>Print();

B ob2;

obj = &ob2;

obj?>Print();

}

A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

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

#include

using namespace std;

int main()

{

float x=3.5,y=1.6;

int i,j=2;

i = x + j + y;

cout << i;

return 0;

}

A.

It prints: 7

B.

It prints: 6

C.

It prints: 7,1

D.

Compilation error

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

#include

#include

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;

}

A.

It prints: 123

B.

It prints: 000

C.

It prints: 23

D.

It prints: 12

Which of the following statements are correct about an array?

int tab[10];

A.

The array can store 10 elements.

B.

The expression tab[1] designates the very first element in the array.

C.

The expression tab[9] designates the last element in the array.

D.

It is necessary to initialize the array at the time of declaration.

Which code, inserted at line 15, generates the output "5 Bob"?

#include

#include

using namespace std;

class B;

class A {

int age;

public:

A () { age=5; };

friend void Print(A &ob, B &so);

};

class B {

string name;

public:

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

//insert code here

};

void Print(A &ob, B &so) {

cout<

}

int main () {

A a;

B b;

Print(a,b);

return 0;

}

A.

friend void Print(A ob, B so);

B.

friend void Print(A &ob, B &so);

C.

friend void Print(A *ob, B *so);

D.

None of these

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

#include

using namespace std;

int op(int x, int y);

int main()

{

float *pf;

float f=0.9;

pf=&f;

cout << op(1, *pf);

return 0;

}

int op(int x, int y)

{

return x*y;

}

A.

It prints: 0

B.

It prints: 0.5

C.

It prints: 1

D.

It prints: ?1