vb随机生成30个学生的成绩,并按照成绩和学号排序?
展开全部
’随机生成学号及分数
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
List1.Items.Clear()
Dim B As Integer
For B = 1 To 30
stdscore(B, 2) = Int(Rnd() * 90) + 10
stdscore(B, 1) = B
List1.Items.Add(" " & stdscore(B, 1) & " " & stdscore(B, 2))
Next B
End Sub
‘下面是按照分数排序
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim j, k As Integer
Dim maxl, mank As Integer
List1.Items.Clear()
For k = 1 To 30
For j = 1 To 30 - k
If stdscore(j, 2) < stdscore(j + 1, 2) Then
maxl = stdscore(j + 1, 1)
mank = stdscore(j + 1, 2)
stdscore(j + 1, 2) = stdscore(j, 2)
stdscore(j + 1, 1) = stdscore(j, 1)
stdscore(j, 2) = mank
stdscore(j, 1) = maxl
End If
Next j
Next k
For k = 1 To 30
List1.Items.Add(" " & stdscore(k, 1) & " " & stdscore(k, 2))
Next
End Sub
'下面是按照学号排序
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim j, k As Integer
Dim maxl, mank As Integer
List1.Items.Clear()
For k = 1 To 30
For j = 1 To 30 - k
If stdscore(j, 1) > stdscore(j + 1, 1) Then
maxl = stdscore(j + 1, 1)
mank = stdscore(j + 1, 2)
stdscore(j + 1, 2) = stdscore(j, 2)
stdscore(j + 1, 1) = stdscore(j, 1)
stdscore(j, 2) = mank
stdscore(j, 1) = maxl
End If
Next j
Next k
For k = 1 To 30
List1.Items.Add(" " & stdscore(k, 1) & " " & stdscore(k, 2))
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询