题型:综合题 题类:常考题 难易度:困难
浙江省杭州市西湖高级中学2018-2019学年高二下学期信息技术5月月考试卷
小诗收集了全市部分教职员工的工资数据,设计了找中位数的程序如下。小诗收集的人员工资数据放在了Access数据库中。小诗的程序在窗体加载时读出了所有人员的数据:姓名放在数组a中,对应的工资放在数组b中,数据总记录数放在n中。单击按钮Command1后先以工资按非升的次序排序,然后找出中位数。
Dim a(1 To 1000) As String
Dim b(1 To 1000) As Single
Dim n As Integer
‘数据库读取所有人员的数据代码略
Private Sub Command1_Click()
Dim i As Integer , j As Integer , k As Integer
Dim tmp1 As Single, tmp2 As String
Dim median As Single
For i = n To 2 step -1
k = i
For j = i-1 To 1 step -1
If Then
k = j
End If
Next j
If k <> i Then
tmp1 = b(k): b(k) = b(i): b(i) = tmp1
tmp2 = a(k): a(k) = a(i): a(i) = tmp2
End If
Next i
For i = 1 To n
List1.AddItem Str(i) & " " & a(i) & " " & Str(b(i))
Next i
If n Mod 2 = 0 Then
median =
Else
median = b(n\2+1)
End If
Label1.Caption = "中位数是:" & Str(median)
End Sub
试题篮