Latest CPA-21-02 Dumps of DumpsBase: Pass CPA – C++ Certified Associate Programmer Exam Successfully

Are you preparing for the CPA – C++ Certified Associate Programmer certification exam? The CPA – C++ Certified Associate Programmer badge demonstrate the ability to accomplish coding tasks related to the basics of programming in the C++ language, and the fundamental notions and techniques used in object-oriented programming. When preparing, you can choose the latest CPA-21-02 dumps of DumpsBase. DumpsBase has just released the newest CPA-21-02 dumps with 222 practice questions and answers based on the actual exam skills and patterns. We have a team of experienced professionals who have designed these dumps of questions and answers after detailed research and analysis of the latest exam patterns. The latest CPA-21-02 dumps will help you to understand the exam format, the types of questions that can be asked, and the best ways to answer them. With the help of DumpsBase, you will be able to prepare for the CPA-21-02 exam in a more organized and effective way.

Read CPA – C++ Certified Associate Programmer CPA-21-02 Dumps Free Demo

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

class A {

int x;

protected:

int y;

public:

int age;

A () { age=5; };

};

class B : public A {

string name;

public:

B () { name="Bob"; };

void Print() {

cout << name << age;

}

};

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

#include <iostream>

#include <string>

using namespace std;

class complex{

double re, im;

public:

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

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,c2,c3;

c3 = c1 ? c2;

c3.Print();

}

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

#include <iostream>

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;

}

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

#include <iostream>

using namespace std;

void fun(int);

int main()

{

int a=0;

fun(a);

return 0;

}

void fun(int n)

{

if(n < 2)

{

fun(++n);

cout << n;

}

}

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

#include <iostream>

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;

}

6. What will be the output of the program?

#include <iostream>

using namespace std;

int fun(int);

int main()

{

cout << fun(5);

return 0;

}

int fun(int i)

{

return i*i;

}

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

#include <iostream>

using namespace std;

#define FUN(arg) if(arg) cout<<"Test";

int main()

{

int i=1;

FUN(i<3);

return 0;

}

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

class A {

int x;

protected:

int y;

public:

int age;

};

class B : private A {

string name;

public:

void Print() {

cout << name << age;

}

};

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

#include <iostream>

using namespace std;

int main()

{

float x=3.5,y=1.6;

int i,j=2;

i = x + j + y;

cout << i;

return 0;

}

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

#include <iostream>

using namespace std;

int main(){

int i = 1;

if (i==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

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

#include <iostream>

#include <string>

using namespace std;

class complex{

double re, im;

public:

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

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,c2,c3;

c3 = c1 + c2;

c3.Print();

}

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

#include <cstdlib>

#include <iostream>

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;

}

13. Which statement should be added in the following program to make work it correctly?

using namespace std;

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

{

cout<<"Hello";

}

14. What is the output of the program?

#include <iostream>

using namespace std;

int main()

{

int tab[4]={10,20,30,40};

tab[1]=10;

int *p;

p=&tab[0];

cout<<*p;

return 0;

}

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

#include <iostream>

using namespace std;

int fun(int x) {

return 2*x;

}

int main(){

int i;

i = fun(1) & fun(0);

cout << i;

return 0;

}

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

#include <iostream>

using namespace std;

class A {

public:

virtual void Print()=0;

};

class B:public A {

public:

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

};

class C:public A {

public:

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

};

int main()

{

B ob2;

C ob3;

A *obj;

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

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

class A {

int x;

protected:

int y;

public:

int age;

};

class B : private A {

string name;

public:

void Print() {

cout << name << age;

}

};

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

#include <iostream>

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<<y<<" "<<x<< " " << i;

}

19. Which of the structures is incorrect?

1:

struct s1{

int x;

long int li;

};

2:

struct s2{

float f;

struct s2 *s;

};

3:

struct s3{

float f;

struct s3 s;

};

20. What is the output of the program?

#include <iostream>

#include <string>

using namespace std;

int main()

{

string s1="Wo";

string s2;

s2 = s1;

string s3;

s3 = s2.append("rldHello");

cout << s3;

return( 0 );

}

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

#include <iostream>

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;

}

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

#include <iostream>

using namespace std;

int fun(int x) {

return x<<2;

}

int main(){

int i;

i = fun(1) / 2;

cout << i;

return 0;

}

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

#include <iostream>

#include <string>

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:

void set() {

y = 4;

z = "John";

}

void Print() {

cout << y << z;

}

};

int main () {

B b;

b.set();

b.Print();

return 0;

}

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

#include <iostream>

#include <string>

using namespace std;

const int size = 3;

class A {

public:

string name;

A() { name = "Bob";}

A(string s) { name = s;}

A(A &a) { name = a.name;}

};

class B : public A {

public:

B() { }

B(string s) : A(s) { }

void Print() {

cout << name;

}

};

int main () {

B b1("Alan");

b1.Print();

return 0;

}

25. What is the output of the program given below?

#include <iostream>

using namespace std;

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

{

int i=10;

{

int i=0;

cout<<i;

}

{

i=5;

cout << i;

}

cout<<i;

return 0;

}

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

#include <iostream>

using namespace std;

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

{

int x,y;

union t

{

char tab[2];

int i;

};

union t u;

u.tab[0] = 1;

u.tab[1] = 2;

u.i = 0;

x = u.tab[0];

y = u.tab[1];

cout << x << "," << y << "," << u.i;

return 0;

}

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

#include <iostream>

#include <string>

using namespace std;

class A {

protected:

int y;

public:

int x,z;

A() : x(1), y(2), z(0) { 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;

}

28. Which code, inserted at line 10, generates the output "Hello World"?

#include <iostream>

#include <string>

using namespace std;

string fun(string, string);

int main()

{

string s="Hello";

string *ps;

ps = &s;

//insert code here

return 0;

}

string fun(string s1, string s2)

{

return s1+s2;

}

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

#include <iostream>

using namespace std;

int x=5;

static int y=0;

void myFunction(int a)

{

y=++a;

}

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

{

int i=0;

myFunction(i);

cout<<y<<" "<<x;

}

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

#include <iostream>

using namespace std;

class A {

public:

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

};

class B:public A {

public:

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

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

#include <iostream>

#include <string>

using namespace std;

class A {

public:

int x;

};

class B : public A {

public:

B() { x=1;}

B(int x) {this?>x = x;}

};

int main () {

B c1;

B c2(10);

cout << c1.x;

cout << c2.x;

return 0;

}

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

#include <iostream>

using namespace std;

void fun(char*);

int main()

{

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

fun(&t[2]);

return 0;

}

void fun(char *a)

{

cout << *a;

}

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

#include <iostream>

#include <string>

using namespace std;

class A {

public:

A() { cout << "A no parameters";}

A(string s) { cout << "A string parameter";}

A(A &a) { cout << "A object A parameter";}

};

class B : public A {

public:

B() { cout << "B no parameters";}

B(string s) { cout << "B string parameter";}

};

int main () {

A a2("Test");

B b1("Alan");

B b2(b1);

return 0;

}

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

#include <iostream>

#include <string>

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<<s; }

};

int main()

{

A a("Hello world");

B b=a;

b.print();

}

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

#include <iostream>

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;

}

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

#include <iostream>

#include <string>

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

}

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

#include <iostream>

using namespace std;

class A

{

public:

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

}

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

#include <iostream>

#include <sstream>

#include <string>

using namespace std;

int main(void)

{

string s;

s = "Test";

s.resize (s.size() ? 1);

cout<<s<<" "<<s.size();

return 0;

}

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

#include <iostream>

using namespace std;

class A {

public:

int x;

A() { x=0;}

};

class B : public A {

public:

B() { x=1;}

};

class C : private B {

public:

C() { x=2;}

};

int main () {

C c1;

cout << c1.x;

return 0;

}

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

#include <iostream>

#include <string>

using namespace std;

class A {

public:

A() { cout << "A no parameters";}

A(string s) { cout << "A string parameter";}

A(A &a) { cout << "A object A parameter";}

};

class B : public A {

public:

B() { cout << "B no parameters";}

B(string s) { cout << "B string parameter";}

B(int s) { cout << "B int parameter";}

};

int main () {

A a2("Test");

B b1(10);

B b2(b1);

return 0;

}

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

#include <iostream>

using namespace std;

#include <iostream>

using namespace std;

class First

{

public:

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

};

int main()

{

First t[2];

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

t[i].Print();

}

42. What is the output of the program given below?

#include <iostream>

using namespace std;

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

{

int i=10;

{

int i=0;

cout<<i;

}

cout<<i;

return 0;

}

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

#include <iostream>

#include <string>

using namespace std;

class A {

public:

int x;

A() { x=0;}

A(int x) { this?>x=x;}

};

class B : private A {

public:

using A::x;

B() { x=1;}

B(int x) {this?>x = x;}

};

int main () {

B c1;

B c2(?5);

cout << c1.x;

cout << c2.x;

return 0;

}

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

#include <iostream>

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;

}

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

#include <iostream>

#include <string>

using namespace std;

class B;

class A {

int age;

public:

A () { age=5; };

friend class B;

};

class B {

string name;

public:

B () { name="Bob"; };

void Print(A ob) {

cout << name << ob.age;

}

};

int main () {

A a;

B b;

b.Print(a);

return 0;

}

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

#include <iostream>

using namespace std;

int main(){

int i = 1;

if (--i==1) {

cout << i;

} else {

cout << i-1;

}

return 0;

}

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

#include <iostream>

using namespace std;

void fun(int &i);

int main()

{

int i=2;

fun(i);

cout<<i;

return 0;

}

void fun(int &i)

{

i+=2;

}

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

#include <iostream>

using namespace std;

int fun(int x);

int main() {

cout << fun(0);

return 0;

}

int fun(int x) {

if(x > 0)

return fun(x-1);

else

return 100;

}

49. What is the output of the program if character 2 is supplied as input?

#include <iostream>

using namespace std;

int main () {

int c;

cin >> c;

try

{

switch (c)

{

case 1:

throw 20;

case 2:

throw 5.2f;

}

}

catch (int e)

{ cout << "int exception.Exception Nr." << e; }

catch (float e)

{ cout << "float exception.Exception Nr." << e; }

catch (...)

{ cout << "An exception occurred."; }

return 0;

}

50. What is the output of the program if character 4 is supplied as input?

#include <iostream>

using namespace std;

int main () {

int c;

cin >> c;

try

{

switch (c)

{

case 1:

throw 20;

case 2:

throw 5.2f;

case 3:

throw 'a';

default:

cout<<"No exception";

}

}

catch (int e)

{ cout << "int exception.Exception Nr." << e; }

catch (float e)

{ cout << "float exception.Exception Nr." << e; }

catch (...)

{ cout << "An exception occurred."; }

return 0;

}

51. Which code, inserted at line 14, generates the output "3.14 10"?

#include <iostream>

using namespace std;

namespace myNamespace1

{

int x = 5;

int y = 10;

}

namespace myNamespace2

{

float x = 3.14;

float y = 1.5;

}

int main () {

//insert code here

cout << x << " " << y;

return 0;

}

52. What is the output of the program?

#include <iostream>

#include <string>

using namespace std;

int main()

{

string s1[]= {"Hello" , "World" };

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

cout << s1[i];

}

return( 0 );

}

53. Which code, inserted at line 8, generates the output "0102020"?

#include <iostream>

using namespace std;

class Base {

static int age;

public:

Base () {};

~Base () {};

//insert code here

void Print() { cout << age;}

};

int Base::age=0;

int main () {

Base a,*b;

b = new Base();

a.Print();

a.setAge(10);

a.Print();

b?>setAge();

a.Print();

b?>Print();

return 0;

}

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

#include <iostream>

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

}

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

#include <iostream>

using namespace std;

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

char *s = "ABCDEF";

cout << s+2;

return 0;

}

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

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

#include <iostream>

#include <string>

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;

}

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

#include <iostream>

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

}

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

#include <iostream>

#include <string>

using namespace std;

class A {

protected:

int y;

public:

int x;

int z;

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

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

void Print() {

cout << z;

}

};

int main () {

A a(2,5);

a.Print();

return 0;

}

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

#include <iostream>

using namespace std;

void fun(int*);

int main()

{

int i=2;

fun(&i);

cout<<i;

return 0;

}

void fun(int *i)

{

*i = *i**i;

}

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

#include <iostream>

using namespace std;

int main()

{

int x=2, *y;

y = &x;

cout << *y + x;

return 0;

}

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

#include <iostream>

using namespace std;

int main(){

int *i;

i = new int;

*i = 1.0 / 2 * 2 / 1 * 2 / 4 * 4;

cout << *i;

return 0;

}

63. Which of the following statements are correct about an array?

int tab[10];

64. Which of the following is a logical operator?

65. How could you pass arguments to functions?

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

#include <iostream>

using namespace std;

int main(){

int i, j;

for(i = 0, j = 1; j < 2, i < 4; i++, j++);

cout << i << " " << j;

return 0;

}

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

#include <iostream>

#include <cstdarg>

using namespace std;

int mult(int f, int s, int t);

int main()

{

cout << mult(1,2,3);

return 0;

}

int mult(int f, int s, int t)

{

int mult_res;

mult_res = f*s*t;

return mult_res;

}

68. Which code, inserted at line 5, generates the output "ABC"?

#include <iostream>

using namespace std;

class A {

public:

//insert code here

};

class B:public A {

public:

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

};

class C:public B {

public:

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

};

int main()

{

A ob1;

B ob2;

C ob3;

A *obj;

obj = &ob1;

obj?>Print();

obj = &ob2;

obj?>Print();

obj = &ob3;

obj?>Print();

}

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

#include <iostream>

using namespace std;

class BaseClass

{

public:

int *ptr;

BaseClass(int i) { ptr = new int(i); }

~BaseClass() { delete ptr; delete ptr;}

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

};

void fun(BaseClass x);

int main()

{

BaseClass o(10);

fun(o);

o.Print();

}

void fun(BaseClass x) {

cout << "Hello:";

}

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

#include <iostream>

using namespace std;

int getValue();

int main()

{

const int x = getValue();

cout<<x;

return 0;

}

int getValue()

{

return 5;

}

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

#include <iostream>

#include <string>

using namespace std;

class A {

public:

A() { cout << "A0 ";}

A(string s) { cout << "A1";}

};

class B : public A {

public:

B() { cout << "B0 ";}

B(string s) { cout << "B1 ";}

};

class C : private B {

public:

C() { cout << "C0 ";}

C(string s) { cout << "C1 ";}

};

int main () {

B b1;

C c1;

return 0;

}

72. What is the output of the program?

#include <iostream>

#include <string>

using namespace std;

struct Person {

int age;

};

class First

{

Person *person;

public:

First() {person = new Person;

person?>age = 20;

}

void Print(){

cout << person?>age;

}

};

int main()

{

First t[2];

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

t[i].Print();

}

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

#include <cstdlib>

#include <iostream>

using namespace std;

inline float sum(float a,float b)

{

return a+b;

}

int main()

{

float a,b;

a = 1.5; b = 3.4;

cout<<sum(a,b);

return 0;

}

74. What is the output of the program?

#include <iostream>

#include <string>

using namespace std;

int main()

{

string s1="Hello";

string s2="World";

s1+=s2;

cout << s1;

return( 0 );

}

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

#include <iostream>

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;

}

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

#include <iostream>

using namespace std;

void set(struct person*);

struct person

{

int age;

};

int main()

{

struct person e = {18};

set(&e);

cout<< e.age;

return 0;

}

void set(struct person *p)

{

p?>age = p?>age + 1;

}

77. Point out an error in the program.

#include <iostream>

using namespace std;

int main()

{

const int x=1;

int const *y=&x;

cout<<*y;

return 0;

}

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

#include <iostream>

using namespace std;

int main()

{

int i=2;

switch(i)

{

case 1:

cout<<"Hello";

case 2:

cout<<"world";

case 3:

cout<<"End";

} return 0;

}

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

#include <iostream>

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;

}

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

#include <iostream>

#include <string>

using namespace std;

int f(int i, int b);

int main()

{

int i=0;

i++;

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

{

cout<<f(0,i);

}

return 0;

}

int f(int a, int b)

{

return a+b;

}


 

 

 

 

CPA – C++ Certified Associate Programmer CPA-21-02 Dumps (V9.02) - Valuable and Powerful CPA-21-02 Exam Preparation Materials

Add a Comment

Your email address will not be published. Required fields are marked *