VB实验,急等,谢谢
发布网友
发布时间:2023-11-05 14:48
我来回答
共1个回答
热心网友
时间:2024-12-04 14:00
Dim Interval(4) As String
Private Sub Command1_Click()
Me.Cls
Randomize (Timer)
Const StudentNumber = 20
Dim Score(StudentNumber - 1) As Single, FixedLength(StudentNumber - 1) As String
Dim ScoreMax As Single, ScoreMin As Single, Average As Single
Dim Interval_PeopleNumber(4) As Single
Dim Interval_PeopleCount(10) As Single
Dim FixedLen(4) As String
ScoreMax = 0: ScoreMin = 100
Call InitialValue(Interval_PeopleNumber)
Call InitialValue(Interval_PeopleCount)
For i = LBound(Score) To UBound(Score)
Score(i) = Int(Rnd(i + 1) * 101)
Interval_PeopleCount(Score(i) \ 10) = Interval_PeopleCount(Score(i) \ 10) + 1
s = s + Score(i)
If Score(i) > ScoreMax Then ScoreMax = Score(i)
If Score(i) < ScoreMin Then ScoreMin = Score(i)
Next i
Call ConversionFormat(Score, FixedLength)
Call PrintArray(FixedLength)
Print
Average = s / 20
Print " 最高分 ="; ScoreMax & Space(2) & "最低分 ="; ScoreMin & Space(2) & "平均分 ="; Average
Print
For i = LBound(Interval_PeopleCount) To UBound(Interval_PeopleCount) - 5
Interval_PeopleNumber(0) = Interval_PeopleNumber(0) + Interval_PeopleCount(i)
Next i
For i = LBound(Interval_PeopleNumber) + 1 To UBound(Interval_PeopleNumber) - 1
Interval_PeopleNumber(i) = Interval_PeopleCount(i + 5)
Next i
Interval_PeopleNumber(UBound(Interval_PeopleNumber)) = Interval_PeopleCount(UBound(Interval_PeopleCount)) + Interval_PeopleCount(UBound(Interval_PeopleCount) - 1)
Call ConversionFormat(Interval_PeopleNumber, FixedLen)
For i = LBound(Interval_PeopleNumber) To UBound(Interval_PeopleNumber)
Print Tab(10); Interval(i), FixedLen(i)
Next i
Print
Call Sort(Score)
Call ConversionFormat(Score, FixedLength)
Call PrintArray(FixedLength)
End Sub
Private Sub Form_Load()
Interval(0) = "[0,60)"
Interval(1) = "[60,70)"
Interval(2) = "[70,80)"
Interval(3) = "[80,90)"
Interval(4) = "[90,100)"
End Sub
Private Sub Sort(ByRef Arr() As Single)
For i = LBound(Arr) To UBound(Arr) - 1
For j = i + 1 To UBound(Arr)
If Arr(j) > Arr(i) Then
t = Arr(i)
Arr(i) = Arr(j)
Arr(j) = t
End If
Next j
Next i
End Sub
Private Sub ConversionFormat(ByRef Arr1() As Single, Arr2() As String)
For i = LBound(Arr1) To UBound(Arr1)
If Arr1(i) < 10 Then
Arr2(i) = Space(2) + CStr(Arr1(i))
ElseIf Arr1(i) < 100 Then
Arr2(i) = Space(1) + CStr(Arr1(i))
Else
Arr2(i) = CStr(Arr1(i))
End If
Next i
End Sub
Private Sub PrintArray(ByRef Arr() As String)
For i = LBound(Arr) To UBound(Arr)
Print Arr(i) + Space(1);
If (i + 1) Mod 10 = 0 Then Print
Next i
End Sub
Private Sub InitialValue(ByRef Arr() As Single)
For i = LBound(Arr) To UBound(Arr)
Arr(i) = 0
Next i
End Sub