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

Page 29 of 65

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

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

Answer(s): C



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

#include <iostream>

using namespace std;

int main()
{
int i = 0;
do {
i++;
if (i==3)

break;
cout<<i;
}
while(i < 5);
return 0;
}

  1. It prints: 12
  2. It prints: 1
  3. It prints: 0
  4. No output

Answer(s): A



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

#include <iostream>

using namespace std;

int compare(int, int);

int main()
{
int x = compare(10, 20);
cout << x;
return 0;
}

int compare(int i, int j)
{
return i<j;

}

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

Answer(s): C



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

#include <iostream>

using namespace std;

int main()
{
int x,y=10;
float f;
f = 5.90;
cout << f << ", ";
x=f;
cout << x <<", ";
f=y;
cout << f;
return 0;
}

  1. It prints: 5, 5, 10.00
  2. It prints: 5.9, 5, 10
  3. It prints: 6, 5, 10
  4. It prints: 6, 5, 10.00

Answer(s): B



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