```vb
Private Sub btnConvert_Click()
Dim score As Integer
score = CInt(txtScore.Text)
If score >= 90 And score <= 100 Then
lblGrade.Caption = "A"
ElseIf score >= 80 Then
lblGrade.Caption = "B"
ElseIf score >= 70 Then
lblGrade.Caption = "C"
ElseIf score >= 60 Then
lblGrade.Caption = "D"
Else
lblGrade.Caption = "E"
End If
End Sub
```
此程序首先从名为 `txtScore` 的文本框中读取用户输入的百分制分数,并将其转换为整数类型。然后根据分数范围分别判断对应的五级分制分数,并将结果显示在名为 `lblGrade` 的标签中。
注意,在此示例代码中并未进行任何错误处理,例如用户输入非法字符或超出分数范围等情况需要自行处理。
dim i as integerdim sum as single
dim Mymax as single
dim Mymin as single
dim MyAvg as single
dim x as single
x=val(inputbox("输入第1个成绩:"))
sum=x
Mymax=x
Mymin=x
for i=2 to 10
x=val(inputbox("输入第" &i &"个成绩:"))
sum = sum + x
if x>Mymax Then Mymax =x
if x<Mymin Then Mymin =x
next i
MyAvg = sum /10
print "最高分:"Mymax
print "最低分:"Mymin
print "平均分:"MyAvg
Private Sub Main()Dim Scores(1 To 10) As Single
Call InputScore(Scores)
Call PrintScore(Scores)
Call AboveAverage(Scores)
Call ScoreSort(Scores)
Call PrintScore(Scores)
Call FindMaxMin(Scores)
End Sub
Private Sub InputScore(sngScores() As Single)
Dim i As Single
For i = LBound(sngScores) To UBound(sngScores)
sngScores(i) = InputBox("请输入第" & i & "名学生高考成绩:", "高考成绩管理系统", 600)
Next i
End Sub
Private Sub PrintScore(sngScores() As Single)
Dim i As Integer
Load Form1
Form1.Show
For i = LBound(sngScores) To UBound(sngScores)
Form1.Print sngScores(i)
Next i
Form1.Print
End Sub
Private Sub ScoreSort(sngScores() As Single)
Dim i As Integer, j As Integer, t As Single
For i = LBound(sngScores) To UBound(sngScores) - 1
For j = i + 1 To UBound(sngScores)
If sngScores(j) > sngScores(i) Then
t = sngScores(i)
sngScores(i) = sngScores(j)
sngScores(j) = t
End If
Next j
Next i
End Sub
Private Sub AboveAverage(sngScores() As Single)
Dim i As Integer, k As Integer, sngSum As Single, sngAverage As Single
For i = LBound(sngScores) To UBound(sngScores)
sngSum = sngSum + sngScores(i)
Next i
sngAverage = sngSum / UBound(sngScores)
For i = LBound(sngScores) To UBound(sngScores)
If sngScores(i) > sngAverage Then
k = k + 1
End If
Next i
Form1.Print "平均值为:" sngAverage,
Form1.Print "高于平均值的人数为:" k
End Sub
Private Sub FindMaxMin(sngScores() As Single)
Dim i As Integer, sngMax As Single, sngMin As Single
sngMax = sngScores(LBound(sngScores))
sngMin = sngScores(LBound(sngScores))
For i = LBound(sngScores) + 1 To UBound(sngScores)
If sngScores(i) > sngMax Then sngMax = sngScores(i)
If sngScores(i) < sngMin Then sngMin = sngScores(i)
Next i
Form1.Print "最高分为:" sngMax, "最低分为:" sngMin
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)