Labour Day - Special Limited Time 65% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: dpm65

Note! The CPA Exam is no longer available. Get in touch with our Live Chat or email us for more information about the CPA-21-02 Exam.

CPA C++ Certified Associate Programmer Questions and Answers

Questions 4

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

}

Options:

A.

It prints: AB

B.

It prints: AA

C.

It prints: BA

D.

It prints: BB

Buy Now
Questions 5

What is the output of the program given below?

#include

using namespace std;

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

{

int i=10;

{

int i=0;

cout<

}

{

int i=5;

cout << i;

}

cout<

return 0;

}

Options:

A.

1010

B.

101010

C.

0510

D.

None of these

Buy Now
Questions 6

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

Options:

A.

char

B.

int

C.

enum

D.

double

Buy Now
Questions 7

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;

}

Options:

A.

It prints: 1 0

B.

It prints: 1 1

C.

It prints: 1 2

D.

Compilation error

Buy Now
Questions 8

Which of the following statements are correct about an array?

int tab[10];

Options:

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.

Buy Now
Questions 9

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;

}

Options:

A.

It prints: 0 0

B.

It prints: 1 1

C.

It prints: 3 3

D.

Compilation error

Buy Now
Questions 10

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

#include

#include

using namespace std;

class A {

public:

string s;

A(string s) { this?>s = s; }

};

class B {

public:

string s;

B (A a) { this?>s = a.s; }

void print() { cout<

};

int main()

{

A a("Hello world");

B b=a;

b.print();

}

Options:

A.

It prints: Hello world

B.

It prints: Hello

C.

Compilation error

D.

None of these

Buy Now
Questions 11

Which of the following statements are correct?

Options:

A.

A function can be defined inside another function

B.

A function may have any number of return statements each returning different values.

C.

A function can return floating point value

D.

In a function two return statements should never occur.

Buy Now
Questions 12

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;

}

Options:

A.

It prints: 123

B.

It prints: 000

C.

It prints: 23

D.

It prints: 12

Buy Now
Questions 13

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

#include

using namespace std;

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

{

int a = 30, b = 1, c = 5, i=10;

i = b < a < c;

cout << i;

return 0;

}

Options:

A.

compilation fails

B.

It prints: 10

C.

It prints: 0

D.

It prints: 1

Buy Now
Questions 14

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

}

Options:

A.

It prints: Text

B.

Compilation error

C.

Runtime error.

D.

None of these

Buy Now
Questions 15

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;

}

Options:

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

Buy Now
Questions 16

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;

}

Options:

A.

It prints: 4

B.

It prints: 6

C.

It prints: 3

D.

It prints: 0

Buy Now
Questions 17

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

#include

using namespace std;

int main()

{

const char *s;

char str[] = "Hello";

s = str;

while(*s) {

cout << *s++;

}

return 0;

}

Options:

A.

It prints: el

B.

It prints: Hello

C.

It prints: H

D.

It prints: o

Buy Now
Questions 18

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

}

Options:

A.

It prints: from First

B.

It prints: from Firstfrom First

C.

It prints: from Firstfrom Second

D.

It prints: from Secondfrom Second

Buy Now
Questions 19

Which code, inserted at line 10, generates the output "2?1"?

#include

#include

using namespace std;

class A {

protected:

int y;

public:

int z;

};

//insert code here

public:

void set() {

y = 2;

z = 3;

}

void Print() { cout << y << z; }

};

int main () {

B b;

b.set();

b.z = ?1;

b.Print();

return 0;

}

Options:

A.

class B : private A {

B.

class B : public A {

C.

class B : protected A {

D.

class B {

Buy Now
Questions 20

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

#include

using namespace std;

int op(int x, int y);

float op(int x, float y);

int main()

{

int i=1, j=2, k;

float f=0.3;

k = op(i, j);

cout<< k << "," << op(0, f);

return 0;

}

int op(int x, int y)

{

return x+y;

}

float op(int x, float y)

{

return x?y;

}

Options:

A.

It prints: 3,1

B.

It prints: 3,?0.3

C.

It prints: 3,0

D.

It prints: 0,0

Buy Now
Questions 21

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

#include

#include

using namespace std;

string fun(string, string);

int main()

{

string s="Hello";

cout << fun(s, " World");

return 0;

}

string fun(string s1, string s2)

{

return s1+s2;

}

Options:

A.

It will print: Hello World

B.

It will print: Hello

C.

It will print: World

D.

It will print: HW

Buy Now
Questions 22

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

#include

using namespace std;

int main()

{

int *t;

t = new int[2];

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

t[i] = i;

}

cout << t[1];

}

Options:

A.

It prints: 0

B.

It prints: 1

C.

It prints: 10

D.

It prints: ?1

Buy Now
Questions 23

What is the output of the program?

#include

#include

using namespace std;

union t

{

char c;

int i;

};

class First

{

union t u;

public:

First() {

u.c = 'A';

}

void Print(){

cout << u.c;

}

};

int main()

{

First *t = new First();

t?>Print();

}

Options:

A.

Garbage value

B.

It prints: A

C.

It prints: A 65

D.

Compilation error

Buy Now
Questions 24

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

#include

using namespace std;

int mul (int a, int b=2)

{

int r;

r=a*b;

return (r);

}

int main ()

{

cout << mul(1) << mul(2,4);

return 0;

}

Options:

A.

It prints: 2

B.

It prints: 28

C.

It prints: 8

D.

It prints: 6

Buy Now
Questions 25

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

#include

using namespace std;

int main() {

int i, j;

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

for(j = i; j < i + 1; j++)

if(j == i)

continue;

else

break;

}

cout << j;

return 0;

}

Options:

A.

It prints: 0

B.

It prints: 3

C.

It prints: 2

D.

It prints: 1

Buy Now
Questions 26

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

#include

#include

using namespace std;

class complex{

double re, im;

public:

complex() : re(1),im(0.3) {}

complex(double n) { re=n,im=n;};

complex(int m,int n) { re=m,im=n;}

complex operator+(complex &t);

void Print() { cout << re << " " << im; }

};

complex complex::operator+ (complex &t){

complex temp;

temp.re = this?>re + t.re;

temp.im = this?>im + t.im;

return temp;

}

int main(){

complex c1(1),c2(2),c3;

c3 = c1 + c2;

c3.Print();

}

Options:

A.

It prints: 1 1.5

B.

It prints: 2 1.5

C.

It prints: 3 3

D.

It prints: 0 0

Buy Now
Questions 27

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;

}

};

Options:

A.

public

B.

private

C.

protected

D.

None of these

Buy Now
Questions 28

Which of the following structures are correct?

1:

struct s1{

int x;

char c;

};

2:

struct s2{

float f;

struct s2 *s;

};

3:

struct s3{

float f;

in i;

}

Options:

A.

1

B.

2

C.

3

D.

All of these

Buy Now
Questions 29

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

#include

#include

using namespace std;

class complex{

double re;

double im;

public:

complex() : re(1),im(0.4) {}

bool operator==(complex &t);

};

bool complex::operator == (complex &t){

if((this?>re == t.re) && (this?>im == t.im))

return true;

else

return false;

}

int main(){

complex c1,c2;

if (c1==c2)

cout << "OK";

else {

cout << "ERROR";

}

}

Options:

A.

It prints: OK

B.

It prints: ERROR

C.

Compilation error

D.

Runtime error.

Buy Now
Questions 30

Which of the following operations is INCORRECT?

Options:

A.

int i=15;

B.

long int k=123

C.

float f=12,2;

D.

double d=12;

Buy Now
Questions 31

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

#include

using namespace std;

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

{

enum state { ok, error, warning};

enum state s1, s2, s3;

s1 = ok;

s2 = warning;

s3 = error;

s4 = ok;

cout << s1<< s2<< s3;

return 0;

}

Options:

A.

It will print:”123”

B.

compilation error

C.

It will print:”021”

D.

It will print:”132”

Buy Now
Questions 32

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

#include

#include

using namespace std;

int fun(int);

int main()

{

int *x = new int;

*x=10;

cout << fun(*x);

return 0;

}

int fun(int i)

{

return i*i;

}

Options:

A.

It will print: 100

B.

It will print: 101

C.

It will print: 10

D.

It will print: 1

Buy Now
Questions 33

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

#include

using namespace std;

void fun(char*);

int main()

{

char t[4]={'0', '1', '2', '3'};

fun(&t[0]);

return 0;

}

void fun(char *a)

{

cout << *a;

}

Options:

A.

It prints: 01

B.

It prints: 1

C.

It prints: 0

D.

It prints: 0123

Buy Now
Exam Code: CPA
Exam Name: C++ Certified Associate Programmer
Last Update: Dec 15, 2023
Questions: 220
dumpsmate guaranteed to pass
24/7 Customer Support

DumpsMate's team of experts is always available to respond your queries on exam preparation. Get professional answers on any topic of the certification syllabus. Our experts will thoroughly satisfy you.

Site Secure

mcafee secure

TESTED 24 Apr 2024