Professional Documents
Culture Documents
constructor?
A. Car *lexus = new (Car);
B. Car* lexus = new Car();
C. Car *lexus = new Car;
D. (Car*) lexus = new Car(); khai báo sai
E. None of the above
Given the following code, what is the output:
#include<iostream>
using namespace std;
void show(char = '*', int = 1);
int main(){
show('$', 2);
return 0;
}
void show(char c, int n){
for(int i = 1; i <= n; ++i){
cout << c;
}
cout << endl;
}
A. *
B. **
C. $
D. $$
E. Compilation Error
After run this code, the output should be:
class CBase{
public:
virtual void show(){
cout << "\n Base class - function show() is called";
}
void display(){
cout << "\n Base class - function display() is called";
}
};
int main()
{
CBase obj1;
CDelivered obj2;
CBase* p;
p = &obj1;
obj1.display();
obj1.show();
p = &obj2;
p->display();
p->show();
return 0;
}
int main(){
int* pp = new int;
int a = 100;
pp = &a;
CBase obj1(pp);
CBase obj2 = obj1;
return 0;
}
A. 100 100
B. 100 101
C. 101 101
D. 101 100
E. None of the above
Which of the following is not OOPS concept in C++?
A. Object
B. Encapsulation
C. Polymorphism
D. Inheritance
E. None of the above
class Person {
void say() {
cout << “Hello”;
}
}
A. Hello
B. Student Hello
C. Hello
Student Hello
D. Student Hello
Hello
E. None of the above
Given the following code, what is the result:
A. Hello
B. Hello
Fresher Academy
C. Hello
Fresher Academy
Fresher Academy
D. Hello
Fresher Academy
Fresher Academy
Fresher Academy
E. Compilation error
Given the following code, what is the result:
int iAr[] = { 1, 3, 5, 7, 9 };
for (int x : iAr) {
for (int j = 0; j < 3; j++) {
if (x > 4 && x < 8)
continue;
cout<< " " << x;
if (j == 1)
break;
}
}
A. 139
B. 5577
C. 13399
D. 113399
E. Compilation fails
Given the following code, what is the result:
int x = 2019;
do {
while (x > 20) {
x -= 2000;
}
} while (x > 2019 + 1);
cout << x;
A. 19
B. 20
C. 2019
D. -1969
E. 2039
Given the following code, what is the result:
A. small
B. tiny
C. huge
D. 20
E. 22
Which of the following is the correct output of the code snippet given below?
int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int n = 6;
n = arr[arr[n] / 2];
cout << arr[n] % 2;
A. 3
B. 0
C. 6
D. 1
E. 2
Which of the following is the correct output of the code snippet given below?
A. Compilation Error
B. 0 1 2 3 4 5 6 7 8 9
C. 1 3 5 7 9
D. 2 4 6 8
E. 0 2 4 6 8
What is the output of the following code?
#include<iostream>
using namespace std;
class Access {
public:
int x;
int y;
void cal(int a, int b) {
x = a + 1;
y = b;
}
};
int main(){
Access* obj = new Access();
obj->cal(2, 3);
cout << obj->x++ << " " << obj->y;
return 0;
}
A. 3 3
B. 2 3
C. 4 3
D. Runtime error
E. Compilation error
What is the output of the following code?
#include<iostream>
using namespace std;
class Access {
public:
static int x;
Access(){
x += 1;
}
};
int Access::x = 0;
int main(){
new Access();
Access *aa = new Access();
cout << Access::x;
return 0;
}
A. count=0
B. count=1
C. count=2
D. count=3
E. None of the above
What is wrong in this segment code?
class CBase {
public:
int* num = nullptr;
CBase(int *x) {
num = x;
}
CBase(const CBase &obj) {
num = new int();
*num = *obj.num;
}
};
A. 69 96
B. 69 69
C. 96 96
D. 96 69
E. None of the above
What is result of this segment code?
int main() {
week day;
day = Thursday;
cout << "Day: " << day + 1 << endl;
return 0;
}
A. Day: 2
B. Day: 3
C. Day: 4
D. Day: 5
E. Compile error
What is the output of the following segment code?
int gvalue = 0;
void changeSomeValue(int gvalue, int lvalue){
lvalue++;
gvalue++;
}
int main(){
int lvalue = 1;
cout << lvalue << " " << gvalue;
return 0;
}
A. 0 1
B. 1 2
C. 0 2
D. 1 1
E. None of the above 1 0
What is the result of this code below:
#include<iostream>
using namespace std;
class CBase
{
public:
CBase(){}
~CBase(){
cout << "Base class - destructor is called\n";
}
};
int main(){
CBase* obj1 = new CBase();
CBase* obj2 = new CDelivered();
CDelivered* obj3 = new CDelivered();
delete obj3;
delete obj2;
delete obj1;
return 0;
}
A. Delivered class - destructor is called
Base class - destructor is called
Base class - destructor is called
B. Base class - destructor is called
Base class - destructor is called
Base class - destructor is called
Delivered class - destructor is called
C. Delivered class - destructor is called
Delivered class - destructor is called
Base class - destructor is called
Base class - destructor is called
D. Delivered class - destructor is called
Base class - destructor is called
Base class - destructor is called
Base class - destructor is called
E. Delivered class - destructor is called
Delivered class - destructor is called
Base class - destructor is called
What is the size of the struct below?
struct Strt {
int a;
float b;
double c;
char ch[69];
};
A. 69
B. 88
C. 32
D. 85
E. 64
After run this code below, result is:
int main() {
float sum = 0.0, average = 0.0;
int num = 0;
float arr[] = { 5, 2, 1, 4, 5, 0, 7 };
for (int i = 1; i < 7; ++i){
if (arr[i] < 1.9){
goto jump;
}
sum += arr[++i];
num++;
}
jump:
average = sum / num;
cout << "\nAverage = " << average;
return 0;
}
A. 3
B. 3.5
C. 4
D. 4.5
E. 2
Which are not storage class in C++? (multiple choice)
A. static
B. unsigned
C. register
D. extend
E. mutable
Give a segment code below, choose the right answer:
#include<iostream>
using namespace std;
class cls {
void f(int a, int b) { stt = a + b; };
static int stt;
double dx(double x) { return x * x; };
char ch[11];
};
int main() {
int a[3] = { 5, 6 };
cout << sizeof(cls) + sizeof(a) << endl;
return 0;
}
A.23
B.31
C.32
D.35
E.Compile error
What is the output of the following program?
#include<iostream>
using namespace std;
int main() {
int i = 3, j = 4, k = 5, result;
result = (i, j, k);
cout << result << endl;
return 0;
}
A. 12
B. 5
C. 4
D. 3
E. None of the above
Logic & GMAT
Kevin, Joseph, and Nicholas are 3 brothers. If the following statements are all true, which of
them is the youngest?
A. Kevin
B. Joseph
C. Nicholas
D. None of them
A. Alex
B. Brian
C. Charlie
D. Daniel
E. Edward
A. Option A
B. Option B
C. Both Option A and Option B yield the same price
The mass of a full jar of honey is 600 grams.
With half of the honey, the total mass is 350 grams.
A. 100
B. 150
C. 200
D. 250
E. 300
What is the smallest integer greater than 2 that when divided by 5 gives a remainder of 1?
A. 2
B. 4
C. 6
D. 8
E. 11
Step 1. Swap places with the 1st and 4th items on the list.
Step 2. Swap places with the 1st and 2nd items on the list.
Step 3. End.
A. CDEBAFG
B. CDEFABG
C. CDEFBAG
D. CDEFGBA
E. None of the above
There is a stack of numbers: 4, 13, 65, 3, 8.
Do the following action in sequence: push(5), pop(), pop(), pop().
What value return in the last pop aciton?
A. 5
B. 13
C. 65
D. 3
E. 8
David wants to create an algorithm to ensure that he buys exactly N items.
Which of these algorithms could he use?
A. Algorithm 1: Start with n with 0
Buy one item. Increase n by 1.
Repeat. Stop when n = N.
B. Algorithm 2: Start with n with 1
Buy one item. Increase n by 1.
Repeat. Stop when n = N.
C. Algorithm 3: Start with n with 0
Buy one item. Multiply n by 2.
Repeat. Stop when n = N.
D. Algorithm 4: Start with n with 1
Buy one item. Multiply n by 2.
Repeat. Stop when n = N.
E. None of the above
Alice wants to create an algorithm that would help her find the largest number in a set.
Assume that the set is denoted by a[0], a[1], ..., a[N-1].
Which of these algorithms could she use?
A. Algorithm 1:
Start with i = 0.
While i < N - 1:
Set large = a[i].
Increase i by 1.
B. Algorithm 2:
Start with i = 0 and large = a[0].
While i < N:
If a[i] > large, replace large with a[i].
Increase i by 1.
C. Algorithm 3:
Start with i = 0. Set large = a[0].
While i < N - 1:
If a[i] > large, replace large with a[i].
Increase i by 1.
D. Algorithm 4:
Start with i = 0. Set large = a[0].
While i < N:
If a[i] < large, replace large with a[i].
Increase i by 1.
E. None of the above
Susan wants to create an algorithm that finds the Nth Fibonacci number, which follows the
rules that:
F(1) = 1, F(2) = 1, F(n) = F(n – 1) + F(n – 2)
Which of the following algorithms could she use to find ?