135
BÀI THI TRẮC NGHIỆM ĐỀ SỐ: 501 1. What value is stored in x after the following two statements are executed: int x; x = 2 / 4 * 4 / 2; A 0 B 0.06 25 C 1 D 1. 0 2. Which of the following statements will correctly output the quote: Dan Quayle once said, "Who’s responsible for the riots? The rioters." A cout << "Dan Quayle once said, "Who\’s responsible for the riots? The rioters. " ";

Lap Trinh c Tren Linux Trac Nghiem 5739

Embed Size (px)

DESCRIPTION

Lap trinh c tren linux

Citation preview

Page 1: Lap Trinh c Tren Linux Trac Nghiem 5739

BÀI THI TRẮC NGHIỆMĐỀ SỐ: 501

 

1. What value is stored in x after the following two statements are executed:

int x;x = 2 / 4 * 4 / 2;

A

0

B

0.0625

C

1

D

1.0

2. Which of the following statements will correctly output the quote:

Dan Quayle once said, "Who’s responsible for the riots? The rioters."

A

cout << "Dan Quayle once said, "Who\’s responsible for the riots? The rioters. " ";

B

cout << "Dan Quayle once said, Who’s responsible for the riots? The rioters.";

C

cout << "Dan Quayle once said, "Who’s responsible for the riots? The rioters. " ";

Page 2: Lap Trinh c Tren Linux Trac Nghiem 5739

D cout << "Dan Quayle once said, \"Who’s responsible for the riots? The rioters. \" ";

3. Which of the following will output "Yes" if the integer variable num is either 2, 3, 4, or 5?

A

B

C

D

4. Which snippet of code correctly adds the odd integers between 1 and 20?

A

Page 3: Lap Trinh c Tren Linux Trac Nghiem 5739

B

C

D

5.

Page 4: Lap Trinh c Tren Linux Trac Nghiem 5739

A

B

C

D

6. Which of the following is an invalid comment?

A

// Comment regarding the program

Page 5: Lap Trinh c Tren Linux Trac Nghiem 5739

B /* Comment regarding the program */

C

/**************************

D

/************************** * Comment about the program **************************/

7. What data types can be used to store numeric values with a decimal point, such as 3.14 ?

A

short, int

B

long

C

float, double

D

char

8.

Page 6: Lap Trinh c Tren Linux Trac Nghiem 5739

A

x = 1, y = 2

B

x = 1, y = 1

C

x = 0, y = 2

D

x = 0, y = 1

9. What value is stored in variable x?

int x;x = 2 * 3 + 4 * 5 -4 / 2;

A

24

B

11

C

14

D

28

10. How can we input a value from the keyboard and store it in the variable named num?

A

cout << num;

Page 7: Lap Trinh c Tren Linux Trac Nghiem 5739

B cin >> num;

C

cin << num;

D

num = input();

11. To access functions such as abs, rand, or exit, what should be added to the top of the program?

A

#include < cmath>using namespace std;

B

#include < stdlib.h>

C

#include < cstdlib> using namespace std;

D

#include < iostream>using namespace std;

12. Which of the following functions correctly returns the minimum of three integers passed in?

A

Page 8: Lap Trinh c Tren Linux Trac Nghiem 5739

B

C

D

13.

Page 9: Lap Trinh c Tren Linux Trac Nghiem 5739

A

3 2 2 3

B

3 2 1 1

C

3 2 1 2

D

3 2 1 3

14.

Page 10: Lap Trinh c Tren Linux Trac Nghiem 5739

A

X =1 Y = 1

B

X =1 Y = 2

C

X =2 Y = 1

D

X =2 Y = 2

15. Which of the following function prototypes is equivalent to the following prototype?

int min(int num1, int num2, int num3);

A

int min(long num1, long num2, long num3);

Page 11: Lap Trinh c Tren Linux Trac Nghiem 5739

B int min(int, int, int);

C

int min(double num1, double num2, double num3);

D

long min(int, int, int);

16.

A

Before foo, X=1 In foo, X=1, After foo, X=1

B

Before foo, X=1 In foo, X=2, After foo, X=2

Page 12: Lap Trinh c Tren Linux Trac Nghiem 5739

C Before foo, X=2 In foo, X=2, After foo, X=2

D

Before foo, X=1 In foo, X=2, After foo, X=1

17.

A

10 4 10 4

B

10 4 10 3

Page 13: Lap Trinh c Tren Linux Trac Nghiem 5739

C 2 3 10 4

D

10 4 2 3

18.

A

10 4 10 4

B

2 3 10 4

C

10 4 10 3

Page 14: Lap Trinh c Tren Linux Trac Nghiem 5739

D 10 4 2 3

19.

A

X=3 Y=2

B

X=3 Y=3

C

X=2 Y=3

D

X=2 Y=2

Page 15: Lap Trinh c Tren Linux Trac Nghiem 5739

20. Given the following function prototype:

void foo(int arr[]);

Which statement correctly passes the array to the function?

A

int arr[10]; foo(arr);

B

int arr[10]; foo(arr[]);

C

int arr[10]; foo(arr[0]);

D

int arr[10]; foo(arr[10]);

21. Which of the following correctly declares an array that holds exactly 10 integers?

A

int[10] arr;

B

int[11] arr;

C

int arr[11];

D

int arr[10];

22.

Page 16: Lap Trinh c Tren Linux Trac Nghiem 5739

A

3 2 1

B

1 2 1

C

3 1 1

D

An error message

23. Which of the following is an invalid function prototype to accept a two-dimensional array of type double?

A

double foo(double arr[10][10]);

B

double foo(double arr[][10]);

Page 17: Lap Trinh c Tren Linux Trac Nghiem 5739

C

double foo(double arr[10][100]);

D

double foo(double arr[][]);

24.

A

1 2 3 4 5

B

5 4 3 2 1

C

5 2 3 4 1

D

5 2 3 4 5

25.

Page 18: Lap Trinh c Tren Linux Trac Nghiem 5739

A

3 1 1

B

3 2 1

C

1 2 3

D

1 2 1

26.

Page 19: Lap Trinh c Tren Linux Trac Nghiem 5739

A

int main(){Foo f;f->printMessage();return 0;}

B

int main(){Foo f;f::printMessage();return 0;}

C

int main() {Foo f;f.printMessage();return 0;

Page 20: Lap Trinh c Tren Linux Trac Nghiem 5739

}

D

int main(){Foo f;printMessage();return 0;}

27. What is the error in the following definition?

class BankAccount{public:int ID;double amount;}

A

There are no methods

B

There are no private variables

C

There is a missing semicolon after the right curly brace.

D

There are no public accessor methods.

28. Given the following declaration, how do we access the x and y members of the structure?

struct Point {int x;int y;};

Page 21: Lap Trinh c Tren Linux Trac Nghiem 5739

A Point p;p->x = 10;p->y = 20;

B

Point p;p::x = 10;p::y = 20;

C

Point p;p.x = 10;p.y = 20;

D

Point p;p:x = 10;p:y = 20;

29. What is the error in the following definition?

struct BankAccount{int ID;double amount;}

A

"ID" cannot be all uppercase

B

The keyword "struct" should be "structure"

C

Different data types are not allowed in the struct.

D

There is a semicolon missing after the right curly brace

Page 22: Lap Trinh c Tren Linux Trac Nghiem 5739

30. Under the principle of information hiding, which class definition best encapsulated the variable named "x"?

A

B

C

Page 23: Lap Trinh c Tren Linux Trac Nghiem 5739

D

31.

Page 24: Lap Trinh c Tren Linux Trac Nghiem 5739

Money m1(10,50), m2(10,50);

A

B

C

D

32.

Page 25: Lap Trinh c Tren Linux Trac Nghiem 5739

A

val1=2 val2=1val1=2 val2=2val1=2 val2=2

B

val1=0 val2=1val1=0 val2=2val1=0 val2=2

Page 26: Lap Trinh c Tren Linux Trac Nghiem 5739

C val1=2 val2=1val1=2 val2=2val1=3 val2=2

D

val1=1 val2=1val1=2 val2=2val1=3 val2=2

33.

A

void main(){cout << Compute:square(4) << endl;}

B

void main(){cout << square(4) << endl;}

C

void main(){cout << Compute::square(4) << endl;}

Page 27: Lap Trinh c Tren Linux Trac Nghiem 5739

D void main(){Compute x;cout << x.square(4) << endl;}

34.

A

In default constructorPrintingPrinting

B

In default constructorIn default constructorPrintingPrinting

Page 28: Lap Trinh c Tren Linux Trac Nghiem 5739

C PrintingPrinting

D

In default constructorPrintingIn default constructorPrinting

35.

Page 29: Lap Trinh c Tren Linux Trac Nghiem 5739

A 5 5

B

10 5

C

10 10

D

An error message will result because we have not overloaded the = operator

36.

Page 30: Lap Trinh c Tren Linux Trac Nghiem 5739

A

Nothing

B

Num1 and Num3 are the same

C

Num1 and Num2 are the same

Page 31: Lap Trinh c Tren Linux Trac Nghiem 5739

D An error message. We are not allowed to compare class objects using ==.

37. Which of the following is not allowed in overloading a function?

A

Two functions have identical parameter lists but different return types.

B

Two functions can have the same name.

C

Two functions have the same name and one takes parameters of type integer while another takes parameters of type long

D

Two functions have the same name and the same type of parameters, but one function takes two parameters while the other takes only one parameter.

38. How would we initialize the following structure to contain 1 and 2 upon declaring the variable of type Foo?

struct Stuff {int val2;};struct Foo {int num;Stuff val1;};

A

Foo x = {1, {2}};

B

Foo x = {{1,2}};

Page 32: Lap Trinh c Tren Linux Trac Nghiem 5739

C Foo x = {1, {2}};

D

Foo x = {1, 2};

39.

A

B

Page 33: Lap Trinh c Tren Linux Trac Nghiem 5739

C

D

40.

Page 34: Lap Trinh c Tren Linux Trac Nghiem 5739

A In the definition of the constructor, the return type of void should be specified.

B

The constructor must have a return type of void in the implementation

C

There should be no semicolon after the right curly brace in the definition of the Foo class

D

There should be no parentheses when declaring the variable f1 and invoking the default constructor.

41. Which of the following prototypes is invalid?

A

int operator %(Number x, int y);

B

int operator %(Number x, Number y);

C

int operator %(int x, int y);

D

int operator %(const Number &x, const Number &y);

42. Which of the following is not a valid reason to use const in the declaration below?

const Money operator +(const Money &, const Money &);

A

When we want to ensure that the programmer cannot change the objects within the function definition.

Page 35: Lap Trinh c Tren Linux Trac Nghiem 5739

B When we want to improve the efficiency of the program by passing the arguments as call by reference.

C

When we want to be able to directly modify the class that is returned

D

When we would like the compiler to flag as errors subtle bugs that may result when class objects are changed

43.

Page 36: Lap Trinh c Tren Linux Trac Nghiem 5739

A

6

7

B

6

8

C

7

8

D

7

9

BÀI THI TRẮC NGHIỆMĐỀ SỐ: 512

 

1. What value is stored in x and y after the following code is executed?

int x=1, y=2;x = (x < y) ? y*2 : y*3;

A

x = 4, y = 2

B

x = 6, y = 6

Page 37: Lap Trinh c Tren Linux Trac Nghiem 5739

C x = 4, y = 4

D

x = 6, y = 2

2. How can we input a value from the keyboard and store it in the variable named num?

A

num = input();

B

cin >> num;

C

cout << num;

D

cin << num;

3. Which of the following statements will correctly output the quote:

Dan Quayle once said, "Who’s responsible for the riots? The rioters."

A

cout << "Dan Quayle once said, "Who\’s responsible for the riots? The rioters. " ";

B

cout << "Dan Quayle once said, \"Who’s responsible for the riots? The rioters. \" ";

C

cout << "Dan Quayle once said, Who’s responsible for the riots? The rioters.";

D

cout << "Dan Quayle once said, "Who’s responsible for the riots? The

Page 38: Lap Trinh c Tren Linux Trac Nghiem 5739

rioters. " ";

4.

A

x = 1, y = 1

B

x = 0, y = 1

C

x = 0, y = 2

D

x = 1, y = 2

5. What will the following code output?

int x, y;x=3;y=(++x)*2;cout << x << " " << y << endl;

Page 39: Lap Trinh c Tren Linux Trac Nghiem 5739

A 3 6

B

3 8

C

4 6

D

4 8

6. What value is stored in variable x?

int x;x = 2 * 3 + 4 * 5 -4 / 2;

A

14

B

28

C

11

D

24

7. Which of the following is an invalid comment?

A

/**************************

B

/* Comment regarding the program */

Page 40: Lap Trinh c Tren Linux Trac Nghiem 5739

C /************************** * Comment about the program **************************/

D

// Comment regarding the program

8.

A

y = 0

B

y = 1

C

y = 2

D

y = 3

9. What data types can be used to store numeric values with a decimal point, such as 3.14 ?

A

float, double

Page 41: Lap Trinh c Tren Linux Trac Nghiem 5739

B long

C

char

D

short, int

10. Which of the following will output "Yes" if the integer variable num is either 2, 3, 4, or 5?

A

B

C

D

11.

Page 42: Lap Trinh c Tren Linux Trac Nghiem 5739

A

Before foo, X=1 In foo, X=1, After foo, X=1

B

Before foo, X=1 In foo, X=2, After foo, X=1

C

Before foo, X=2 In foo, X=2, After foo, X=2

D

Before foo, X=1 In foo, X=2, After foo, X=2

12. To access functions such as abs, rand, or exit, what should be added to

Page 43: Lap Trinh c Tren Linux Trac Nghiem 5739

the top of the program?

A

#include < iostream>using namespace std;

B

#include < cmath>using namespace std;

C

#include < cstdlib> using namespace std;

D

#include < stdlib.h>

13. Which of the following function prototypes is equivalent to the following prototype?

int min(int num1, int num2, int num3);

A

int min(long num1, long num2, long num3);

B

int min(double num1, double num2, double num3);

C

long min(int, int, int);

D

int min(int, int, int);

14.

Page 44: Lap Trinh c Tren Linux Trac Nghiem 5739

A

0 1 2 3 3

B

0 1 2 3 4

C

0 1 2 3 1

D

0 1 2 3 4 1

15. Which of the following functions correctly returns the minimum of three integers passed in?

A

Page 45: Lap Trinh c Tren Linux Trac Nghiem 5739

B

C

D

16.

Page 46: Lap Trinh c Tren Linux Trac Nghiem 5739

A

X=3 Y=2

B

X=3 Y=3

C

X=2 Y=2

D

X=2 Y=3

17.

Page 47: Lap Trinh c Tren Linux Trac Nghiem 5739

A

10 4 10 3

B

10 4 2 3

C

10 4 10 4

D

2 3 10 4

18.

Page 48: Lap Trinh c Tren Linux Trac Nghiem 5739

A

10 4 2 3

B

2 3 10 4

C

10 4 10 4

D

10 4 10 3

19. Given a function with a reference parameter such as: void foo(int &); Which of the following calls would give an error message?

Page 49: Lap Trinh c Tren Linux Trac Nghiem 5739

A

B

C

D

Page 50: Lap Trinh c Tren Linux Trac Nghiem 5739

20.

A

5 4 3 2 1

B

5 2 3 4 1

C

1 2 3 4 5

D

5 2 3 4 5

21.

Page 51: Lap Trinh c Tren Linux Trac Nghiem 5739

A

B

Page 52: Lap Trinh c Tren Linux Trac Nghiem 5739

C

D

22. Given the following array declaration, which snippet of code outputs all elements in the array? int arr[5];

A

for (int i=0; i<=5; i++) { cout << arr[i] << endl; }

B

for (int i=1; i<=5; i++) { cout << arr[i] << endl; }

C

for (int i=0; i<5; i++) { cout << arr[i] << endl; }

D

for (int i=1; i<5; i++) { cout << arr[i] << endl; }

23.

Page 53: Lap Trinh c Tren Linux Trac Nghiem 5739

A

1 2 1

B

1 2 3

C

3 1 1

D

3 2 1

24.

Page 54: Lap Trinh c Tren Linux Trac Nghiem 5739

A

3 2 1

B

1 2 1

C

3 1 1

D

An error message

25. Which of the following correctly declares an array that holds exactly 10 integers?

A

int[10] arr;

B

int arr[11];

Page 55: Lap Trinh c Tren Linux Trac Nghiem 5739

C

int arr[10];

D

int[11] arr;

26. Under the principle of information hiding, which class definition best encapsulated the variable named "x"?

A

B

Page 56: Lap Trinh c Tren Linux Trac Nghiem 5739

C

D

27.

Page 57: Lap Trinh c Tren Linux Trac Nghiem 5739

A

void Money::addValue(int d, int c){dollars = dollars + d;cents = cents + c;if (cents > 99) {dollars = dollars + (cents / 100);cents = cents / 100;}}

B

void Money::addValue(int d, int c){dollars = dollars + d;cents = cents + c;}

Page 58: Lap Trinh c Tren Linux Trac Nghiem 5739

C void Money::addValue(int d, int c){dollars = dollars + d;cents = cents + c;if (cents > 99) {dollars = dollars + (cents / 100);cents = cents % 100;}}

D

void Money::addValue(int d, int c){dollars = dollars + d;cents = cents + c;if (cents > 99) {dollars = dollars + (cents % 100);cents = cents / 100;}}

28.

Page 59: Lap Trinh c Tren Linux Trac Nghiem 5739

A

int main(){Foo f;printMessage();return 0;}

B

int main() {Foo f;f.printMessage();return 0;}

C

int main(){Foo f;f->printMessage();return 0;}

D

int main(){Foo f;f::printMessage();return 0;}

29. What is the error in the following definition?

struct BankAccount{int ID;double amount;}

A

There is a semicolon missing after the right curly brace

Page 60: Lap Trinh c Tren Linux Trac Nghiem 5739

B The keyword "struct" should be "structure"

C

Different data types are not allowed in the struct.

D

"ID" cannot be all uppercase

30. Which of the following is a way that structures differ from classes?

A

We can specify member variables to be public or private within a class, but not within a struct.

B

A class allows member functions in addition to member variables while a struct does not.

C

A class is used with object-oriented programming while a struct is not.

D

We can specify member functions to be public or private within a class, but not within a struct.

31.

Page 61: Lap Trinh c Tren Linux Trac Nghiem 5739

A

void main(){cout << square(4) << endl;}

B

void main(){Compute x;cout << x.square(4) << endl;}

C

void main(){cout << Compute:square(4) << endl;}

D

void main(){cout << Compute::square(4) << endl;}

32.

Page 62: Lap Trinh c Tren Linux Trac Nghiem 5739

Money m1(10,50), m2(10,50);

A

B

Page 63: Lap Trinh c Tren Linux Trac Nghiem 5739

C

D

33.

A

In default constructorPrintingIn default constructorPrinting

Page 64: Lap Trinh c Tren Linux Trac Nghiem 5739

B

In default constructorIn default constructorPrintingPrinting

C

PrintingPrinting

D

In default constructorPrintingPrinting

34.

Page 65: Lap Trinh c Tren Linux Trac Nghiem 5739

A

val1=2 val2=1val1=2 val2=2val1=3 val2=2

B

val1=2 val2=1val1=2 val2=2val1=2 val2=2

Page 66: Lap Trinh c Tren Linux Trac Nghiem 5739

C val1=0 val2=1val1=0 val2=2val1=0 val2=2

D

val1=1 val2=1val1=2 val2=2val1=3 val2=2

35.

Page 67: Lap Trinh c Tren Linux Trac Nghiem 5739

A 5 5

B

10 5

C

10 10

D

An error message will result because we have not overloaded the = operator

36.

Page 68: Lap Trinh c Tren Linux Trac Nghiem 5739

A

Nothing

B

Num1 and Num3 are the same

C

Num1 and Num2 are the same

Page 69: Lap Trinh c Tren Linux Trac Nghiem 5739

D An error message. We are not allowed to compare class objects using ==.

37.

A

2 dollars and 50 cents 4 dollars and 50 cents

B

2 dollars and 50 cents 4 dollars and 0 cents

C

This program will give an error message because the number of parameters on printMoney(4) do not match.

D

2 dollars and 50 cents 4 dollars and cents

38. How would we initialize the following structure to contain 1 and 2 upon declaring the variable of type Foo?

struct Stuff {

Page 70: Lap Trinh c Tren Linux Trac Nghiem 5739

int val2;};struct Foo {int num;Stuff val1;};

A

Foo x = {{1,2}};

B

Foo x = {1, 2};

C

Foo x = {1, {2}};

D

Foo x = {1, {2}};

39.

Page 71: Lap Trinh c Tren Linux Trac Nghiem 5739

A

B

C

Page 72: Lap Trinh c Tren Linux Trac Nghiem 5739

D

40.

A

There should be no parentheses when declaring the variable f1 and invoking the default constructor.

B

In the definition of the constructor, the return type of void should be specified.

Page 73: Lap Trinh c Tren Linux Trac Nghiem 5739

C

There should be no semicolon after the right curly brace in the definition of the Foo class

D

The constructor must have a return type of void in the implementation

41.

Page 74: Lap Trinh c Tren Linux Trac Nghiem 5739

A

B

C

D

42.

Page 75: Lap Trinh c Tren Linux Trac Nghiem 5739

A

6

7

B

6

8

Page 76: Lap Trinh c Tren Linux Trac Nghiem 5739

C 7

8

D

7

9

43.

Page 77: Lap Trinh c Tren Linux Trac Nghiem 5739

A 8

B

10

C

15

D

30

Page 78: Lap Trinh c Tren Linux Trac Nghiem 5739

BÀI THI TRẮC NGHIỆMĐỀ SỐ: 482

 

1.

A

y = 0

B

y = 1

C

y = 2

D

y = 3

2. Which snippet of code correctly adds the odd integers between 1 and 20?

A

Page 79: Lap Trinh c Tren Linux Trac Nghiem 5739

B

C

D

3.

Page 80: Lap Trinh c Tren Linux Trac Nghiem 5739

A

B

C

D

4. What data types can be used to store numeric values with a decimal point, such as 3.14 ?

A

short, int

Page 81: Lap Trinh c Tren Linux Trac Nghiem 5739

B long

C

float, double

D

char

5. Which of the following is a valid name for an identifier?

A

2fast

B

interest rate

C

_foobar_2

D

cout

6. Which of the following is an invalid comment?

A

// Comment regarding the program

B

/************************** * Comment about the program **************************/

C

/* Comment regarding the program */

D

/**************************

Page 82: Lap Trinh c Tren Linux Trac Nghiem 5739

7. How can we input a value from the keyboard and store it in the variable named num?

A

cin >> num;

B

num = input();

C

cin << num;

D

cout << num;

8. What value is stored in variable x?

int x;x = 2 * 3 + 4 * 5 -4 / 2;

A

11

B

14

C

28

D

24

9. Which of the following statements will correctly output the quote:

Dan Quayle once said, "Who’s responsible for the riots? The rioters."

Page 83: Lap Trinh c Tren Linux Trac Nghiem 5739

A cout << "Dan Quayle once said, Who’s responsible for the riots? The rioters.";

B

cout << "Dan Quayle once said, "Who\’s responsible for the riots? The rioters. " ";

C

cout << "Dan Quayle once said, "Who’s responsible for the riots? The rioters. " ";

D

cout << "Dan Quayle once said, \"Who’s responsible for the riots? The rioters. \" ";

10. What value is stored in x and y after the following code is executed?

int x=1, y=2;x = (x < y) ? y*2 : y*3;

A

x = 4, y = 2

B

x = 6, y = 6

C

x = 6, y = 2

D

x = 4, y = 4

11.

Page 84: Lap Trinh c Tren Linux Trac Nghiem 5739

A

0 1 2 3 3

B

0 1 2 3 4 1

C

0 1 2 3 4

D

0 1 2 3 1

12.

Page 85: Lap Trinh c Tren Linux Trac Nghiem 5739

A

X =2 Y = 2

B

X =2 Y = 1

C

X =1 Y = 1

D

X =1 Y = 2

13. What does the return type of void refer to?

A

That the function can return a numeric value

B

That the function does not return any value.

Page 86: Lap Trinh c Tren Linux Trac Nghiem 5739

C That the function returns a string.

D

That the function can return any value.

14.

A

3 2 1 1

B

3 2 2 3

C

3 2 1 2

Page 87: Lap Trinh c Tren Linux Trac Nghiem 5739

D 3 2 1 3

15.

A

Before foo, X=1 In foo, X=2, After foo, X=2

B

Before foo, X=2 In foo, X=2, After foo, X=2

C

Before foo, X=1 In foo, X=2, After foo, X=1

Page 88: Lap Trinh c Tren Linux Trac Nghiem 5739

D Before foo, X=1 In foo, X=1, After foo, X=1

16.

A

10 4 10 3

B

10 4 2 3

C

2 3 10 4

Page 89: Lap Trinh c Tren Linux Trac Nghiem 5739

D 10 4 10 4

17. Given a function with a reference parameter such as: void foo(int &); Which of the following calls would give an error message?

A

B

C

D

18.

Page 90: Lap Trinh c Tren Linux Trac Nghiem 5739

A

X=3 Y=2

B

X=3 Y=3

C

X=2 Y=3

D

X=2 Y=2

19.

Page 91: Lap Trinh c Tren Linux Trac Nghiem 5739

A

10 4 10 4

B

10 4 10 3

C

2 3 10 4

D

10 4 2 3

20. Which of the following correctly declares an array that holds exactly 10 integers?

Page 92: Lap Trinh c Tren Linux Trac Nghiem 5739

A int[11] arr;

B

int[10] arr;

C

int arr[11];

D

int arr[10];

21. Given the following function prototype:

void foo(int arr[]);

Which statement correctly passes the array to the function?

A

int arr[10]; foo(arr[0]);

B

int arr[10]; foo(arr[]);

C

int arr[10]; foo(arr);

D

int arr[10]; foo(arr[10]);

22.

Page 93: Lap Trinh c Tren Linux Trac Nghiem 5739

A

1 2 3 < unknown value > < unknown value >

B

1 2 3 < blank > < blank >

C

1 2 3 0 0

D

The program will output an error message.

23.

A

5 4 3 2 1

B

5 2 3 4 5

Page 94: Lap Trinh c Tren Linux Trac Nghiem 5739

C 1 2 3 4 5

D

5 2 3 4 1

24.

A

Page 95: Lap Trinh c Tren Linux Trac Nghiem 5739

B

C

D

25.

Page 96: Lap Trinh c Tren Linux Trac Nghiem 5739

A

3 2 1

B

1 2 1

C

3 1 1

D

An error message

26. What is the error in the following definition?

class BankAccount{public:int ID;double amount;}

Page 97: Lap Trinh c Tren Linux Trac Nghiem 5739

A There are no public accessor methods.

B

There is a missing semicolon after the right curly brace.

C

There are no methods

D

There are no private variables

27. What is the error in the following definition?

struct BankAccount{int ID;double amount;}

A

"ID" cannot be all uppercase

B

Different data types are not allowed in the struct.

C

The keyword "struct" should be "structure"

D

There is a semicolon missing after the right curly brace

28. Given the following declaration, how do we access the x and y members of the structure?

struct Point {int x;int y;};

Page 98: Lap Trinh c Tren Linux Trac Nghiem 5739

A Point p;p:x = 10;p:y = 20;

B

Point p;p.x = 10;p.y = 20;

C

Point p;p::x = 10;p::y = 20;

D

Point p;p->x = 10;p->y = 20;

29.

Page 99: Lap Trinh c Tren Linux Trac Nghiem 5739

A

int main(){Foo f;f::printMessage();return 0;}

B

int main() {Foo f;f.printMessage();return 0;}

C

int main(){Foo f;printMessage();return 0;}

D

int main(){Foo f;f->printMessage();return 0;}

30. Under the principle of information hiding, which class definition best encapsulated the variable named "x"?

A

Page 100: Lap Trinh c Tren Linux Trac Nghiem 5739

B

C

D

Page 101: Lap Trinh c Tren Linux Trac Nghiem 5739

31.

A

0 3

B

1 3

C

This program will crash because we did not initialize f1

Page 102: Lap Trinh c Tren Linux Trac Nghiem 5739

D 3 3

32.

Money m1(10,50), m2(10,50);

A

B

Page 103: Lap Trinh c Tren Linux Trac Nghiem 5739

C

D

33.

A

In default constructorPrintingPrinting

Page 104: Lap Trinh c Tren Linux Trac Nghiem 5739

B

In default constructorPrintingIn default constructorPrinting

C

In default constructorIn default constructorPrintingPrinting

D

PrintingPrinting

34.

Page 105: Lap Trinh c Tren Linux Trac Nghiem 5739

A

val1=1 val2=1val1=2 val2=2val1=3 val2=2

B

val1=2 val2=1val1=2 val2=2val1=2 val2=2

Page 106: Lap Trinh c Tren Linux Trac Nghiem 5739

C val1=0 val2=1val1=0 val2=2val1=0 val2=2

D

val1=2 val2=1val1=2 val2=2val1=3 val2=2

35.

Page 107: Lap Trinh c Tren Linux Trac Nghiem 5739

A

Nothing

B

Num1 and Num3 are the same

C

Num1 and Num2 are the same

D

An error message. We are not allowed to compare class objects using ==.

36.

Page 108: Lap Trinh c Tren Linux Trac Nghiem 5739

A

5 5

B

10 5

C

10 10

Page 109: Lap Trinh c Tren Linux Trac Nghiem 5739

D An error message will result because we have not overloaded the = operator

37. Which of the following is not allowed in overloading a function?

A

Two functions have the same name and one takes parameters of type integer while another takes parameters of type long

B

Two functions have identical parameter lists but different return types.

C

Two functions can have the same name.

D

Two functions have the same name and the same type of parameters, but one function takes two parameters while the other takes only one parameter.

38. How would we initialize the following structure to contain 1 and 2 upon declaring the variable of type Foo?

struct Stuff {int val2;};struct Foo {int num;Stuff val1;};

A

Foo x = {1, 2};

B

Foo x = {1, {2}};

Page 110: Lap Trinh c Tren Linux Trac Nghiem 5739

C Foo x = {{1,2}};

D

Foo x = {1, {2}};

39.

A

The constructor must have a return type of void in the implementation

B

There should be no parentheses when declaring the variable f1 and invoking the default constructor.

Page 111: Lap Trinh c Tren Linux Trac Nghiem 5739

C In the definition of the constructor, the return type of void should be specified.

D

There should be no semicolon after the right curly brace in the definition of the Foo class

40. Which of the following is not a valid reason to declare a class parameter as const? e.g.: void someFunction(const FooClass &);

A

When you want to pass the class by reference.X

B

When you want to ensure the programmer does not change the contents of a class variable inside a function.

C

It is more efficient to pass a class by value than by reference

D

When you would like an indicator that the intended use of the class variable is that it should not be changed inside the function

41.

Page 112: Lap Trinh c Tren Linux Trac Nghiem 5739

A

6

7

B

6

8

Page 113: Lap Trinh c Tren Linux Trac Nghiem 5739

C 7

8

D

7

9

42.

Page 114: Lap Trinh c Tren Linux Trac Nghiem 5739

A

B

C

D

43. Which of the following is not a valid reason to use const in the declaration below?

const Money operator +(const Money &, const Money &);

A

When we want to improve the efficiency of the program by passing the arguments as call by reference.

Page 115: Lap Trinh c Tren Linux Trac Nghiem 5739

B When we would like the compiler to flag as errors subtle bugs that may result when class objects are changed

C

When we want to be able to directly modify the class that is returned

D

When we want to ensure that the programmer cannot change the objects within the function definition.