1个回答
展开全部
Option Base 1 Private Sub Command1_Click() Dim re() As record ReDim re(n) Dim i% Open "d:\stud1.dat" For Append As #1 For i = 1 To n re(i).Nu = InputBox("请输入学号!") re(i).Na = InputBox("请输入姓名!") re(i).Ma = InputBox("请输入数学成绩!") re(i).Ch = InputBox("请输入化学成绩!") re(i).Co = InputBox("请输入计算机成绩!") Write #1, re(i).Nu, re(i).Na, re(i).Ma, re(i).Ch, re(i).Co Next Close #1 End Sub Private Sub Command2_Click() Dim re() As record, su() As Integer, av() As Single Dim i%, j%, k%, temp%, temp1% ReDim re(n + 1), su(n + 1), av(n + 1) Kill "d:\stud2.dat" Form1.Cls Open "d:\stud1.dat" For Input As #1 For i = 1 To n + 1 Input #1, re(i).Nu, re(i).Na, re(i).Ma, re(i).Ch, re(i).Co Next Close #1 For i = 2 To n + 1 su(i) = re(i).Ma + re(i).Ch + re(i).Co av(i) = su(i) / 3 Next i For i = 2 To n k = i + 1 For j = k To n + 1 If su(i) < su(j) Then temp = su(i): su(i) = su(j): su(j) = temp temp1 = re(i).Nu: re(i).Nu = re(j).Nu: re(j).Nu = temp1 temp1 = re(i).Na: re(i).Na = re(j).Na: re(j).Na = temp1 temp1 = re(i).Ma: re(i).Ma = re(j).Ma: re(j).Ma = temp1 temp1 = re(i).Ch: re(i).Ch = re(j).Ch: re(j).Ch = temp1 temp1 = re(i).Co: re(i).Co = re(j).Co: re(j).Co = temp1 temp = av(i): av(i) = av(j): av(j) = temp End If Next j Next i Open "d:\stud2.dat" For Append As #2 Write #2, "学号", "姓名", "数学", "化学", "计算机", "平均分", "总分" Print "学号", "姓名", "数学", "化学", "计算机", "平均分", "总分" For i = 2 To n + 1 Write #2, re(i).Nu, re(i).Na, re(i).Ma, re(i).Ch, re(i).Co, av(i), su(i) Print re(i).Nu, re(i).Na, re(i).Ma, re(i).Ch, re(i).Co, av(i), su(i) Next i Close #2 End Sub
求采纳
求采纳
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询