2018年2月13日 星期二

計概15-05程式語言的基本結構-02選擇結構-統測試題

【四技試題】

D01.以下是一個體重評估的Visual Basic程式片段,假設小明和小華的身高和體重相同,都是height = 160weight = 54,但是小明的性別sex = "M",而小華的sex = "F",若由以下程式進行評估,執行之後evaluation的結果分別為何? (A)小明和小華evaluation的結果都是"太瘦" (B)小明和小華evaluation的結果都是"太胖" (C)小明evaluation的結果為"適中",而小華evaluation的結果為"太胖" (D)小明evaluation的結果為"太瘦",而小華evaluation的結果為"適中"[100商業]

Dim standard, height, weight As Integer

Dim sex, evaluation As String

If sex = "M" Then

 standard = (height - 80) * 0.7

Else

 standard = (height - 70) * 0.6

End If

Select Case weight - standard

 Case Is > 0

  evaluation = "太胖"

 Case Is < 0

  evaluation = "太瘦"

 Case Else

  evaluation = "適中"

小明sex = "M"

(160 - 80) * 0.7 = 56

 

 

 

54 - 56 = -2

 

 

-2 < 0

evaluation = ""

小華sex = F

 

 

(160 - 70) * 0.6 = 54

 

54 - 54 = 0

 

 

 

 

0 = 0

evaluation = "適中"

End Select

 

A02.下列Visual Basic程式片段執行後,s之值為何? (A)"a" (B)"b" (C)"c" (D)"d"[100管理]

Dim i As Integer = 20, s As String

Select Case i i = 20

 Case Is >10 20 > 10成立

  s = "a" s = "a"

 Case 10 To 30

  s = "b"

 Case 15, 20

  s = "c"

 Case 20

  s = "d"

End Select

 

D03.判斷某西元年是否為閏年的規則如下:如果某個年份的西元年是400的倍數則必然為閏年,否則要判斷該西元年是否為4的倍數,且不可為100的倍數。在Visual Basic中,假設要判斷的某西元年變數為year,若用以下程式判斷是否為閏年:If 敘述式 Then....End If,則其條件式應是以下何者? (A)(year Mod 400) == 0 || ((year Mod 4) == 0 && (year Mod 100)! = 0) (B)(year Mod 4)=0 Or ((year Mod 400) == 0 And (year Mod 100)! = 0) (C)(year Mod 4) == 0 || ((year Mod 400) == 0 && (year Mod 100) <> 0) (D)(year Mod 400) = 0 Or ((year Mod 4) = 0 And (year Mod 100) <> 0)[103管理]

閏年的條件:(1)西元年為400的倍數,(2)西元年為4的倍數,且不可為100的倍數。

 

C04.執行下列Visual Basic程式片段後,變數s的值為何? (A)-3 (B)0 (C)3 (D)9[105商業]

Dim r, s As Integer

r = 3

Select Case r

 Case 1, 3 r = 3

  s = r s = 3

 Case 4, 6

  s = r * r

 Case Is >= 5, Is <= 0

  s = 0

 Case 3

  s = -r

End Select

 

C05.執行下列Visual Basic程式片段後,變數K的值為何? (A)0 (B)1 (C)2 (D)3[105管理]

Dim I, J, K As Integer

I = 1: J = 0

If I = 0 Then 1 = 0不成立

 If J = 0 Then

  K = 0

 Else

  K = 1

 End If

Else

 If J = 0 Then J = 0成立

  K = 2 K = 2

 Else

  K = 3

 End If

End If

 

C06.執行下列Visual Basic程式片段,變數Result的值為何? (A)過輕 (B)正常 (C)過重 (D)肥胖[106商業]

Dim Height, Weight, BMI As Single

Dim Result As String

Height = 150: Weight = 55

BMI = Weight / (Height / 100) ^ 2 55 / (150 / 100) ^ 2 = 55 / (1.5) ^ 2 = 55 / 2.25 = 24.4

Select Case BMI

  Case Is >= 27

    Result = "肥胖"

  Case 24 To 27 BMI = 24.4

    Result = "過重" "過重"

  Case 18.5 To 24

    Result = "正常"

  Case Else

    Result = "過輕"

End Select

 

A07.執行下列Visual Basic程式片段後,變數N的值為何? (A)0 (B)1 (C)6 (D)7[106管理]

Dim N As Integer = 30

If N < 30 Then 30 < 30 不成立

  N = N \ 5

Else

  N = N Mod 5 30 Mod 5 = 0

End If

 

D08.執行下列Visual Basic程式片段後變數a的值為何 (A)0 (B)1 (C)2 (D)3[107管理]

Dim a, b As Integer

a = 0: b = 95

If b >= 80 Then 95 >= 80成立

  If b < 90 Then 95 < 90不成立

    a = 1

  Else

    a = 2 a = 2

  End If

  a = 3 a = 3

End If

 

D09.下列Visual Basic程式執行後,變數result的值為何? (A)4 (B)3 (C)2 (D)1[108管理]

Dim operation, result As Integer

operation = 5 * 2 Mod 2 * 3 + 6 / 2 10 Mod 6 + 3 = 4 + 3 = 7

Select Case operation

 Case 7

  result = 1 result = 1

 Case 3

  result = 2

 Case 2

  result = 3

 Case 18

  result = 4

End Select

 

D10.執行下列的程式後,A = 107,則Value的初始值為何? (A)2 (B)4 (C)7 (D)8[109資電]

Dim A As Integer

Dim Value As Integer

A = 2: Value =

Select Case Value

  Case 1 To 3

    A = 103 + Value

  Case 4, 5, 6

    A = 100 + Value

  Case 8 to 13

    A = 99 + Value

  Case Else

Value

A

1

103 + 1 = 104

2

103 + 2 = 105

3

103 + 3 = 106

4

100 + 4 = 104

5

100 + 5 = 105

6

100 + 6 = 106

7

105 + 7 = 112

8

99 + 8 = 107

    A = 105 + Value

End Select

 

B11.請問執行下列VB程式片段後,變數X的值為何? (A)5 (B)10 (C)20 (D)25[109管理]

Dim X, Y As Integer

X = 10: Y = 15

If X > Y Then 10 > 15不成立

  X = X + 5

  If X >10 Then

    X = X + 10

  Else

    X = X + 5

  End If

Else

  X = X + 5 10 + 5 = 15

  If X < 10 Then 15 < 10不成立

    X = X - 10

  Else

    X = X - 5 15 - 5 = 10

  End If

End If

 

B12.請問執行下列VB程式片段後,變數X的值為何? (A)3 (B)5 (C)9 (D)11[109管理]

Dim X, Y As Integer

X = 10: Y = 15

X = X Mod 6 10 Mod 6 =4

Y = Y Mod 4 15 Mod 4 = 3

If X > Y Then 4 > 3成立

  X = X + 1 4 + 1 = 5

Else

  X = X - 1

End If

 

B13.程式執行結束後,關於這個程式碼中的變數ABCD之數值,下列何者正確? (A)B值為100 (B)D值為100 (C)C值為100 (D)A值為95[110資電]

Private Sub Mytest()

  Dim A, B, C, D As Integer

  A = 10

  B = 100

  C = 95

  If A >= B Then 10 >= 100 False

    D = A

    A = B

  Else

    D = B D = 100

    B = A B = 10

  End If

  If D <= C Then 100 <= 95 False

    D = C

    B = D

    A = C

    C = B

  End If

End Sub

A = 10B = 10C = 95D = 100

 

B】14.圖所示的流程圖與下列哪一項Visual Basic的語法結構最相關 (A)If...Then...End If (B)If...Then...Else...End If (C)Select Case...End Select (D)While...Wend[110管理]

 

D】15.執行下列Visual Basic程式片段後,變數Ans的值為何? (A)8 (B)9 (C)10 (D)11[110管理]

Dim C = 10, Ans = 0

If C / 3 = 3 Then 10 / 3 <> 3

  Ans = Ans + 1

Else

  Ans = Ans + 2 0 + 2 = 2

End If

C = C * 4 + 5 Mod 3 10 * 4 + 5 Mod 3 40 + 2 = 42

If C = 0 Then

  Ans = Ans + 7

Else

  Ans = Ans + 9 2 + 9 = 11

End If

 

【二技試題】

A01.下列Visual Basic程式片段執行後,結果為何? (A)HappyBirthday (B)Happy (C)BirthdayHappy (D)Birthday[96護理]

x = 10: y = 4

If x >= 10 And y < 6 Then 10 >= 10 And 4 < 6成立

 Print "Happy"; 顯示"Happy"

End If

Print "Birthday" 顯示"Birthday"

 

D02.下列Visual Basic語言片段程式執行後,下列哪一項是正確的? (A)a = 3 (B)b = 3 (C)a = 5 (D)b = 5[100管理]

Dim a, b As Integer

a = 1: b = 2

If (a > 1) Then 1 > 1不成立

 a = a + 1

Else

 b = b + 2 2 + 2 = 4

End If

If (b > 2) Then 4 > 2成立

 b = b + 1 4 + 1 = 5

Else

 a = a + 2

End If

 

沒有留言:

張貼留言

注意:只有此網誌的成員可以留言。