为实现上述功能的程序如下,请在划线处填入合适的语句或代码。
Dim xm1(1 To 20) As String, xh1(1 To 20) As String′数组xm1、xh1分别存储选报课程1的学生的姓名和学号
Dim xm2(1 To 30) As String, xh2(1 To 30) As String′数组xm2、xh2分别存储选报课程2的学生的姓名和学号
Const n = 20, m = 30
Private Sub Form_Load()
'获取选报数据,并显示在列表框List1和List2中
'代码略
End Sub
Private Sub Command1_Click()
Dim i As Integer, j As Integer, tt As String
List2.Clear
For i = 1 To m - 1
For j =Step -1
If xm2(j) < xm2(j - 1) Then
tt = xm2(j): xm2(j) = xm2(j - 1): xm2(j - 1) = tt
tt = xh2(j): xh2(j) = xh2(j - 1): xh2(j - 1) = tt
End If
Next j
Next i
For i = 1 To m
List2.AddItem xh2(i) + “ ” + xm2(i)
Next i
End Sub
Private Sub Command2_Click()
Dim i As Integer, j As Integer, w As Integer, tt As String, k As Integer
For i = 1 To n
p = 1
Do While p <= q
w = (p + q) \ 2
If xm1(i) = xm2(w) Then
List3.AddItem xh1(i) + “ ” + xm1(i)
k = k + 1
End If
If Then
q = w - 1
Else
p = w + 1
End If
Loop
Next i
List3.AddItem “共有” + Str(k) + “ 位同学”
End Sub