Lap Trinh c Tren Linux Trac Nghiem 5739

Preview:

DESCRIPTION

Lap trinh c tren linux

Citation preview

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. " ";

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

B

C

D

5.

A

B

C

D

6. Which of the following is an invalid comment?

A

// Comment regarding the program

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.

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;

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

B

C

D

13.

A

3 2 2 3

B

3 2 1 1

C

3 2 1 2

D

3 2 1 3

14.

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

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

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

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

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

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.

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

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.

A

3 1 1

B

3 2 1

C

1 2 3

D

1 2 1

26.

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;

}

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

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

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

A

B

C

D

31.

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

A

B

C

D

32.

A

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

B

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

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

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

34.

A

In default constructorPrintingPrinting

B

In default constructorIn default constructorPrintingPrinting

C PrintingPrinting

D

In default constructorPrintingIn default constructorPrinting

35.

A 5 5

B

10 5

C

10 10

D

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

36.

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 ==.

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

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

D

Foo x = {1, 2};

39.

A

B

C

D

40.

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.

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.

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

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

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;

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 */

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

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.

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

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.

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

B

C

D

16.

A

X=3 Y=2

B

X=3 Y=3

C

X=2 Y=2

D

X=2 Y=3

17.

A

10 4 10 3

B

10 4 2 3

C

10 4 10 4

D

2 3 10 4

18.

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?

A

B

C

D

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.

A

B

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.

A

1 2 1

B

1 2 3

C

3 1 1

D

3 2 1

24.

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

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

C

D

27.

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

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.

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

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.

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.

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

A

B

C

D

33.

A

In default constructorPrintingIn default constructorPrinting

B

In default constructorIn default constructorPrintingPrinting

C

PrintingPrinting

D

In default constructorPrintingPrinting

34.

A

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

B

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

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

D

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

35.

A 5 5

B

10 5

C

10 10

D

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

36.

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 ==.

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 {

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.

A

B

C

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.

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.

A

B

C

D

42.

A

6

7

B

6

8

C 7

8

D

7

9

43.

A 8

B

10

C

15

D

30

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

B

C

D

3.

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

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

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

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."

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.

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.

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.

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

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

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

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.

A

X=3 Y=2

B

X=3 Y=3

C

X=2 Y=3

D

X=2 Y=2

19.

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?

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.

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

C 1 2 3 4 5

D

5 2 3 4 1

24.

A

B

C

D

25.

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

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

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.

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

B

C

D

31.

A

0 3

B

1 3

C

This program will crash because we did not initialize f1

D 3 3

32.

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

A

B

C

D

33.

A

In default constructorPrintingPrinting

B

In default constructorPrintingIn default constructorPrinting

C

In default constructorIn default constructorPrintingPrinting

D

PrintingPrinting

34.

A

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

B

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

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

D

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

35.

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.

A

5 5

B

10 5

C

10 10

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

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.

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.

A

6

7

B

6

8

C 7

8

D

7

9

42.

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.

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.