浙江科技学院考试试卷
2. 下面程序用来验证哥德巴赫猜想:一个大于等于6的偶数可以表示为两个素数
之和。其中判断素数的功能利用函数prime来解决。 Private Sub Command3_Click()
Dim n As Integer, n1 As Integer, n2 As Integer n = Val(InputBox(\输入一个大于等于6的偶数\ For n1 = 3 To n \\ 2 Step 2 n2 = n - n1
If ________(4)________ Then Print n; \ End If Next n1 End Sub
Public Function prime(x As Integer) ________(5)________ Dim i As Integer ________(6)________ For i = 2 To Int(Sqr(x)) If x Mod i = 0 Then prime = False Exit For End If Next i End Function
(4)(A)prime(n1, n2)
(B)prime(n1) And prime(n2) (D)prime(n1) Or prime(n2) (B)As Boolean (D)As Long (B)prime = True
(D)Dim Prime As Boolean
(C)prime(n1, n2) = n (5)(A)As Integer (C)%
(6)(A)Dim x As Integer (C)prime = False
第 5 页 共 15 页
浙江科技学院考试试卷
3. 下面的程序是一个金曲榜程序。运行界面和具体要求如下:列表框显示榜单。
选择歌曲名后,“↑”和“↓”按钮分别用于提升和降低歌曲名次;“←”和“→”按钮分别用于进榜和出榜。
Private Sub cmdUp_Click() ? '此处代码省略 End Sub
Private Sub cmdDown_Click()
'下降名次按钮
'上升名次按钮
Dim i As Integer, t As String ________(7)________ If i = -1 Then
MsgBox \请先选择歌名\
ElseIf i <> List1.ListCount - 1 Then t = List1.List(i)
List1.List(i) = List1.List(i + 1) List1.List(i + 1) = t List1.ListIndex = i + 1 End If End Sub
Private Sub cmdIn_Click()
'进榜按钮
Dim song As String, i As Integer song = Text1 i = Val(Text2)
第 6 页 共 15 页
浙江科技学院考试试卷
If song <> \ ________(8)________ Else
MsgBox \输入有误!\ End If End Sub
Private Sub cmdOut_Click()
'出榜按钮
Dim i As Integer, t As String i = List1.ListIndex If i = -1 Then
MsgBox \请先选择歌名\ Else
________(9)________ End If End Sub
(7)(A)i = List1.ListIndex
(C)i = Val(Text1)
(B)i = List1.ListCount (D)i = List1.ListCount-1
(8)(A)List1.AddItem song, i – 1 (B)List1.AddItem song, i + 1 (C)List1.AddItem song, I (9)(A)List1.RemoveItem i
(C)List1.Remove i
(D)List1.AddItem song (B)List1.Clear (D)List1.Kill i
4. 已知一个递增的数组,输入一个整数,将其插入到数组中,保持数组任然有序。
插入的操作由函数insert完成。 Private Sub Command4_Click() Dim a(), x%, i%
a = Array(1, 3, 5, 6, 7, 15, 36, 88, 90) x = Val(InputBox(\输入要插入的数\ ________(10)________
第 7 页 共 15 页
浙江科技学院考试试卷
For i = LBound(a) To UBound(a) Print a(i); Next i Print End Sub
Public Sub insert(a(), x As Integer) Dim i%, p%, q% p = LBound(a) q = UBound(a)
________(11)________ For i = q To p Step -1 If x <= a(i) Then a(i + 1) = a(i) If i = 0 Then a(i) = x Else
________(12)________ Exit For End If Next i End Sub
(10)(A)insert(a, x) (C)insert a, x (11)(A)q = q + 1
(B)ReDim Preserve a(p To q) (C)ReDim Preserve a(p To q + 1) (D)ReDim a(1 To q) (12)(A)a(i) = x
(B)a(i) = a(i + 1) (D)a(i - 1) = a(i)
(B)a = insert(x) (D)Call insert
(C)a(i + 1) = x
第 8 页 共 15 页