修改时间:2021-05-20 浏览次数:149 类型:期末考试
Private Sub Command1_Click()
Dim s As Integer, b As Integer
s = 0: b = a(1) + 1
For i = 2 To n
Next i
Label1.Caption = Str(s)
End Sub
Function max(x As Integer, y As Integer)
If x > y Then Else
End Function
方框中的代码由以下四部分组成:
①max = y ②max = x ③b = max(b, a(i) + i) ④s = max(s, a(i) - i + b)
代码顺序正确的是( )
m = Int(Rnd * 4 + 2)
For i = 1 To 6 - m
For j = 1 To 6 - i
If a(j) - a(j + 1) < 0 Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
数组元素a(1)到 a(6)的值依次为“49,45,5,61,42,71”,执行该程序段后,a(1)~a(6)各元素值不可能的是( )
Key = Val(Text1.Text)
i = 1: j = 10: c = 0
Do While i <= j
m = (i + j) \ 2
c = c + 1
If a(m) >= Key Then j = m – 1 Else i = m + 1
Loop
Text2.Text = Str(c) + Str(i) + Str(j) + Str(m)
数组元素a(1)至a(10)的值依次为“8,10,12,15,15,15,21,34,45,66”。在文本框Text1中输入数值15,执行该程序段后,文本框Text2中显示的内容是( )
请回答下列问题:
请回答下列问题:
Dim a(1 To 100) As Integer, n As Integer
Private Sub Form_Load()
'本过程从数据库中读取n个IP地址区间数据,并依次存入数组a(1)、…、a(2*n)中
'对能通过过滤的IP区间按区间起始端点升序排序
'代码略
End Sub
Private Sub Cmd1_Click()
Dim ip As Integer, L As Integer, R As Integer
Dim i As Integer, pos As Integer, f As Boolean
ip = Val(Text1.Text)
L = a(1): R = a(2): i = 3: pos = 1 ‘合并重叠区间
Do While i <= 2 * n - 1
If Then
If a(i + 1) > R Then R = a(i + 1)
Else
a(2 * pos - 1) = L:a(2 * pos) = R
pos = pos + 1
L = a(i)
R = a(i + 1)
End If
Loop
a(2 * pos - 1) = L: a(2 * pos) = R '依次输出排序合并后的区间数据,代码略
If Then '判断请求的 IP 地址
Label4.Caption = "IP 需过滤"
Else
i = 1: f = False
Do While i <= pos And Not f
If Then
i = i + 1
Else
Label4.Caption = "IP 不需过滤" f = True
End If
Loop
If f = False Then Label4.Caption = "IP 需过滤"
End If
End Sub
编写“商品销售统计”程序功能如下:窗体加载时从数据库中读取商品的相关数据,对各商品类别总销量及名次进行统计,结果在列表框List1中显示;单击“查询”按钮Command1,按商品类别编号从小到大排列,同一类别商品按销量从大到小排序,在列表框List2中显示。程序运行界面如图c所示。
Dim a(1 To 2000) As Integer, b(1 To 2000) As Integer, s(1 To 2000) As Integer
Dim gid(1 To 100) As Integer, t(1 To 2000) As Integer
Dim c(1 To 2000) As String, gtype(1 To 100) As String
Dim ts(1 To 100) As Integer '数组 ts 存储每个类别商品总销量
Dim k(1 To 2000) As Integer '数组 k 存储每个类别商品总数
Dim m As Integer, n As Integer
Private Sub Form_Load()
'从数据库读取 m 条记录中类别编号、商品类别数据分别存储在数组 gid、gtype 中
'从数据库读取n 条记录中类别编号、商品名称、商品销量数据分别存储在数组 b、c、s中,代码略
For i = 1 To n '统计各类别商品总销量及商品总数
k(b(i)) = k(b(i)) + 1
Next i
For i = 1 To m '计算各类别商品总销量的名次
p = 0
For j = 1 To m
If ts(i) < ts(j) Then p = p + 1
mc(i) = p + 1
Next j
Next i
List1.AddItem "类别 销量 名次"
For i = 1 To m
List1.AddItem gtype(i) + " " + Str(ts(i)) + " " + Str(mc(i))
Next i
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, pos As Integer, tmp As Integer, p As Integer
p = 1
For i = 1 To m
a(i) = p
p = p + k(i)
Next i
For i = 1 To n
p = b(i)
t(a(p)) = i
a(p) = a(p) + 1
Next i
pos = 1
For i = 1 To m '对各类别商品按商品销量进行排序
For j = pos To pos + k(i) - 2
tmp =t(j): t(j) = t(p): t(p) = tmp
Next j
pos = pos + k(i)
Next i
List2.AddItem "类别 商品 商品销量"
For i = 1 To n
List2.AddItem + " " + geshi(c(t(i))) + " " +Str(s(t(i)))
Next i
End Sub
Function f(head As Integer, tail As Integer) As Integer
Dim i As Integer, p As Integer
p = head - 1
For i = head To tail
If s(t(i)) > s(t(p)) Then p = i
Next i
f = p
End Function
Function geshi(s As String) As String '格式输出,代码略
End Function
试题篮