用VB编制程序,计算某个学生奖学金的等级,以三门课程成绩为评奖依据

用VB编制程序,计算某个学生奖学金的等级,以三门课程成绩为评奖依据,第1张

Dim m1%, m2%, m3%, a As String, b As String

Private Sub Form_click()

m1 = InputBox("请输入第一门成绩")

m2 = InputBox("请输入第二门成绩")

m3 = InputBox("请输入第三门成绩")

a = (m1 = 100 And m2 = 100) Or (m1 = 100 And m3 = 100) Or (m2 = 100 And m3 = 100)

b = m1 = 100 Or m2 = 100 Or m3 = 100

x = 95: y = 90: z = 70

If (Val(m1) + Val(m2) + Val(m3)) / 3 >95 And a Then

Print "该生有评选一等见的资格"

ElseIf (Val(m1) + Val(m2) + Val(m3)) / 3 >90 And b Then

Print "该生有评选一等见的资格"

ElseIf 70 <= (Val(m1) + Val(m2) + Val(m3)) / 3 Then

Print "该生有评选一等见的资格"

Else

Print "该生无评选资格"

End If

End Sub

’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

Private Sub Form_Load()

    '// 添加数组控件label1 ;数组控件text1;command1;command2

    Dim i As Integer

    For i = 0 To 5

        Label1(i).Alignment = 1                                                 '// 标签右对齐

        Label1(i).Caption = Chr(65 + i) + ":"                                   '//标签标题

        Text1(i) = ""                                                           '//text清空

    Next

    Label2.Caption = "选手最后得分:"

    Label2.Alignment = 1

    Text2 = ""

    Command1.Caption = "得分"

    Command2.Caption = "清除"

End Sub

Private Sub Command1_Click()

    

    Dim i As Integer, a(5) As Single

    For i = 0 To 5

        If Text1(i) = "" Then Exit Sub: Exit For

        a(i) = Val(Text1(i))

    Next

    Text2 = px(a(), max%, min%)

    Text1(max).BackColor = vbRed

    Text1(min).BackColor = vbRed

End Sub

Private Sub Command2_Click()

    Dim i%

    For i = 0 To Text1.UBound

        Text1(i) = ""

        Text1(i).BackColor = vbWhite

    Next

    Text2 = ""

End Sub

Function px(a() As Single, max%, min%) As Single

    Dim i%, j%, k%, sum%, js%

    For i = 0 To UBound(a)

        If a(i) > max Then max = a(i): j = i

        If min > a(i) Then min = a(i): k = i

    Next

    max = j: a(max) = Empty

    min = k: a(min) = Empty

    For i = 0 To 5

        If a(i) <> Empty Then sum = sum + a(i): js = js + 1

    Next

    px = sum / js

End Function


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存