False Indicate whether the statement is true or false

CS12 Exam 1 True/False Indicate whether the statement is true or false. ____ 1. The statement lstBox.Items.Add("") clears all the text from the list ...
5 downloads 0 Views 149KB Size
CS12 Exam 1 True/False Indicate whether the statement is true or false. ____

1. The statement lstBox.Items.Add("") clears all the text from the list box.

____

2. If strVar.Length is 5, then the value of strVar.Substring(4, 1)

is the last character of the value of strVar. ____

3. The following two statements are equivalent. var1 = var2 var2 = var1

____

4. When the Mask property of a masked text box is set to LL, only a string of two letters can be en-

tered. ____

5. A string literal is a sequence of characters that is treated as a single entity.

____

6. The value of strVar.Length is the number of characters in the value of strVar.

____

7. The value returned by InputBox is a string.

____

8. If sr is a StreamReader, then a statement of the form var = sr.ReadLine reads an item of data from

a file and assigns it to the string variable var. ____

9. The following statement assigns 6 times the value of y to x. x = 6y

____ 10. The following statement is valid. Dim x As Double = 3,542.36

____ 11. You can use a variable name in almost any place you could use a literal value. ____ 12. When reading from a file in the Debug subfolder of the bin subfolder of the program's folder, there is

no need to specify the path. ____ 13. The value of FormatCurrency(12345) is $12,345.00.

____ 14. When declaring a variable of type String, you must specify a length for the string ____ 15. The Substring method is used to extract a portion of a string. ____ 16. Numeric variables can be initialized to zero or any other number, but once they are initialized, they

cannot be changed. ____ 17. The following statement is valid where dog and cat are variables of the same type. dog = cat

____ 18. The empty string is the same as a string that contains one space. ____ 19. When using zones to display output in a table, you should use a fixed width font like Courier New. ____ 20. The statement a + b = c assigns to c the sum of the values of a and b. ____ 21. An assignment statement is used to assign a value to a variable or property. ____ 22. The variables firstName and firstNAME are identical. ____ 23. All comment statements must be placed at the beginning of a program. ____ 24. A numeric variable that has not been assigned a value has the value zero. ____ 25. The following statement is valid. y = y + 72

____ 26. When using the equal sign to assign values, the variable on the left hand side of the equal sign will

always receive the value. ____ 27. The following two statements are equivalent, where numVar is a numeric variable. numVar = numVar + 1 numVar += 1

Multiple Choice Identify the choice that best completes the statement or answers the question. ____ 28. What is the proper syntax when using a message dialog box? a. MsgBox("Hi there", 0, "Hi") c. MsgBox Hi There, 0, Hi b. MsgBox(Hi there, 0, Hi)

d. MsgBox "Hi There", 0, "Hi"

____ 29. What is the displayed in the title bar of the message dialog box by the following statement? MsgBox("This is a test.", 0, "Test")

a. Test c. Nothing. b. The same as the name of the program. d.

This is a test.

____ 30. Suppose the first two lines of the file DATA.TXT contain the strings Clint and 1930. What is dis-

played by the following lines of code? Dim name As String, birthYear As Integer Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT") name = sr.ReadLine birthYear = CInt(sr.ReadLine) txtBox.Text = "In 2005, " & name & " will be " & (2005 – birthYear) sr.Close() a. In 2005, Clint will be 2005 – 1930 b. In 2005, Clint will be 75 c. In 2005, "Clint" will be 75

d. Clint, 1930 ____ 31. The symbol for the string concatenation operator is a. & c. % b. # d.

@

____ 32. What will be displayed when the following lines are executed? Dim x As Double = 3, y As Double = 1 Dim z As Double z = x + (y * x) x = y z = x + z lstBox.Items.Add(x + y + z) a. 4 c. 9 b. 10 d. None of

the above

____ 33. What will be displayed when the following lines are executed? Dim fmtStr As String = "{0,-4:C0}{1, 6:P1}" lstBox.Items.Add("123456789012") lstBox.Items.Add(String.Format(fmtStr, 2.25, 0.375))

a. 123456789012 $2.00

37.5%

b. 123456789012 $2

37.5 %

c. 123456789012 $2.00

37 %

d. 123456789012 $2

0.375 %

____ 34. Which statement will assign the words “Hello World” to a text box? a. txtBox.Text = Hello & " World" b. txtBox.Text = "Hello" & " World" c. txtBox.Text = "Hello " & World d. txtBox.Text = Hello & World ____ 35. Which statement can be used to clear the contents of a text box? a. txtBox.Text = "" c. txtBox.Wipe() b. txtBox.Empty = True d. txtBox = "" ____ 36. What is the value of ("12/15/06").Substring(3,2)? a. 12/15/96 c. /15 b. /15/

d. 15

____ 37. Which of the following expressions has as its value the value of strVar with its leading and trailing

spaces removed? a. strVar.Ctrim b. strVar.ToUpper

c. strVar.Length d. strVar.Trim

____ 38. What will be the output of the following statement? txtBox.Text = CStr(Math.Round(17 / 2))

a. 9

b. 8.5

c. 8 d. 17.00

____ 39. Which of the following statements removes all text from lstBox? a. lstBox.Text.Clear() c. lstBox.Items.Add("") b. lstBox.Clear() d. lstBox.Items.Clear() ____ 40. Which of the following statements declare the variables a and b as type Integer? a. Dim a, b c. a = 0: b = 0 b. Dim a, b As Integer

d. Dim a & b As Integer

____ 41. What value will be assigned to the numeric variable x when the following statement is executed? x = 2 + 3 * 4

a. 234 b.

20

c. 14 d. 92

____ 42. Which of the following expressions will yield the string "John Doe", where name1 = "John Blake"

and name2 = "Janet Doe"? a. name1.Substring(0, 4) & name2.Substring(0, 3) b. name1.Substring(0, 4) & name2.Substring(6, 8) c. name1.Substring(0, 5) & name2.Substring(6, 3) d. None of the above.

____ 43. Which format statement should be used when you want to output your results in tabular format with

the first column 10 characters wide, the second 5, and the third 10? a. Dim b. Dim c. Dim d. Dim

fmtStr fmtStr fmtStr fmtStr

as as as as

String String String String

= = = =

"{10}{5}{10}" "{0, 10; 1, 5; 2, 10}" "{0}{1}{2}" "{0, 10}{1, 5}{2, 10}"

____ 44. To continue a long statement on another line, use a. an ampersand character. b. Ctrl + Enter. c. a space followed by an underscore character. d.

an underscore character.

____ 45. What character is used to signify the beginning of a comment statement? a. apostrophe c. backslash b. d. exclamation mark

asterisk

____ 46. Which statement prompts the user for a name and then assigns the name to the string variable str-

Name? a. InputBox("What is your first name?", "First Name") = strName b. strName = InputBox("What is your first name?", "First Name") c. strName = MsgBox("What is your first name?", 0, "First Name") d. MsgBox "What is your first name?", 0, "First Name" = strName ____ 47. What will be the output of the following statement? txtBox.Text = FormatPercent(2/3, 4) c. 0.6667

a. 0.6666 b. 66.6667%

d. 66.66%

____ 48. After the statement Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT")

has been executed, which of the following statements will close the file? a. Close sr b. sr.Close()

c. "DATA.TXT".Close() d. Close "DATA.TXT"

____ 49. Reserved words in Visual Basic are words that a. are used as prefixes for control names (such as txt, btn, lbl, and lst). b. have special meaning and should not be used when naming variables. c.

should be used when naming variables. d. are used to name controls, such as TextBox1, Command2, etc.

____ 50. Which of the numbers below is equivalent to 0.000017489? a. 17489E+06 c. 1.7489E-06

b. 1.7489E-05

d.

1.7489E+05

____ 51. Which one of the statements below is equivalent to the following code? With lstBox.Items .Add(5) End With a. Add.lstBox.Items(5) b. Add lstBox.Items(5)

c. lstBox.Items Add(5) d. lstBox.Items.Add(5)

____ 52. What will be the value of numVar when the following code is executed? Dim strVar As String, numVar As Integer strVar = "Now is the time for all good men" numVar = strVar.IndexOf("the time for") "12" a. c. 8 b. "Now is all good men" d. 7

____ 53. What message will be displayed by the following statement: MsgBox("This is a test.", 0, "Test")

a. Test b. Nothing.

c. This is a test. Test d.

This is a test.

____ 54. What is the correct syntax for displaying the value of the String variable myString in a text box? a. txtBox.Text = myString c. txtBox.Text = "myString" b. txtBox.Text = Str(myString)

d. txtBox.Text.myString

____ 55. What will be the output of the following line? txtBox.Text = "2" & 3

a. 2 3 b. 5

c. 23 d. Syntax error

____ 56. Assume that x, y, and temp are Integer variables. Which of the following lines of code swaps the val-

ues of x and y? a. x = y y = x

b. x = temp x = y y = temp

c. x = y temp = x y = temp

d. temp = x x = y

y = temp

____ 57. What is the correct statement when declaring and assigning the value of 100 to an Integer variable

called commission?

a. Dim commission = Int(100) b. Dim commission = 100 c. Dim commission As Integer = 100 d. commission = 100 ____ 58. What will be the contents of the variable x after the following statement is executed? x = Math.Sqrt(((9 + 7) / (4 * 2)) + 2)

a. 4 b. 3 c.

1

d. 2 e. None of the above ____ 59. What will be displayed when the following lines are executed?

a.

Dim x As Double = 2 'x = 3 txtBox.Text = CStr(x) 0

b. 2

c. 3 d. None of the above

____ 60. What will be the output of the following lines? Dim alphabet, soup As String alphabet = "abcdefghijklmnopqrstuvwxyz" soup = alphabet.ToUpper txtBox.Text = alphabet.Substring(0, 5) & soup.Substring(0, 5) eE a. c. abcdeABCDE EE b. d. ABCDEABCDE

____ 61. What will be displayed when the following lines are executed? Dim a, b, c As String a = "THE WHOLE" b = "PART" c = a.Substring(CInt(Math.Sqrt(4)), b.Length) txtBox.Text = CStr(c) a. E WH c. HE W b. THE WHOLE PART d. 6

____ 62. What will be the output of the following statement? txtBox.Text = FormatNumber(1234.56789, 3) 1,230 a. c. 1234.568 b. 1,234.568 d. 1230

____ 63. Given x = 3 and y = 1, what value will be assigned to the Double variable w when the following

statement is executed? w = (x + y) / (x – y)

a.

c. 3

1 b. 2

d. None of the above

____ 64. Suppose the Double variable num has the value 123.4567. What value will the following statement

assign to num? num = Math.Round(num, 2)

a.

c. 123.457

123.4567 b. 123.46

d. 123.45

____ 65. Give a declaration statement for the format string fmtStr that will produce the output 1234567890 a bc

when the following lines of code are executed. lstOutput.Items.Add("1234567890") lstOutput.Items.Add(String.Format(fmtStr, "a", "bc")) Dim fmtStr As String = "{0,-4}{1,-4}"

a. b. Dim fmtStr As String = "{0,4}{1,4}" c. Dim fmtStr As String = "{0,-4}{1,4}" d. Dim fmtStr As String = "{0,4}{1,-4}"

____ 66. Suppose you are 20 years old, num is an integer variable, and the statement num = 1 + CInt(InputBox("How old are you?"))

is executed and responded to? What will be the output of a.

txtBox.Text = num & " years old" 20 years old c.

b. Syntax error

1 + "How old are you?"

d. 21 years old

____ 67. What will be displayed when the following lines are executed? Dim x As Double = 2 Dim y As Double = 3 Dim fmtStr As String = "{0,-5}{1, -5}" lstOutput.Items.Add("1234567890") lstOutput.Items.Add(String.Format(fmtStr, x, y))

a. 1234567890 2

3

b. 1234567890 2

3

c. 1234567890 2

3

d. 1234567890 23

____ 68. Which of the following is a valid name for a variable? a. 2One c. Two One b. Two.One d.

Two_One

____ 69. Which of the following statements is a valid assignment statement? a. txtBox.Text = "Hello World" c. Text.txtBox = "Hello World" b. "Hello World" = txtBox.Text d. txtBox = "Hello World" ____ 70. What will be the output of the following statement? txtBox.Text = FormatCurrency(1234.567)

a. $1234.57

b. $1,234.57 ____ 71. What is the value of Int(8.9)? a.

8 b. 9

c. $1234.567 d. 1,234.57

c. 8.9 d. 1

____ 72. Which of the following masks is appropriate for a masked text box into which the user will enter a

license plate consisting of two digits followed by 4 letters? a. c. 00LLLL &&LLLL b. &&&&&&

d. None of the above.

____ 73. The joining of two strings together to form a new string is called a. c. substrings.

concatenation.

b. compaction.

d. addition.

____ 74. Given the data assigned to the string variable y shown below, which of the following statements will

assign the value ALL to the string variable x? y = "WHEN ALL ELSE FAILS, READ THE DIRECTIONS" c. x = y.Substring(6, 3)

a. x = y.Substring(5, 3) b. x = y.IndexOfStr("ALL")

d. x = y.Substring(5)

____ 75. Which declaration statement is used when you want to read data from the file DATA.TXT? a. Dim sr As IO.StreamReader = IO.File.OpenText("DATA.TXT") b. Dim DATA.TXT As IO.File.OpenText c. Dim IO.File.OpenText("DATA.TXT") d. Dim sr As IO.StreamReader = IO.File.OpenText(DATA.TXT)

CS12 Exam 1 Answer Section TRUE/FALSE 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27.

ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS:

F T F T T T T T F F T T T F T F T F T F T T F T T T T

PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

MULTIPLE CHOICE 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38.

ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS:

A A B A C B B A D D C

PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS:

1 1 1 1 1 1 1 1 1 1 1

39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75.

ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS: ANS:

D B C C D C A B B B B B D D D A C D C D B C A B B B C D B D A B A C A A A

PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS: PTS:

1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Suggest Documents