题型:综合题 题类:模拟题 难易度:困难
浙江省杭州市2016年信息技术高考模拟卷九
部分程序代码如下:
Public number As String '货物编号
Public na As String '货物名称
Public co As String '货物数量
Private Sub Command1Click()
Dim flag As Integer '查询结果标志
number = Text1.Text
na = Text2.Text
co = Text3.Text
If (number = "" And na = "" And co = "") Then MsgBox ("你还没有输入查询条件") ’第一种情况
If number <> ""Then ’第二种情况
flag = searchnum(1, n) 'n 表示总的货物种类数量
List1.AddItem id(flag) + n(flag) + c(flag)
If flag = -1 Then MsgBox ("查询无结果,检查是否输入有误")
End If
If na <> "" Then ‘第三种情况
flag = searchna(1, n) 'n 表示总的货物种类数量
List1.AddItem id(flag) + n(flag) + c(flag)
If flag = -1 Then MsgBox ("查询无结果,检查是否输入有误")
End If
If co <> "" Then ‘第四种情况
flag = searchco(1, n)
If flag = 0 Then MsgBox ("查询无结果,检查是否输入有误")
End If
End Sub
Function searchnum(i, j) As Integer '按编号查询函数
Dim m As Integer
Do While i <= j
m = Fix((i + j) / 2)
If id(m) = number Then
searchnum = m: Exit Function '查询到结果返回值并结束该函数
End If
If id(m) > number Then ① Else i = m + 1
Loop
searchnum = -1
End Function
Function searchna(i, j) As Integer '按名称查询函数
For i = 1 To j Step 1
If n(i) = na Then searchna = i: Exit Function
Next i
searchna = -1
End Function
Function searchco(i, j) As Integer '按货物数量函数
Dim f As Integer
f = 0
For i = 1 To j Step 1
If ② Then
List1.AddItem id(i) + n(i) + c(i)
f = 1
End If
Next i
searchco (f)
End Function
回答下列问题:
a(1) |
a(2) |
a(3) |
…… |
a(n —2) |
a(n—1) |
a(n) |
3 |
25 |
38 |
…… |
55 |
31 |
12 |
依据对分查找思想,设计一个在数组a中查找数据key的程序。实现该功能的VB程序如下,但加框处代码有错,请改正。
Private Sub Command1_Click()
Const n = 6
Dim a(1 To n)As Integer,flag As Boolean
Dim i As Integer,j As Integer,m As Integer,key As Integer
'读取一组正整数,按上述规则存入数组a中,代码略。
key = VaKText1. Text)
i = 1
j = (n + 1) \ 2
flag = False
Do While And Not flag ‘①
m = (i + j) \ 2
If key = a(m) Then
flag = True
ElseIf key< a(m) Then
j = m - 1
Else
i = m + 1
End If
Loop
If Not flag And j > 0 Then
m = ‘②
If key = a(m) Then flag = True
End If
If flag Then
Text2. Text = Str(m)
Else
Text2. Text = "找不到"
End If
End Sub
①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#}
试题篮