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

Page 30 of 65

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:

int *tab;
B() { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;} B(string s) : A(s) { tab = new int[size]; for (int i=0; i<size; i++) tab[i]=1;} ~B() { delete tab; }
void Print() {
for (int i=0; i<size; i++) cout << tab[i];
cout << name;
}
};
int main () {
B b1("Alan");
B b2;
b1.tab[0]=0;
b1.Print(); b2.Print();
return 0;
}

  1. It prints: Alan
  2. It prints: 111
  3. It prints: 011Alan111Bob
  4. It prints: 0

Answer(s): C



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;
B *obj;
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}

  1. It prints: BB
  2. It prints: AA
  3. It prints: BC
  4. It prints: AB

Answer(s): C



What is the output of the program?

#include <iostream>
using namespace std;

class Base {
static int age;
public:
Base () {};
~Base () {};
void setAge(int a=10) {age = a;}
void Print() { cout << age;}
};

int Base::age=0;

int main () {
Base a,*b;
b = new Base();

  1. setAge();
    b?>setAge(20);
  2. Print();
    b?>Print();
    return 0;
    }
  3. It prints: 2020
  4. It prints: 1020
  5. It prints: 20
  6. It prints: 10

Answer(s): A



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 : private A {
string name;
public:
void set() {
x = 1;
}
void Print() {
cout << x;
}
};

int main () {
B b;

  1. set();
  2. Print();
    return 0;
    }
  3. It prints: 123
  4. It prints: 1
  5. It prints: ?123

  6. Compilation error

Answer(s): D



Page 30 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