VB程序设计中,有10个分数,怎样输入一个除去最大值、最小值,求平均值的程序?急!
有十个text1,里边是输入分数的,还有一个text2里要输入除去一个最大值、一个最小值后的平均分数,在command里怎么设计这个程序?...
有十个text1,里边是输入分数的,还有一个text2里要输入除去一个最大值、一个最小值后的平均分数,在command里怎么设计这个程序?
展开
2个回答
展开全部
先在窗体上放一个text1,在界面将text1的index属性值设为0,这样我们就创建了一个textbox控件数组,用复制粘贴的办法再添加9个成员
再在窗体上放3个按纽控件,代码如下:
Option Explicit: Dim a(9) As Integer, s As Double, max As Integer, min As Integer
Private Sub Command1_Click()
a(0) = Val(Text1(0).Text): a(1) = Val(Text1(1).Text): a(2) = Val(Text1(2).Text): a(3) = Val(Text1(3).Text): a(4) = Val(Text1(4).Text): a(5) = Val(Text1(5).Text): a(6) = Val(Text1(6).Text): a(7) = Val(Text1(7).Text): a(8) = Val(Text1(8).Text): a(9) = Val(Text1(9).Text)
If a(0) < a(1) Then min = a(0) Else min = a(1)
If min > a(2) Then min = a(2)
If min > a(3) Then min = a(3)
If min > a(4) Then min = a(4)
If min > a(5) Then min = a(5)
If min > a(6) Then min = a(6)
If min > a(7) Then min = a(7)
If min > a(8) Then min = a(8)
If min > a(9) Then min = a(9)
If a(0) > a(1) Then max = a(0) Else max = a(1)
If max < a(2) Then max = a(2)
If max < a(3) Then max = a(3)
If max < a(4) Then max = a(4)
If max < a(5) Then max = a(5)
If max < a(6) Then max = a(6)
If max < a(7) Then max = a(7)
If max < a(8) Then max = a(8)
If max < a(9) Then max = a(9)
s = (a(0) + a(1) + a(2) + a(3) + a(4) + a(5) + a(6) + a(7) + a(8) + a(9) - max - min) / 8
Text2.Text = s
End Sub
Private Sub Command2_Click()
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Text1(3).Text = ""
Text1(4).Text = ""
Text1(5).Text = ""
Text1(6).Text = ""
Text1(7).Text = ""
Text1(8).Text = ""
Text1(9).Text = ""
Text2.Text = ""
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Text1(3).Text = ""
Text1(4).Text = ""
Text1(5).Text = ""
Text1(6).Text = ""
Text1(7).Text = ""
Text1(8).Text = ""
Text1(9).Text = ""
Text2.Text = ""
Command1.Caption = "计算平均分数"
Command2.Caption = "清空"
Command3.Caption = "退出"
End Sub
再在窗体上放3个按纽控件,代码如下:
Option Explicit: Dim a(9) As Integer, s As Double, max As Integer, min As Integer
Private Sub Command1_Click()
a(0) = Val(Text1(0).Text): a(1) = Val(Text1(1).Text): a(2) = Val(Text1(2).Text): a(3) = Val(Text1(3).Text): a(4) = Val(Text1(4).Text): a(5) = Val(Text1(5).Text): a(6) = Val(Text1(6).Text): a(7) = Val(Text1(7).Text): a(8) = Val(Text1(8).Text): a(9) = Val(Text1(9).Text)
If a(0) < a(1) Then min = a(0) Else min = a(1)
If min > a(2) Then min = a(2)
If min > a(3) Then min = a(3)
If min > a(4) Then min = a(4)
If min > a(5) Then min = a(5)
If min > a(6) Then min = a(6)
If min > a(7) Then min = a(7)
If min > a(8) Then min = a(8)
If min > a(9) Then min = a(9)
If a(0) > a(1) Then max = a(0) Else max = a(1)
If max < a(2) Then max = a(2)
If max < a(3) Then max = a(3)
If max < a(4) Then max = a(4)
If max < a(5) Then max = a(5)
If max < a(6) Then max = a(6)
If max < a(7) Then max = a(7)
If max < a(8) Then max = a(8)
If max < a(9) Then max = a(9)
s = (a(0) + a(1) + a(2) + a(3) + a(4) + a(5) + a(6) + a(7) + a(8) + a(9) - max - min) / 8
Text2.Text = s
End Sub
Private Sub Command2_Click()
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Text1(3).Text = ""
Text1(4).Text = ""
Text1(5).Text = ""
Text1(6).Text = ""
Text1(7).Text = ""
Text1(8).Text = ""
Text1(9).Text = ""
Text2.Text = ""
End Sub
Private Sub Command3_Click()
Unload Me
End Sub
Private Sub Form_Load()
Text1(0).Text = ""
Text1(1).Text = ""
Text1(2).Text = ""
Text1(3).Text = ""
Text1(4).Text = ""
Text1(5).Text = ""
Text1(6).Text = ""
Text1(7).Text = ""
Text1(8).Text = ""
Text1(9).Text = ""
Text2.Text = ""
Command1.Caption = "计算平均分数"
Command2.Caption = "清空"
Command3.Caption = "退出"
End Sub
展开全部
先排序
定义十个数的数组
Dim a(10) As Integer
maxa = a(1)
For i = 1 To 10
If a(i) > maxa Then
maxa = a(i)
End If
Next i
Text2.Text = maxa
求最大值...
For i = 1 To 9
For j = i + 1 To 10
If a(i) < a(j) Then
x = a(i): a(i) = a(j): a(j) = x
End If
Next j
Next i
Text1 = ""
For i = 1 To 10
Text1.Text = Text1.Text & a(i) & " "
Next i
求最小一样..
然后去掉两个后求各,求平均就行了.
定义十个数的数组
Dim a(10) As Integer
maxa = a(1)
For i = 1 To 10
If a(i) > maxa Then
maxa = a(i)
End If
Next i
Text2.Text = maxa
求最大值...
For i = 1 To 9
For j = i + 1 To 10
If a(i) < a(j) Then
x = a(i): a(i) = a(j): a(j) = x
End If
Next j
Next i
Text1 = ""
For i = 1 To 10
Text1.Text = Text1.Text & a(i) & " "
Next i
求最小一样..
然后去掉两个后求各,求平均就行了.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询