2018年4月12日 星期四

計概15-06陣列-統測試題

【四技試題】

D01.執行下列Visual Basic程式片段後,A(0)的值為何? (A)2 (B)4 (C)6 (D)10[100管理]

Dim A(5), K As Integer

A(5) = 0: A(4) = 2

For K = 5 To 2 Step -1

 A(K - 2) = A(K) + A(K - 1)

Next K

K

A(K)

A(K - 1)

A(K - 2)

K

A(K)

A(K - 1)

A(K - 2)

5

A(5) = 0

A(4) = 2

A(3) = 2

3

A(3) = 2

A(2) = 4

A(1) = 6

4

A(4) = 2

A(3) = 2

A(2) = 4

2

A(2) = 4

A(1) = 6

A(0) = 10

 

C02.請問下列Visual Basic程式片段執行運算後,X(7)所得之結果為何? (A)5 (B)7 (C)8 (D)9[101商業]

Dim Y, X(7) As Integer

X(1) = 2: Y = 1

For Y = 2 To 7

  X(Y) = Y + X(Y - 1) \ 5

Next Y

Y

X(Y) = Y + X(Y - 1) \ 5

Y

X(Y) = Y + X(Y - 1) \ 5

2

X(2) = 2 + X(1) \ 5 = 2 + 1 \ 5 = 2 + 0 = 2

5

X(5) = 5 + X(4) \ 5 = 5 + 4 \ 5 = 5 + 0 = 5

3

X(3) = 3 + X(2) \ 5 = 3 + 2 \ 5 = 3 + 0 = 3

6

X(6) = 6 + X(5) \ 5 = 6 + 5 \ 5 = 6 + 1 = 7

4

X(4) = 4 + X(3) \ 5 = 4 + 3 \ 5 = 4 + 0 = 4

7

X(7) = 7 + X(6) \ 5 = 7 + 6 \ 5 = 7 + 1 = 8

 

D03.下列Visual Basic程式片段執行後,若將陣列B之值由B(0)B(2)列出,並以逗點分隔各元素,其結果為何? (A)3, 7, 11 (B)4, 9, 14 (C)7, 18, 28 (D)8, 20, 31[102商業]

Dim A(3, 2)As Integer

A(0, 0) = 2: A(0, 1) = 1: A(1, 0) = 3: A(1, 1) = 4: A(2, 0) = 5: A(2, 1) = 6

Dim B() As Integer = {1, 2, 3}

For i = 0 To 2

 For j = 0 To 1

  A(i, j) = A(i, j) + A(i, (j + 1) Mod 2)

 Next j

Next i

For i = 0 To 2

 B(i) = B(i) + (A(i, 0) + A(i, 1))

Next i

i

j

A(i, j) = A(i, j) + A(i, (j + 1) Mod 2)

i

B(i) = B(i) + (A(i, 0) + A(i, 1))

0

0

A(0, 0)=A(0, 0)+A(0, 1)=2+1=3

0

B(0)=B(0)+A(0, 0)+A(0, 1)=1+3+4=8

1

A(0, 1)=A(0, 1)+A(0, 0)=1+3=4

1

B(1)=B(1)+A(1, 0)+A(1, 1)=2+7+11=20

1

0

A(1, 0)=A(1, 0)+A(1, 1)=3+4=7

2

B(2)=B(2)+A(2, 0)+A(2, 1)=3+11+17=31

1

A(1, 1)=A(1, 1)+A(1, 0)=4+7=11

 

 

2

0

A(2, 0)=A(2, 0)+A(2, 1)=5+6=11

 

 

1

A(2, 1)=A(2, 1)+A(2, 0)=6+11=17

 

 

 

A04.執行下列Visual Basic程式片段後變數C的值為何 (A)0 (B)1 (C)2 (D)3[104商業]

Dim A(3), B(3) As Integer

A(0) = 1: A(1) = 3: A(2) = 0: A(3) = 2

B(0) = 2: B(1) = 1: B(2) = 3: B(3) = 0

C = A(B(A(2) + 1) + 1) A(B(0 + 1) + 1) = A(1 + 1) = 0

 

D05.執行下列Visual Basic程式片段後,a(0)a(1)之值依序為何? (A)2, 26 (B)4, 18 (C)5, 23 (D)6, 28[105商業]

Dim i, j, k, s, a(10) As Integer

i = 0

For j = 1 To 1000

 s = 0

 For k = 1 To j - 1

  If j Mod k = 0 Then

   s = s + k

  End If

 Next

 If s = j Then

  a(i) = j: i = I + 1

 End If

Next

a(0) = 6a(1) = 28a(2) = 496

 

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

Dim K, A(6), B(6) As Integer

A(1) = 1: A(2) = 2

B(1) = 1: B(2) = 2

For K = 3 To 5

 A(K) = A(K - 1) + A(K - 2) - 1

 B(K) = A(K) - B(K - 1)

Next K

K

A(K) = A(K - 1) + A(K - 2) - 1

B(K) = A(K) - B(K - 1)

3

A(3) = A(3 - 1) + A(3 - 2) - 1 = 2 + 1 - 1 = 2

B(3) = A(3) - B(3 - 1) = 2 - 2 = 0

4

A(4) = A(4 - 1) + A(4 - 2) - 1 = 2 + 2 - 1 = 3

B(4) = A(4) - B(4 - 1) = 3 - 0 = 3

5

A(5) = A(5 - 1) + A(5 - 2) - 1 = 3 + 2 - 1 = 4

B(5) = A(5) - B(5 - 1) = 4 - 3 = 1

 

C07.執行下列Visual Basic程式片段,變數Total的值為何? (A)0 (B)1 (C)2 (D)4[106商業]

Dim X, Y, Total, A(8, 4) As Integer

Total = 0

For X = 1 To 8 Step 2

  For Y = 1 To 4 Step 3

    If X > Y Then

      Total = Total + 1

    Else

      Total = Total - 1

    End If

    A(X, Y) = Total

  Next Y

Next X

Total = Math.Abs(Int((A(1, 1) + A(3, 1) + A(5, 1)) / Total))

Abs(Int((A(1, 1) + A(3, 1) + A(5, 1)) / Total)) = Abs(Int((A(1, 1) + A(3, 1) + A(5, 1)) / A(7, 4))) = Abs(Int(((-1) + (-1) + (-1)) / 2)) = Abs(Int((-3) / 2)) = Abs(Int(-1.5)) = Abs(-2) = 2

 

C08.執行下列Visual Basic程式片段後,陣列元素A(3)的值為何? (A)3 (B)4 (C)6 (D)10[107商業]

Dim X, Y As Integer

Dim A(6) As Integer

For X = 1 To 6

  A(1) = 1: A(X) = 0

  For Y = X - 1 To 2 Step - 1

    A(Y) = A(Y - 1) + A(Y)

  Next Y

Next X

X

A(X)

Y

A(Y) = A(Y - 1) + A(Y)

1

A(1) = 0

0

 

2

A(1) = 1, A(2) = 0

1

 

3

A(1) = 1, A(3) = 0

2

A(2) = A(1) + A(2) = 1 + 0 = 1

4

A(1) = 1, A(4) = 0

3

A(3) = A(2) + A(3) = 1 + 0 = 1

 

 

2

A(2) = A(1) + A(2) = 1 + 1 = 2

5

A(1) = 1, A(5) = 0

4

A(4) = A(3) + A(4) = 1 + 0 = 1

 

 

3

A(3) = A(2) + A(3) = 2 + 1 = 3

 

 

2

A(2) = A(1) + A(2) = 1 + 2 = 3

6

A(1) = 1, A(6) = 0

5

A(5) = A(4) + A(5) = 1 + 0 = 1

 

 

4

A(4) = A(3) + A(4) = 3 + 1 = 4

 

 

3

A(3) = A(2) + A(3) = 3 + 3 = 6

 

 

2

A(2) = A(1) + A(2) = 1 + 3 = 4


【二技試題】

A01.在程式語言中,那一種資料結構屬於靜態,且於編譯(compile)期間就已決定所需記憶體空間? (A)陣列(array)結構 (B)鏈結串列(linked list)結構 (C)樹狀(tree)結構 (D)指標(pointer)結構。[93護理]

 

C02.一個二維陣列A(1:10, 1:10)採用以列為主(row major order)佈設方式,它的起始位址以十六進位表示為0X0001,而A(1, 5)這個元素的位址為0X0011,則A(3, 6)這個元素的位址為何? (A)0X0038 (B)0X0039 (C)0X0065 (D)0X0072[94電機]

 

B03.執行下列Visual Basic程式片段後,其顯示的結果為何? (A)9 (B)10 (C)11 (D)12[94管理]

Dim A(8) As Integer

For i = 1 To 8

 A(i) = i + 2

Next i

Print A(A(A(2) + 1) - 2) + 3

A(1)

A(2)

A(3)

A(4)

A(5)

A(6)

A(7)

A(8)

3

4

5

6

7

8

9

10

A(A(A(2) + 1) - 2) + 3 = A(A(4 + 1) - 2) + 3 = A(7 - 2) + 3 = 7 + 3 = 10

 

D04.函式自己呼叫自己的方法,稱為 (A)副程式 (B)排序 (C)搜尋 (D)遞迴。[96管理]

函數自己呼叫自己的方法,稱為遞迴。

 

C05.下列有關鏈結串列(linked list)與陣列(array)的比較,何者錯誤? (A)在概念上,鏈結串列可以無限制的加入元素(element),而陣列則受其本身大小的限制 (B)陣列中閒置的元素會造成空間的浪費,而鏈結串列在概念上可藉由刪除不需要的元素以解決此問題 (C)鏈結串列允許隨機存取(random access),而陣列則僅允許循序存取(sequential access) (D)在元素的型態與數目均相同的情況下,鏈結串列所使用的空間通常比陣列多。[96管理]

 

A06.下列SQL敘述所定義的資料表,其所代表之結構與何者最為類似?

CREATE TABLE x (

  id CHAR(10),

data VARCHAR(100),

p CHAR(10),

CONSTRAINT x_pk PRIMARY KEY (id),

CONSTRAINT x_fk FOREIGN KEY (p) REFERENCES x(id),

CONSTRAINT x_uk UNIQUE(p)); (A)鏈結串列(linked list) (B)(tree) (C)圖形(graph) (D)二維陣列(two-dimensional array)[96管理]

 

C07.下列何者可處理二維的一系列相同資料型態(data type)之資料? (A)字元(character) (B)位元(bit) (C)陣列(array) (D)資料欄(data field)[96護理]

 

D08.下列的Visual Basic函數,在執行Print I2J(3, 6)後,結果為何? (A)9 (B)12 (C)15 (D)18[97護理]

Private Function I2J(I As Integer, J As Integer)

 k = 0

 For a = I To J

3

4

5

6

  k = k + a

0 + 3 = 3

3 + 4 = 7

7 + 5 = 12

12 + 6 = 18 (傳回值)

 Next a

 I2J = k

End Function

 

D09.對資料的存取而言,有關鏈結串列(Linked List)與陣列(Array)之敘述,下列何者不正確? (A)陣列較鏈結串列節省記憶體空間 (B)欲隨機取得串列中任何資料,陣列比鏈結串列快 (C)鏈結串列要加入或刪除一個資料較陣列容易 (D)對於大量資料的處理,欲讀取全部資料,鏈結串列較陣列快。[98電機]

 

B10.電腦在處理運算式A - B/C時,若將其轉為後序(Postfix)式,可利用下列何種資料結構? (A)(Tree) (B)堆疊(Stack) (C)佇列(Queue) (D)鏈結串列(Linked List)[98電機]

 

D11.三維陣列A的宣告為A(3 To 20, -5 To 10, 2 To 15),若A(3, -5, 2)為其第一個元素,A(4, -5, 2)為第二個元素,則A(5, 6, 7)為第幾個元素? (A)1464 (B)1465 (C)1640 (D)1641[98管理]

以行為主(Column-major)方式

X = 20 - 3 + 1 = 18Y = 10 - (-5) + 1 = 16Z = 15 - 2 + 1 = 14

1 + (7 - 2) * 18 * 16 + [6 - (-5)] * 18 + (5 - 3) = 1641

 

B12.執行Microsoft Visual Basic指令Call S1(2)呼叫下列程式片段時,所印出的X值為何?

Sub S1 (ByVal X As Integer)

  Call S2 (X, X, X)

  Print X

End Sub

Sub S2 (ByRef A As Integer, ByVal B As Integer, ByRef C As Integer)

  A = A + 1: B = B + 2: C = A + B * C

End Sub (A)7 (B)15 (C)18 (D)23[98管理]

AC為傳址呼叫,B為傳值呼叫 ACX共同記憶體位址

A = A + 1 = 2 + 1 = 3B = B + 2 = 2 + 2 = 4C = 3 + 4 * 3 = 15

 

D13.執行下列Visual Basic程式片段的列印結果為何? (A)4 (B)6 (C)10 (D)20[98管理]

Dim A(3, 3) As Integer

For K = 0 To 3

  A(K, 0) = 1: A(0 , K) = 1

Next K

For K = 1 To 3

  For J = 1 To 3

    A(K, J) = A(K, J - 1) + A(K - 1, J)

  Next J

Next K

Print A(3, 3)

A(0, 0) = 1A(1, 0) = 1A(0, 1) = 1A(2, 0) = 1A(0, 2) = 1A(3, 0) = 1A(0, 3) = 1

K

J

A(K, J) = A(K, J - 1) + A(K - 1, J)

1

1

A(1, 1) = A(1, 0) + A(0, 1) = 1 + 1 = 2

2

A(1, 2) = A(1, 1) + A(0, 2) = 2 + 1 = 3

3

A(1, 3) = A(1, 2) + A(0, 3) = 3 + 1 = 4

2

1

A(2, 1) = A(2, 0) + A(1, 1) = 1 + 2 = 3

2

A(2, 2) = A(2, 1) + A(1, 2) = 3 + 3 = 6

3

A(2, 3) = A(2, 2) + A(1, 3) = 6 + 4 = 10

3

1

A(3, 1) = A(3, 0) + A(2, 1) = 1 + 3 = 4

2

A(3, 2) = A(3, 1) + A(2, 2) = 4 + 6 = 10

3

A(3, 3) = A(3, 2) + A(2, 3) = 10 + 10 = 20

 

B14.有一Visual Basic程式片段如下,在按下Command1鈕後,顯示的值為何? (A)1.461 (B)22.49 (C)22.50 (D)24.85[98護理]

Private Sub Command1_Click()

  Dim Weight, Height As Integer

  Weight = 65: Height = 170

  BMI = Weight / (Height / 100) ^ 2 65 / (170 / 100) ^ 2 = 22.49

  Print Mid(BMI, 1, 5)

End Sub

 

C15.欲設計程式以廣度優先搜尋(Breadth First Search)的方式,拜訪一個圖(Graph)中全部的頂點(Vertex),最合適使用哪種資料結構? (A) (B)堆疊 (C)佇列 (D)雜湊表。[99電機]

 

B16.當指標指向一單向鏈結串列(Singly Linked List)的某節點(Node)時,執行下列哪種動作效率最差? (A)更改此節點內的資料內容 (B)在此節點之前插入一新節點 (C)在此節點之後插入一新節點 (D)指標前進到此節點之下一節點。[99電機]

 

17.有一Visual Basic程式片段如下:

Private Sub Command1_Click()

  Sum = Total(200) - Total(100)

  Print Sum

End Sub

Private Function Total(i As Integer) As Long

  For j = 1 To i

    Total = Total + j

  Next j

End Function

B17-1.有關此程式片段之敘述,下列何者正確? (A)Function Total程式片段是一個遞迴程式 (B)Function Total程式片段是一個函數 (C)Total是一個位元組變數 (D)Total是一個整數變數。

D17-2.此程式片段執行後,有關Sum值之敘述,下列何者正確? (A)等於100 + 101 + ... + 199的和 (B)等於100 + 101 + ... + 200的和 (C)等於101 + 102 + ... + 199的和 (D)等於101 + 102 + ... + 200的和。[99管理]

 

A18.下列何種資料結構最適合用來記錄主程式呼叫副程式時,所需儲存的各種資訊? (A)堆疊 (B)佇列 (C)雙佇列 (D)二元樹。[99管理]

 

C19.陣列A(I1:J1, I2:J2),其中I1J1分別是陣列左方維度之註標下限及上限,I2J2則分別是陣列右方維度之註標下限及上限,下列何者正確? (A)陣列為2個一維陣列 (B)陣列個數為(J1 - I1 - 1) * (J2 - I2 - 1) (C)陣列位址可以利用「以列為優先」來計算 (D)陣列所需空間為(J1 - I1) * (J2 - I2) * uu為單位空間大小。[100管理]

 

A20.下列Visual Basic語言片段程式,將資料12345儲存到一個陣列中,然後將此資料依反序輸出54321,程式中的空白列為何? (A)A(I) = I (B)A(I) = I + 1 (C)I = I + 1 (D)A(I) = 1[100管理]

Dim A( 0 To 5) As Integer

Dim I As Integer

Dim Output As String

For I = 1 To 5

  _______

Next I

Output = ""

For I = 5 To 1 Step -1

  Output = Output & A(I) & " "

Next I

 


沒有留言:

張貼留言

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