[Feb 06, 2024] Latest Questions CPA-21-02 Guide to Prepare Free Practice Tests [Q126-Q142]

Share

[Feb 06, 2024] Latest Questions CPA-21-02 Guide to Prepare Free Practice Tests

Reliable CPA-21-02 Dumps Questions Available as Web-Based Practice Test Engine

NEW QUESTION # 126
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class Base
{
string s;
public:
Base() { s="Sample text";}
Base(string s) { this?>s=s; }
void Print() { cout << s; }
};
int main()
{
Base *o = new Base();
o?>Print();
}

  • A. None of these
  • B. It prints: Sample text
  • C. It prints: text
  • D. It prints: Sample

Answer: B


NEW QUESTION # 127
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;
}

  • A. It prints: 6, 5, 10.00
  • B. It prints: 6, 5, 10
  • C. It prints: 5.9, 5, 10
  • D. It prints: 5, 5, 10.00

Answer: C


NEW QUESTION # 128
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main (int argc, const char * argv[])
{
int a = 30, b = 1, c = 5, i=10;
i = b < a < c;
cout << i;
return 0;
}

  • A. It prints: 0
  • B. compilation fails
  • C. It prints: 10
  • D. It prints: 1

Answer: D


NEW QUESTION # 129
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
public:
A() { cout << "A no parameters";}
A(string s) { cout << "A string parameter";}
A(A &a) { cout << "A object A parameter";}
};
class B : public A {
public:
B() { cout << "B no parameters";}
B(string s) { cout << "B string parameter";}
B(int s) { cout << "B int parameter";}
};
int main () {
A a2("Test");
B b1(10);
B b2(b1);
return 0;
}

  • A. It prints: A no parametersA no parametersB string parameter
  • B. It prints: A no parametersB string parameter
  • C. It prints: A string parameterA no parametersB int parameterA object A parameter
  • D. It prints: A no parametersA no parameters

Answer: C


NEW QUESTION # 130
Which code, inserted at line 8, generates the output "100"?
#include <iostream>
using namespace std;
int fun(int);
int main()
{
int *x = new int;
*x=10;
//insert code here
return 0;
}
int fun(int i)
{
return i*i;
}

  • A. cout << fun(5) ;
  • B. cout << fun(y) ;
  • C. cout << fun(*x) ;
  • D. cout << fun(10);

Answer: C,D


NEW QUESTION # 131
What happens when you attempt to compile and run the following code?
#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 () {
namespace newname = myNamespace1;
using namespace newname;
cout << x << " ";
cout << y;
return 0;
}

  • A. It prints: 5 1.5
  • B. It prints: 3.14 1.5
  • C. It prints: 5
  • D. It prints: 5 10

Answer: D


NEW QUESTION # 132
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;
A *obj;
obj = &ob1;
obj?>Print();
obj = &ob2;
obj?>Print();
obj = &ob3;
obj?>Print();
}

  • A. It prints: ABB
  • B. It prints: AAA
  • C. It prints: BBB
  • D. It prints: ABC

Answer: B


NEW QUESTION # 133
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int op(int x, int y)
{
int i;
i = x + y;
return i;
}
int main()
{
int i=1, j=2, k, l;
k = op(i, j);
l = op(j, i);
cout<< k << "," << l;
return 0;
}

  • A. It prints: 1,1
  • B. It prints: 1,2
  • C. It prints: ?1,1
  • D. It prints: 3,3

Answer: D


NEW QUESTION # 134
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void set(struct person*);
struct person
{
char name[25];
int age;
};
int main()
{
struct person e = {"Steve", 30};
set(&e);
cout<< e.name << " " << e.age;
return 0;
}
void set(struct person *p)
{
p?>age = p?>age + 1;
}

  • A. Error: in structure
  • B. None of these
  • C. It prints: Steve 31
  • D. Error: in prototype declaration unknown struct person

Answer: C


NEW QUESTION # 135
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
void print(char *c);
int main (int argc, const char * argv[])
{
print("Test");
return 0;
}
void print(char *c)
{
cout<<c;
}

  • A. It prints: st
  • B. None of these
  • C. It prints: Test
  • D. It prints: T

Answer: C


NEW QUESTION # 136
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 {
public:
void set() {
y = 4; z = 2;
}
void Print() {
cout << y << z;
}
};
int main () {
B b;
b.set();
b.Print();
return 0;
}

  • A. It prints: 2
  • B. It prints: 42
  • C. It prints: 22
  • D. It prints: 44

Answer: B


NEW QUESTION # 137
What is the expected output of the following program?

  • A. It prints: 4321
  • B. It prints: 321
  • C. It prints: 3210
  • D. It prints: 432

Answer: B


NEW QUESTION # 138
What is the expected result of the following program?

  • A. The program enters an infinite loop
  • B. It prints: 42
  • C. It prints: 420
  • D. It prints: 4

Answer: B


NEW QUESTION # 139
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;
}
};

  • A. private
  • B. protected
  • C. public
  • D. None of these

Answer: B


NEW QUESTION # 140
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;
double i=2;
c1 = i;
c1.print();
return 0;
}

  • A. It prints: 2 2
  • B. It prints: 0 0
  • C. It prints: 2 0
  • D. It prints: 1 1

Answer: A


NEW QUESTION # 141
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;
}

  • A. It prints: ?1,3
  • B. Compilation fails
  • C. It prints: ?1,2
  • D. It prints: ?1,?1

Answer: C


NEW QUESTION # 142
......

Correct and Up-to-date C++ Institute CPA-21-02 BrainDumps: https://interfacett.braindumpquiz.com/CPA-21-02-exam-material.html