Winter Sale Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: v4s65

Note! Following CPA Exam is Retired now. Please select the alternative replacement for your Exam Certification. The new exam code is CPA-21-02

CPA Exam Dumps - C++ Certified Associate Programmer

Question # 4

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

#include

using namespace std;

class First

{

public:

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

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

Full Access
Question # 5

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

#include

using namespace std;

class A

{

public:

virtual void Print()=0;

};

class B:public A

{

public:

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

};

int main()

{

B ob2;

A *obj;

obj = &ob2;

obj?>Print();

}

A.

It prints: B

B.

It prints: A

C.

It prints: AB

D.

It prints: BA

Full Access
Question # 6

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

#include

using namespace std;

class Base {

int age;

public:

class C {

int b;

void PrintC() { cout << b; }

};

Base () {age=5;};

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

void Print() { cout << age;}

};

int main () {

Base a;

a.setAge(10);

a.Print();

return 0;

}

A.

It prints: 1020

B.

It prints: 105

C.

It prints: 10

D.

It prints: 20

Full Access
Question # 7

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

}

A.

It prints: BB

B.

It prints: A

C.

It prints: AB

D.

Compilation error

Full Access
Question # 8

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

#include

using namespace std;

int compare(int, int);

int main()

{

int x = compare(10, 20);

cout << x;

return 0;

}

int compare(int i, int j)

{

return i

}

A.

It prints: 0

B.

It prints: 2

C.

It prints: 1

D.

It prints: 10

Full Access
Question # 9

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

#include

using namespace std;

class First

{

public:

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

};

class Second

{

public:

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

};

int main()

{

Second t[2];

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

t[i].Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Secondfrom Second

D.

It prints: from Second

Full Access
Question # 10

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;

}

A.

It prints: 10

B.

It prints: 2

C.

It prints: 5

D.

It prints: 1

Full Access
Question # 11

What will the variable "y" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

};

class B : protected A {

string name;

public:

void Print() {

cout << name << age;

}

};

A.

public

B.

private

C.

protected

D.

None of these

Full Access
Question # 12

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

#include

using namespace std;

int main()

{

int i = 0;

do {

i++;

if (i==3)

break;

cout<

}

while(i < 5);

return 0;

}

A.

It prints: 12

B.

It prints: 1

C.

It prints: 0

D.

No output

Full Access
Question # 13

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

#include

using namespace std;

void print(char *c);

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

{

print("Test");

return 0;

}

void print(char *c)

{

cout<

}

A.

It prints: Test

B.

It prints: T

C.

It prints: st

D.

None of these

Full Access
Question # 14

Which of the following is a correct way to define the function fun() in the program below?

#include

#include

#include

using namespace std;

int main()

{

int a[2][2];

fun(a);

return 0;

}

A.

void fun(int *p[2]) {}

B.

void fun(int *p[2][2]) {}

C.

void fun(int *p[][2]) {}

D.

void fun(int p[][2]) {}

Full Access
Question # 15

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

#include

#include

using namespace std;

class First

{

string *s;

public:

First() { s = new string("Text");}

~First() { delete s;}

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

};

int main()

{

First FirstObject;

FirstObject.Print();

FirstObject.~First();

}

A.

It prints: Text

B.

Compilation error

C.

Runtime error.

D.

None of these

Full Access
Question # 16

Which of the following can be checked in a switch?case statement?

A.

char

B.

int

C.

enum

D.

double

Full Access
Question # 17

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

#include

using namespace std;

int main()

{

int x=0;

int *ptr;

ptr = &x;

cout<

return 0;

}

A.

It prints: 0 0

B.

It prints address of ptr

C.

It prints: 1

D.

It prints: 2

Full Access
Question # 18

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;

}

A.

It prints: 5, 10

B.

It prints: 5.2, 10

C.

It prints: 5.20, 10.0

D.

It prints: 5.2, 10.00

Full Access
Question # 19

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

#include

using namespace std;

class First

{

public:

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

};

class Second

{

public:

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

};

int main()

{

First FirstObject;

FirstObject.Print();

Second SecondObject;

SecondObject.Print();

}

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

Full Access
Question # 20

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

#include

using namespace std;

#define DEF_A 0

#define DEF_B DEF_A+1

#define DEF_C DEF_B+1

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

cout << DEF_C;

return 0;

}

A.

It prints: 2

B.

It prints: 10

C.

It prints: 0

D.

It prints: 1

Full Access
Question # 21

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

Full Access
Question # 22

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 );

}

A.

It prints: Hoto

B.

It prints: Ho

C.

It prints: to

D.

It prints: Ht

Full Access
Question # 23

What is the output of the program?

#include

#include

using namespace std;

int main()

{

string s1="World";

string s2;

s2="Hello" + s1;

cout << s2;

return( 0 );

}

A.

It prints: HelloWorld

B.

It prints: Hello

C.

It prints: World

D.

Compilation error

Full Access
Question # 24

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);

}

A.

It prints: 10

B.

It prints: 20

C.

It prints: 5

D.

It prints: 0

Full Access
Question # 25

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

#include

using namespace std;

int s(int n);

int main()

{

int a;

a = 3;

cout << s(a);

return 0;

}

int s(int n)

{

if(n == 0) return 1;

return s(n?1)*n;

}

A.

It prints: 4

B.

It prints: 6

C.

It prints: 3

D.

It prints: 0

Full Access
Question # 26

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

#include

using namespace std;

int x=5;

static int y;

int i=0;

void static myFunction()

{

y=x++ + ++i;

}

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

{

x++;

myFunction();

cout<

}

A.

Compilation fails

B.

It prints: 5 5 0

C.

It prints: 7 7 1

D.

It prints: 6 5 1

Full Access
Question # 27

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(1,2);

c1.print();

return 0;

}

A.

It prints: 1 0

B.

It prints: 1 1

C.

It prints: 1 2

D.

Compilation error

Full Access
Question # 28

What will the variable "age" be in class B?

class A {

int x;

protected:

int y;

public:

int age;

};

class B : protected A {

string name;

public:

void Print() {

cout << name << age;

}

};

A.

public

B.

private

C.

protected

D.

None of these

Full Access
Question # 29

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

Full Access
Question # 30

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

Full Access
Question # 31

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

Full Access
Question # 32

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

#include

using namespace std;

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

char *s = "ABCDEF";

cout << s+2;

return 0;

}

A.

It prints: CDEF

B.

It prints: ABCDEF

C.

It prints: BCDEF

D.

None of these

Full Access
Question # 33

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

#include

#include

using namespace std;

class SampleClass

{

string *s;

public:

SampleClass() { s = new string("Text");}

SampleClass(string s) { this?>s = new string(s);}

~SampleClass() { delete s;}

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

};

int main()

{

SampleClass *obj;

obj = new SampleClass("Test");

obj?>Print();

}

A.

It prints: Text

B.

It prints: Test

C.

It prints: TextTest

D.

Garbage value.

Full Access