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

Page: 1 / 14
Total 220 questions
Question 1

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 :

void print() {

cout << "B ";

}

};

int main() {

B sc[2];

B *bc = (B*)sc;

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

(bc++)->print();

return 0;

}



Answer : B


Question 2

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

#include

using namespace std;

class A {

public:

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

};

class C:public A {

public:

virtual void Print()=0;

};

int main()

{

C obj3;

obj3?>Print();

}



Answer : D


Question 3

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 4

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


Question 5

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

#include

#include

using namespace std;

int main()

{

string s1[]= {"H" , "t" };

string s;

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

s = s1[i];

s.insert(1,"o");

cout << s;

}

return( 0 );

}



Answer : A


Question 6

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

#include

using namespace std;

int min(int a, int b);

int main()

{

int b=10;

b = min(5,20);

cout << b;

return 0;

}

int min(int a, int b)

{

if (a

return(a);

else

return(b);

}



Answer : C


Question 7

Which code, inserted at line 19, generates the output "23"?

#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 {

string z;

public:

int y;

void set() { y = 4; z = "John"; }

void Print() {

//insert code here

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}



Answer : C


Page:    1 / 14   
Total 220 questions