C++ Institute CPA-21-02 CPA - C++ Certified Associate Programmer Exam Practice Test

Page: 1 / 14
Total 257 questions
Question 1

Which code, inserted at line 8, generates the output "100"?

#include

using namespace std;

int fun(int);

int main()

{

int *x = new int;

*x=10;

//insert code here

return 0;

}

int fun(int i)

{

return i*i;

}



Answer : A, B


Question 2

Which definitions are correct?



Answer : A, C


Question 3

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

#include

using namespace std;

int main()

{

int a=5;

cout << ((a < 5) ? 9.9 : 9);

}



Answer : A


Question 4

Which code, inserted at line 18, generates the output "AB"

#include

using namespace std;

class A

{

public:

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

void Print2(){ cout<< "a";}

};

class B:public A

{

public:

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

void Print2(){ cout<< "b";}

};

int main()

{

B ob2;

//insert code here

ob2.Print();

}



Answer : D


Question 5

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

#include

#include

using namespace std;

class A {

protected:

int y;

public:

int x, z;

A() : x(1), y(2), z(0) {}

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

void Print() { cout << z; }

};

class B : public A {

public:

int y;

B() : A() {}

B(int a, int b) : A(a,b) {}

void Print() { cout << z; }

};

int main () {

A b(2,5);

b.Print();

return 0;

}



Answer : A


Question 6

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;

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

};

class B : public A {

public:

void set() {

y = 4; z = 2;

}

void Print() {

cout << y << z;

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}



Answer : A


Question 7

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

#include

#include

using namespace std;

int f(int i);

int main()

{

int i=0;

i++;

for (i=0; i<=2; i++)

{

cout<

}

return 0;

}

int f(int a)

{

return a+a;

}



Answer : C


Page:    1 / 14   
Total 257 questions