Summer Special 60% Discount Offer - Ends in 0d 00h 00m 00s - Coupon code: bestdeal

Free C++ Institute CPA-21-02 Practice Exam with Questions & Answers | Set: 7

Questions 61

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;

}

Options:
A.

cout << fun(" World");

B.

cout << fun(*ps);

C.

cout << fun("Hello");

D.

cout << fun("Hello", " World");

Questions 62

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

#include <iostream>

using namespace std;

int op(int x, int y)

{

return x?y;

}

int op(int x, float y)

{

return x+y;

}

int main()

{

int i=1, j=2, k, l;

float f=0.23;

k = op(i, j);

l = op(j, f);

cout<< k << "," << l;

return 0;

}

Options:
A.

It prints: ?1,?1

B.

It prints: ?1,3

C.

It prints: ?1,2

D.

Compilation fails

Questions 63

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;

}

Options:
A.

It prints: 0

B.

It prints: 1

C.

It prints: -1

D.

It prints: 2

Questions 64

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;

}

Options:
A.

using myNamespace2::y; using myNamespace1::x;

B.

using namespace myNamespace1;

C.

using namespace myNamespace1; using namespace myNamespace2;

D.

using myNamespace1::y; using myNamespace2::x;

Questions 65

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;

}

Options:
A.

1010

B.

100

C.

010

D.

None of these

Questions 66

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

}

Options:
A.

It prints: 1 0.4

B.

It prints: 2 0.8

C.

It prints: 0 0

D.

It prints: 1 0.8

Questions 67

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

}

Options:
A.

It prints: HelloWorld

B.

It prints: Hello

C.

It prints: WorldHello

D.

It prints: World

Questions 68

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;

}

Options:
A.

It prints: 5

B.

It prints: 1?5

C.

It prints: 05

D.

It prints: 0

Questions 69

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;

}

};

Options:
A.

public

B.

private

C.

protected

D.

None of these

Questions 70

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

class A {

int x;

protected:

int y;

public:

int age;

};

class B : protected A {

string name;

public:

void Print() {

cout << name << age;

}

};

Options:
A.

public

B.

private

C.

protected

D.

None of these