Pass4itsure > C++ Institute > C++ Certified Professional Programmer > CPA > CPA Online Practice Questions and Answers

CPA Online Practice Questions and Answers

Questions 4

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.4) {}

complex operator?(complex andt);

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

};

complex complex::operator? (complex andt){

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

}

A. It prints: 1 0.4

B. It prints: 2 0.8

C. It prints: 0 0

D. It prints: 1 0.8

Buy Now
Questions 5

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

Buy Now
Questions 6

What is the output of the program?

#include

#include

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

}

A. It prints: 10

B. It prints: 2020

C. It prints: 22

D. It prints: 00

Buy Now
Questions 7

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

#include

using namespace std;

int main()

{

int i=2;

switch(i)

{

case 1:

cout<<"Hello";

case 2:

cout<<"world";

case 3:

cout<<"End";

} return 0;

}

A. It prints: Hello

B. It prints: world

C. It prints: worldEnd

D. It prints: End

Buy Now
Questions 8

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

A *bc = (A*)sc;

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

(bc++)->print();

return 0;

}

A. It prints: A A

B. It prints: B B

C. It prints: A B

D. It prints: B A

Buy Now
Questions 9

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

Buy Now
Questions 10

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]=0;

}

cout << t[1];

}

A. It prints: 0

B. It prints: 1

C. It prints: 2

D. It prints: 3

Buy Now
Questions 11

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

Buy Now
Questions 12

How many times will "HELLO" be printed?

#include

using namespace std;

int main()

{

for(int i=?1; i<=10; i++)

{

if(i < 5)

continue;

else

break;

cout<<"HELLO";

}

return 0;

}

A. 1

B. 2

C. 0

D. 20

Buy Now
Questions 13

Which definitions are correct?

A. int age;

B. int double;

C. char c;

D. int char;

Buy Now
Exam Code: CPA
Exam Name: C++ Certified Associate Programmer
Last Update: Apr 23, 2024
Questions: 220
10%OFF Coupon Code: SAVE10

PDF (Q&A)

$45.99

VCE

$49.99

PDF + VCE

$59.99