编一个VB程序,30个选手,10个评委,0~10 分,去掉最高分与最低分,求平均分,并将选手成绩排名

编一个VB程序,30个选手,10个评委,0~10 分,去掉最高分与最低分,求平均分,并将选手成绩排名,第1张

看以下代码是否合用[ 先要建立一个TextBox 和 一个Command ]:

Private Sub Command1_Click()

Dim 运动员成绩(1 To 30, 1 To 10) As Double '30人,10个成绩评分.

Dim 运动员平均成绩(1 To 30) As Double, 中介数组(1 To 10) As Double

Dim 最低分 As Double, 最高分 As Double, 合计分数 As Double

'各运动员随机给分.

Text1.Text = "各运动员成绩:" &vbCrLf

Dim 随机值, 上限, 下限

上限 = 10

下限 = 0

随机值 = Int((上限 - 下限 + 1) * Rnd(Second(Now)) + 下限)

For i = 1 To 30

For j = 1 To 10

运动员成绩(i, j) = Int((上限 - 下限 + 1) * Rnd(Second(Now)) + 下限)

Next

Text1.Text = Text1.Text &运动员成绩(i, 1) &" " &运动员成绩(i, 2) &" " &运动员成绩(i, 3) &" " &运动员成绩(i, 4) &" " &运动员成绩(i, 5) &" " &_

运动员成绩(i, 6) &" " &运动员成绩(i, 7) &" " &运动员成绩(i, 8) &" " &运动员成绩(i, 9) &" " &运动员成绩(i, 10) &vbCrLf

Next

'计算各运动员的成绩

Text1.Text = Text1.Text &"各运动员平均成绩:" &vbCrLf

For i = 1 To 30

合计分数 = 0

For j = 1 To 10

中介数组(j) = 运动员成绩(i, j)

合计分数 = 合计分数 + 中介数组(j)

If j = 10 Then

最低分 = Max(中介数组)

最高分 = Min(中介数组)

运动员平均成绩(i) = (合计分数 - 最低分 - 最高分) / 8

End If

Next

Text1.Text = Text1.Text &运动员平均成绩(i) &vbCrLf

Next

'按成绩排序

Text1.Text = Text1.Text &"组序后成绩:" &vbCrLf

Call 排序(运动员平均成绩)

For i = 1 To 30

Text1.Text = Text1.Text &运动员平均成绩(i) &vbCrLf

Next

End Sub

Public Sub 排序(List() As Double)

Dim First As Double, Last As Double

Dim i As Integer, j As Integer

Dim Temp As Double

First = LBound(List)

Last = UBound(List)

For i = First To Last - 1

For j = i + 1 To Last

If List(i) >List(j) Then

Temp = List(j)

List(j) = List(i)

List(i) = Temp

End If

Next j

Next i

End Sub

Public Function Max(输入() As Double) As Double

Dim First As Double, Last As Double

Dim i As Integer, j As Integer

Dim Temp As Double

First = LBound(输入)

Last = UBound(输入)

For i = First To Last - 1

For j = i + 1 To Last

If 输入(i) >输入(j) Then

Temp = 输入(j)

输入(j) = 输入(i)

输入(i) = Temp

End If

Next j

Next i

Max = 输入(i)

End Function

Public Function Min(输入() As Double) As Double

Dim First As Double, Last As Double

Dim i As Integer, j As Integer

Dim Temp As Double

First = LBound(输入)

Last = UBound(输入)

For i = First To Last - 1

For j = i + 1 To Last

If 输入(i) >输入(j) Then

Temp = 输入(j)

输入(j) = 输入(i)

输入(i) = Temp

End If

Next j

Next i

Min = 输入(1)

End Function

’3个label,2个command

Private Sub Command1_Click()

Dim s, i, j, arr(1 To 10), t, sum

For i = 1 To 10

s = InputBox("输入评分(0-10分):", "第" &i &"个分数")

If IsNumeric(s) Then

s = Val(s)

If s <0 Or s >10 Then

i = i - 1

Else

arr(i) = s

End If

Else

i = i - 1

End If

Next

For i = 1 To 9

For j = i + 1 To 10

If arr(i) >arr(j) Then

t = arr(i): arr(i) = arr(j): arr(j) = t

End If

Next

Next

For i = 2 To 9

sum = sum + arr(i)

Next

Label1.Caption = "最高分为:" &arr(10)

Label2.Caption = "最低分为:" &arr(1)

Label3.Caption = "选手最后得分:" &Round(sum / 8, 1)

End Sub

Private Sub Command2_Click()

Unload Me

End Sub

Private Sub Form_Load()

Command1.Caption = "评分"

Command2.Caption = "结束"

With Label1

.Caption = ""

.AutoSize = True

End With

With Label2

.Caption = ""

.AutoSize = True

End With

With Label3

.Caption = ""

.AutoSize = True

End With

End Sub

Option Base 0

Dim s(5, 10) As Single

Dim str1 As String

Private Sub Command1_Click() '输入选手成绩

i = Val(InputBox("请输入先手抽签号(1-5)"))

If i <1 Or i >5 Then Exit Sub

s(i, 0) = i

For j = 1 To 6

s(i, j) = Val(InputBox("请输入 " &j &"号裁判的打分(10分)"))

If s(i, j) >10 Or s(i, j) <0 Then j = j - 1

Next j

smin = 10

smax = 0

ss = 0

str2 = s(i, 0) &Chr(9)

For j = 1 To 6

str2 = str2 &CStr(s(i, j)) &Chr(9)

ss = ss + s(i, j)

If s(i, j) >smax Then smax = s(i, j)

If s(i, j) <smin Then smin = s(i, j)

Next j

s(i, 7) = smin

s(i, 8) = smax

s(i, 9) = (ss - smin - smax) / 4

Print str1

Print str2 &s(i, 7) &Chr(9) &s(i, 8) &Chr(9) &s(i, 9) &Chr(9)

End Sub

Private Sub Command2_Click()

Print "选手排名"

n = Val(InputBox("要列出前几名", , 5))

Dim temp(1 To 5) As Single

For i = 1 To 5

temp(i) = s(i, 9)

Next i

For i = 1 To 4

For j = i To 5

If temp(i) <temp(j) Then

t = temp(i)

temp(i) = temp(j)

temp(j) = t

End If

Next j

Next i

For i = 1 To 5

For j = 1 To 5

If temp(i) = s(j, 9) Then s(j, 10) = i

Next j

Next i

Print str1

For i = 1 To n

For j = 1 To 5

If s(j, 10) = i Then

For k = 0 To 10

Str3 = Str3 &s(j, k) &Chr(9)

Next k

End If

Next j

Print Str3

Str3 = ""

Next i

End Sub

Private Sub Form_Load()

str1 = "抽签号" &Chr(9)

For i = 1 To 6

str1 = str1 &"裁判" &i &Chr(9)

Next i

str1 = str1 &"最低分" &Chr(9) &"最高分" &Chr(9) &"平均分" &Chr(9) &"排名"

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7866664.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存