2018年春江蘇省計算機二級VB考試真題第1套 |
第1部分 公共基礎 略 第2部分 VB部分 1(單選題): 可以作為VB應用程序啟動對象的是______。 A. ①④ B. ①② C. ③④ D. ②③ D 解析:在VB中,能作為啟動對象的包括窗體模塊,sub main過程。 3 表達式37.6 Mod 5的結果數據類型為______。 A. 整型 B. 長整型 C. 單精度 D. 雙精度 B 解析:Mod運算符的作用是取余數,要求Mod左右兩邊都是整型或長整型,首先將雙精度類型37.6轉換為長整型38,然后再執行38 Mod 5,根據VB約定,兩個不同的類型的數值運算時返回的是占字節多的類型,因為長整型數值38占4個字節,整型5占2個字節,所以得到結果長整型3,如果直接寫 37 mod 5因為37與5都是整型,所以返回結果整型2 。 3 在多窗體程序中,僅用于將窗體Form2從內存中卸載的語句是______。 A. Form2.Unload B. Unload Form2 C. End D. Form2.Hide B 解析:A選項沒有這種寫法,C選項是結束整個程序運行,D選項是Form2隱藏。 2 下列關于Len函數的敘述,錯誤的是________。 A. 該函數可以接收數值型常量作為其參數 B. 該函數可以接收數值型變量作為其參數 C. 該函數可以接收字符型常量作為其參數 D. 若該函數的參數為非字符型變量,則其返回該類型變量所占用的存儲空間的大小 A 解析: 該函數不可以接收數值型常量作為其參數 。 3 Sub過程與Function過程最根本的區別是____。 A. Sub過程使用Call語句或直接使用過程名調用,而Function過程不可以 B. Function過程可以有參數,Sub過程不可以 C. 兩種過程參數的傳遞方式不同 D. Sub過程的過程名不能返回值,而Function可以 D 解析: Sub過程的過程名不能返回值,而Function過程名可以返回值是兩者最根本的區別。 7 6 (填空題 <2空> ) : 執行下面程序,單擊Command1按鈕,則a(1)的值是____________ ,a(4)的值是____________ 。 Option Explicit Option Base 1 Private Sub Command1_Click() Dim a(4) As Integer, i As Integer For i = 1 To 4 a(i) = F1(a, i) + a(i) Next i For i = 1 To 4 Print a(i) Next i End Sub Private Function F1(a() As Integer, x As Integer) As Integer Dim i As Integer If i Mod 2 <> 0 Then a(x) = x Else F1 = F1 + x End If End Function 1@4 解析: 因為文字描述不如視頻清晰,具體見視頻詳細講解 7 7 (填空題 <2空> ) : 執行下面程序,單擊Command1按鈕,則窗體上顯示的數組元素a(2)的值是____________ ,a(3)的值是____________ 。 Option Explicit Option Base 1 Private Sub Command1_Click() Dim a(3) As Integer, b As Integer, i As Integer For i = 1 To 3 a(i) = i Next i b = UBound(a) Call sub1(a, b) For i = 1 To 3 Print a(i); Next i End Sub Private Sub sub1(m() As Integer, n As Integer) If n > 1 Then m(n) = m(n) + n Call sub1(m, n - 1) End If End Sub 4@6 解析: 因為文字描述不如視頻清晰,具體見視頻詳細講解 7 8 (填空題 <3空> ) : 執行下面程序,單擊命令按鈕Command1,窗體上顯示的第一行內容是____________ ,a數組元素的個數是____________ ,其中a(2)的值是____________ 。 Option Explicit Option Base 1 Private Sub Command1_Click() Dim St As String, i As Integer Dim a() As String, j As Integer, k As Integer St = "abcd" Call Sub1(St) Print St For i = 1 To Len(St) For j = i + 1 To Len(St) If Mid(St, i, 1) = Mid(St, j, 1) Then Exit For Next j If j <= Len(St) Then k = k + 1 ReDim Preserve a(k) a(k) = Mid(St, i, 1) Print a(k) End If Next i End Sub Private Sub Sub1(S As String) Dim i As Integer For i = 1 To Len(S) \ 2 Mid(S, i, 1) = Mid(S, Len(S) - i + 1, 1) Next i End Sub dccd@2@c 解析: 因為文字描述不如視頻清晰,具體見視頻詳細講解 7 9 (填空題 <3空> ) : 執行下面程序,單擊命令按鈕Command1,則a(1,2)的值是____________ ,a(2,3)的值是____________ ,a(3,3)的值是____________ 。 Option Explicit Option Base 1 Private a(3, 3) As Integer Private Sub Form_Activate() Dim i As Integer, j As Integer, k As Integer k = 1 For i = 1 To 3 For j = 1 To 3 a(i, j) = k k = k + 1 Next j Next i End Sub Private Sub Command1_Click() Dim b(4) As Integer, i As Integer, j As Integer, t As Integer b(1) = 2 For i = 2 To 4 b(i) = i - 1 Next i t = a(b(1), b(4)) a(b(1), b(4)) = a(b(2), b(1)) a(b(2), b(1)) = a(b(3), b(2)) a(b(3), b(2)) = a(b(4), b(3)) a(b(4), b(3)) = t For i = 1 To 3 For j = 1 To 3 Print a(i, j); Next j Print Next i End Sub 4@2@9 解析: 因為文字描述不如視頻清晰,具體見視頻詳細講解 7 1(完善程序): 【要求】 1)打開T盤中“P1.vbp”文件,完善程序后,直接保存所有文件。 【題目】 下面程序的功能是,隨機生成10個不含數字0且由5位不同數字組成的整數,再將所生成的五位整數轉換為由組成該數的數字構成的最小整數后輸出。 Option Explicit Private Sub Command1_Click() Dim a(1 To 10) As Long, b(0 To 9) As Boolean, c(1 To 5) As Integer Dim i As Integer, j As Integer, k As Integer, n As Long For i = 1 To 10 n = Int(Rnd * 90000) + 10000 Erase b b(0) = True For j = 1 To 5 c(j) = Mid(n, j, 1) If b(c(j)) = False Then b(c(j)) = True Else (1) End If Next j If j = 6 Then Call Sort(c) For k = 1 To 5 a(i) = a(i) * 10 + c(k) Next k List1.AddItem a(i) Else (2) End If Next i End Sub Private Sub Sort(a() As Integer) Dim i As Integer, t As Integer, ub As Integer, f As Boolean ub = UBound(a) f = True Do While f (3) ub = ub - 1 For i = 1 To ub If a(i) > a(i + 1) Then f = True (4) a(i) = a(i + 1) a(i + 1) = t End If Next i Loop End Sub Exit For@i=i-1@f=false@t=a(i) (1)Exit For (2)i=i-1 (3)f=false (4)t=a(i) 因為文字描述不如視頻清晰,請查看自帶的本題目的視頻詳細講解 2(改錯題): 【要求】 (1)打開T盤中“P2.vbp”文件,按參考界面形式編輯窗體界面,改正程序中的錯誤后,直接保存所有文件; (2)改錯時,不得增加或刪除語句,但可適當調整語句位置。 【題目】本程序的功能是:生成一個4×4的數組,并根據數組中元素的大小生成一個標記數組。在標記數組中字母“L”表示數組的對應位置元素為最大,字母“S”表示隨組的對應位置元素為最。ㄈ舸嬖诙鄠相等的最大或最小元素也用字母“L”與“S”標記),其他非最大最小元素均用“0”表示。 Option Explicit Dim a(4, 4) As Variant, i As Integer, j As Integer Private Sub Command1_Click() For i = 1 To 4 For j = 1 To 4 a(i, j) = Int(Rnd * 90) + 10 Next j Next i Call printsz(Picture1) End Sub Private Sub Command2_Click() Dim Max As Integer, Min As Integer, a(4, 4) As Integer Max = 0 Min = 0 For i = 1 To 4 For j = 1 To 4 If a(i, j) > Max Then Max = a(i, j) If a(i, j) < Min Then Min = a(i, j) Next j Next i Call bj(Max, Min) End Sub Private Sub bj(m As Integer, n As Integer) For i = 1 To 4 For j = 1 To 4 If a(i, j) = m Then a(i, j) = L ElseIf a(i, j) = n Then a(i, j) = S Else a(i, j) = "0" End If Next j Next i Call printsz(Picture2) End Sub Private Sub printsz(pic As Control) pic.Cls For i = 1 To 4 For j = 1 To 4 pic.Print a(i, j); " "; Next j pic.Print Next i End Sub Dim Max As Integer, Min As Integer, a(4, 4) As Integer修改為Dim Max As Integer, Min As Integer@ Max = 0修改為Max=a(1,1) Min = 0修改為Min=a(1,1)@ a(i, j) = L修改為a(i, j) = “L”@ a(i, j) = S修改為a(i, j) = “S” (1)Dim Max As Integer, Min As Integer, a(4, 4) As Integer修改為Dim Max As Integer, Min As Integer@ (2)Max = 0修改為Max=a(1,1) Min = 0修改為Min=a(1,1) (3)a(i, j) = L修改為a(i, j) = “L” (4)a(i, j) = S修改為a(i, j) = “S” 因為文字描述不如視頻清晰,請查看自帶的本題目的視頻詳細講解 3(編程題): 【要求】 (1)打開T盤中“P3.vbp”文件,根據題目要求編寫和調試程序后,直接保存所有文件; (2)程序代碼書寫應呈鋸齒形,否則適當扣分。 【題目】 找出任意給定的兩個自然數的相同因子(因子中不包含1和該數本身)。 【編程要求】 (1)程序參考界面如圖所示,編程時不得增加或減少界面對象或改變對象的種類,窗體及界面元素大小適中,且均可見; (2)運行程序,單擊“查找”按鈕,根據文本框1和文本框2中給定的數字,分別求出它們除1和本身外的因子,并最終求出這兩個數的相同因子輸出在文本框3中,若兩個數沒有相同因子,則在文本框3中輸出”沒有相同因子”;單擊“退出”按鈕,則結束程序運行; (3)程序中必須包含一個求因子的通用過程。 Option Explicit Option Base 1 Private Sub Command1_Click() Dim a() As Integer, b() As Integer, c() As Integer Dim n1 As Integer, n2 As Integer Dim i As Integer, j As Integer, k As Integer n1 = Text1.Text n2 = Text2.Text Call yinzi(n1, a) Call yinzi(n2, b) For i = 1 To UBound(a) For j = 1 To UBound(b) If a(i) = b(j) Then k = k + 1 ReDim Preserve c(k) c(k) = a(i) End If Next j Next i Text3.Text = n1 & "的因子: " For i = 1 To UBound(a) Text3.Text = Text3.Text & a(i) & " " Next i Text3.Text = Text3.Text & vbCrLf Text3.Text = Text3.Text & n2 & "的因子: " For i = 1 To UBound(b) Text3.Text = Text3.Text & b(i) & " " Next i Text3.Text = Text3.Text & vbCrLf If k = 0 Then Text3.Text = Text3.Text & "沒有相同的因子數:" Else Text3.Text = Text3.Text & "相同的因子數:" For i = 1 To UBound(c) Text3.Text = Text3.Text & c(i) & " " Next i End If End Sub Private Sub Command2_Click() End End Sub Private Sub yinzi(n As Integer, c() As Integer) Dim i As Integer, k As Integer For i = 2 To n - 1 If n Mod i = 0 Then k = k + 1 ReDim Preserve c(k) c(k) = i End If Next i End Sub 因為文字描述不如視頻清晰,請查看自帶的本題目的視頻詳細講解
|