匿名使用者
匿名使用者 發問時間: 電腦與網際網路程式設計 · 1 0 年前

VB 排序

請問一下我的平均和總分都可以排序

能請大大幫我做學號和分數的排序嗎??

因為學號和分數不會跟著總分和平均排序!!

Dim student(,) = {{93001, "John", 89, 90, 77}, _

{93002, "Mary", 80, 95, 97}, _

{93003, "Bill", 88, 71, 71}, _

{93004, "tksg", 85, 77, 76}, _

{93005, "skyg", 97, 60, 78}}

Dim total_score(5), avg_score(5)

For i As Integer = 0 To 4

For j As Integer = 2 To 4

total_score(i) += student(i, j)

Next

Next

For i As Integer = 0 To 5

avg_score(i) = Math.Round(total_score(i) / 3)

Next

TextBox1.Text = "學號 姓名 數學 國文 英文 總分 平均" & vbCrLf

For i As Integer = 0 To 3

For j As Integer = i + 1 To 4

If avg_score(i) > avg_score(j) Then

Dim c As Integer = avg_score(i)

avg_score(i) = avg_score(j)

avg_score(j) = c

End If

Next

Next

For i As Integer = 0 To 3

For j As Integer = i + 1 To 4

If total_score(i) > total_score(j) Then

Dim c As Integer = total_score(i)

total_score(i) = total_score(j)

total_score(j) = c

End If

Next

Next

For i As Integer = 0 To 4

For j As Integer = 0 To 4

TextBox1.Text &= student(i, j) & " "

Next

TextBox1.Text &= total_score(i) & " "

TextBox1.Text &= avg_score(i) & vbCrLf

Next

1 個解答

評分
  • 屁德
    Lv 4
    1 0 年前
    最佳解答

    For i As Integer = 0 To 4

    For j As Integer = 0 To 4

    a(i) &= student(i, j) & " "

    Next

    a(i) &= total_score(i) & " "

    a(i) &= avg_score(i) & " " & vbCrLf

    Next

    For i As Integer = 0 To 3

    For j As Integer = i To 0 Step -1

    If avg_score(j) < avg_score(j + 1) Then

    Dim b As String = avg_score(j)

    avg_score(j) = avg_score(j + 1)

    avg_score(j + 1) = b

    Dim c As String = a(j)

    a(j) = a(j + 1)

    a(j + 1) = c

    End If

    Next

    Next

    For i As Integer = 4 To 0 Step -1

    TextBox1.Text &= a(i)

    Next

還有問題?馬上發問,尋求解答。