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

Page: 1 / 14
Total 257 questions
Question 1

What is the output of the program?

#include

using namespace std;

class Base {

static int age;

public:

Base () {};

~Base () {};

void setAge(int a=10) {age = a;}

void Print() { cout << age;}

};

int Base::age=0;

int main () {

Base a,*b;

b = new Base();

a.setAge();

b?>setAge(20);

a.Print();

b?>Print();

return 0;

}



Answer : A


Question 2

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

#include

using namespace std;

int main()

{

int x,y=10;

float f;

f = 5.20;

x=(int) f;

cout << x <<", ";

f=float (y);

cout << f;

return 0;

}



Answer : A


Question 3

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

#include

#include

using namespace std;

float* sum(float a,float b);

float* sum(float a,float b)

{

float *f = new float;

*f = a+b;

return f;

}

int main()

{

float a,b,*f;

a = 1.5; b = 3.4;

f = sum(a,b);

cout<<*f;

return 0;

}



Answer : B


Question 4

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(2), y(2), z(1) { z = x + y; }

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;

b.Print();

return 0;

}



Answer : A


Question 5

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

#include

using namespace std;

int fun(int x) {

return 2*x;

}

int main(){

int i;

i = fun(0.5) || fun(0);

cout << i;

return 0;

}



Answer : A


Question 6

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

#include

using namespace std;

class First

{

public:

virtual void Print(){ cout<<"from First";}

};

class Second:public First

{

public:

void Print(){ cout<< "from Second";}

};

void fun(First *obj);

int main()

{

First FirstObject;

fun(&FirstObject);

Second SecondObject;

fun(&SecondObject);

}

void fun(First *obj)

{

obj?>Print();

}



Answer : C


Question 7

How many times will the program print "HELLO" ?

#include

using namespace std;

int main()

{

cout<<"HELLO";

main();

return 0;

}



Answer : D


Page:    1 / 14   
Total 257 questions