Free CPA-21-02 Exam Braindumps (page: 6)

Page 6 of 65

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

  1. It prints: 1 0
  2. It prints: 1 1
  3. It prints: 1 2
  4. Compilation error

Answer(s): C



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

  1. It prints: 0
  2. It prints: 1
  3. It prints: 2
  4. It prints: 4

Answer(s): C



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;

  1. set();
  2. Print();
    return 0;

    }
  3. It prints: 4John
  4. It prints: 2John
  5. It prints: 23
  6. It prints: 43

Answer(s): A



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

  1. It prints: 111Alan
  2. It prints: Bob
  3. It prints: Alan
  4. It prints: 0

Answer(s): C



Page 6 of 65



Post your Comments and Discuss C++ Institute CPA-21-02 exam with other Community members:

Subash commented on October 21, 2024
I am planning to take this exam. Are these 257 questions enough to clear it? Also, does each section have a passing percentage, or is it based on the overall ?
INDIA
upvote