C++ Institute CPA-21-02 Exam Prep Guide: Prep guide for the CPA-21-02 Exam
2024 New Preparation Guide of C++ Institute CPA-21-02 Exam
NEW QUESTION # 77
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;
c1 = 3.0;
c1.print();
return 0;
}
- A. Compilation error
- B. It prints: 3 3
- C. It prints: 1 1
- D. It prints: 0 0
Answer: B
NEW QUESTION # 78
Which of the following statements are correct about an array?
int tab[10];
- A. The expression tab[1] designates the very first element in the array.
- B. The expression tab[9] designates the last element in the array.
- C. It is necessary to initialize the array at the time of declaration.
- D. The array can store 10 elements.
Answer: B,D
NEW QUESTION # 79
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int i = 4;
while(i >= 0) {
cout<<i;
i??;
}
return 0;
}
- A. It prints: "3210?1"
- B. It prints:"43210"
- C. None of these
- D. It prints:"3210"
Answer: B
NEW QUESTION # 80
Which of the following is a correct way to define the function fun() in the program below?
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
int main()
{
int a[2][2];
fun(a);
return 0;
}
- A. void fun(int *p[][2]) {}
- B. void fun(int *p[2]) {}
- C. void fun(int p[][2]) {}
- D. void fun(int *p[2][2]) {}
Answer: C
NEW QUESTION # 81
What happens when you attempt to compile and run the following code?
- A. It prints: 3
- B. It prints: 6
- C. It prints: 4
- D. It prints: 0
Answer: B
NEW QUESTION # 82
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int f(int a, int b);
int main()
{
float b;
b = f(20,10);
cout << b;
return 0;
}
int f(int a, int b)
{
return a/b;
}
- A. It prints: 2
- B. It prints: 10
- C. It prints: 0
- D. It prints: 5
Answer: A
NEW QUESTION # 83
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
int *a= new int;
*a=100;
cout << *a;
delete a;
}
- A. It prints: 10
- B. It prints: 0
- C. It prints: 100
- D. It prints: 1
Answer: C
NEW QUESTION # 84
What will the variable "age" be in class B?
class A {
int x;
protected:
int y;
public:
int age;
A () { age=5; };
};
class B : public A {
string name;
public:
B () { name="Bob"; };
void Print() {
cout << name << age;
}
};
- A. public
- B. private
- C. None of these
- D. protected
Answer: A
NEW QUESTION # 85
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
#define DEF_A 0
int main(int argc, char *argv[]) {
cout << DEF_A;
return 0;
}
- A. It prints: ?1
- B. Compilation error
- C. It prints: 0
- D. It prints: 1
Answer: C
NEW QUESTION # 86
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
int main()
{
const char *s;
char str[] = "Hello";
s = str;
while(*s) {
cout << *s++;
}
return 0;
}
- A. It prints: Hello
- B. It prints: H
- C. It prints: o
- D. It prints: el
Answer: A
NEW QUESTION # 87
What happens when you attempt to compile and run the following code?
#include <iostream>
using namespace std;
class A
{
public:
virtual void Print(){ cout<<"A";}
};
class B:public A
{
public:
void Print(){ cout<< "B";}
};
int main()
{
A *obj;
A ob1;
obj = &ob1;
obj?>Print();
B ob2;
obj = &ob2;
obj?>Print();
}
- A. It prints: AB
- B. It prints: AA
- C. It prints: BA
- D. It prints: BB
Answer: A
NEW QUESTION # 88
What is the output of the program?
#include <iostream>
using namespace std;
#define PRINT(i) cout<<i;
int main()
{
int y=2, z=3;
PRINT(y);
PRINT(z);
return 0;
}
- A. It prints: 23
- B. It prints: 3
- C. It prints: 2
- D. It prints: 123
Answer: A
NEW QUESTION # 89
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s1[]= {"H" , "t" };
string s;
for (int i=0; i<2; i++) {
s = s1[i];
if (i==0)
s.insert(1,"ow");
else
s.push_back('o');
cout << s;
}
return( 0 );
}
- A. It prints: Hoto
- B. It prints: Ht
- C. It prints: Howto
- D. It prints: toHo
Answer: C
NEW QUESTION # 90
What happens when you attempt to compile and run the following code?
#include <iostream>
#include <string>
using namespace std;
class A {
protected:
int y;
public:
int x;
int z;
A() { x=2; y=2; z=3; }
A(int a, int b) : x(a), y(b) { z = x ? y;}
void Print() {
cout << z;
}
};
int main () {
A a(2,5);
a.Print();
return 0;
}
- A. It prints: ?3
- B. It prints: 6
- C. It prints: 2
- D. It prints: 5
Answer: A
NEW QUESTION # 91
What happens when you attempt to compile and run the following code?
- A. It prints: Tesc failed
- B. It causes a compilation error
- C. .It prints: failed
- D. It prints: Tesc
Answer: D
NEW QUESTION # 92
What is the output of the program?
#include <iostream>
using namespace std;
class BaseC
{
int i;
public:
BaseC() { i=?1;}
BaseC(int i) { i=i; }
void seti(int a) { i = a; };
void Print() { cout << i; }
};
int main()
{
BaseC *o = new BaseC();
o?>seti(10);
o?>Print();
}
- A. It prints: ?1
- B. Compilation error
- C. It prints: 0
- D. It prints: 10
Answer: D
NEW QUESTION # 93
Which code, inserted at line 8, generates the output "0102020"?
#include <iostream>
using namespace std;
class Base {
static int age;
public:
Base () {};
~Base () {};
//insert code here
void Print() { cout << age;}
};
int Base::age=0;
int main () {
Base a,*b;
b = new Base();
a.Print();
a.setAge(10);
a.Print();
b?>setAge();
a.Print();
b?>Print();
return 0;
}
- A. void setAge() {age = 10;}
- B. void setAge(int a=20) {age = a;}
- C. void setAge() {age = 20;}
- D. void setAge(int a) {age = a;}
Answer: B
NEW QUESTION # 94
Which code lines inserted independently instead of the comment will make the following program work correctly? (Choose three.)
- A. void main ()
- B. int main
- C. int main (int argc, char *argv[])
- D. int main (int c, char *v[])
Answer: C,D
NEW QUESTION # 95
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 );
}
- A. It prints: World
- B. It prints: HelloWorld
- C. It prints: Hello
- D. It prints: WorldHello
Answer: B
NEW QUESTION # 96
What is the output of the program?
#include <iostream>
#include <string>
using namespace std;
int main()
{
char str[] = "Hello\0\World\0";
cout << str;
return 0;
}
- A. It prints: Hello
- B. It prints: World
- C. It prints: World\0World
- D. It prints: HW
Answer: A
NEW QUESTION # 97
......
Latest Questions CPA-21-02 Guide to Prepare Free Practice Tests: https://www.passcollection.com/CPA-21-02_real-exams.html
CPA-21-02 Practice Exam - 256 Unique Questions: https://drive.google.com/open?id=1Dy0Wn47AlbB_3OynULuBYzGaJzokp3P_

