将考生原始成绩从高到低划分为A、B+、B、C+、C、D+、D、E共8个等级,各等级人数所占比例分别为3%、7%、16%、24%、24%、16%、7%、3%,如下表所示。
等级 |
A |
B+ |
B |
C+ |
C |
D+ |
D |
E |
比例 |
3% |
7% |
16% |
24% |
24% |
16% |
7% |
3% |
比如参加技术学考有20000人,小明卷面分90分,排名为1800名,则他在技术学科中的所处比例是9%。A占3%,B+占7%,因此B+所处的累积比例为4%-%10,可知他所处等级为B+。
编写一个VB程序计算学生某科目成绩的等级,功能如下:从数据库中读入学生学号、姓名、班级和原始成绩,并在列表框List1中显示,单击“等级划分”按钮Command1,在列表框List2中按原始成绩从高到低显示成绩与等级。等级划分时,先按原始成绩从高到低排序(如原始成绩相同,则按“班级”号从小到大排序),再根据人数比例计算切分位置确定等级。若切分位置有相同分数学生,则归为同一个等级。例如,某等级切分位置是第100位,但第101位学生的原始成绩和第100位相同,则这两名学生的赋分等级相同。程序运行界面如图a所示。
实现上述功能的VB程序如下,请回答下列问题:
Const max = 1000
Dim n As Integer '存放学生人数
Dim xh(1 To max) As String '数组xh存放学生的学籍号
Dim xm(1 To max) As String '数组xm存放学生的姓名
Dim bj(1 To max) As Integer '数组bj存放学生的班级
Dim fs(0 To max) As Single '数组fs存储学生的原始分数
Dim ffdj(0 To max) As String '数组ffdj存储学生的赋分等级
Private Sub Command1_Click()
Dim p(1 To 8) As Single, dj(1 To 8) As String
Dim i As Integer, j As Integer, pos As Integer, last As Integer
Dim st As String, it As Integer, sit As Single
‘从数据库中读入学生学号、姓名、班级和原始成绩,分别存入数组xh、xm、bj和fz中,代码略
p(1) = 0.03: p(2) = 0.07: p(3) = 0.16: p(4) = 0.24:p(5) = 0.24: p(6) = 0.16: p(7) = 0.07: p(8) = 0.03:dj(1) = "A": dj(2) = "B+": dj(3) = "B": dj(4) = "C+":dj(5) = "C": dj(6) = "D+": dj(7) = "D": dj(8) = "E"
For i = 2 To 8
'计算到该等级累计所占比例
Next i
For i = 1 To n - 1
For j = 1 To n - i
If Then
st = xh(j): xh(j) = xh(j + 1): xh(j + 1) = st
st = xm(j): xm(j) = xm(j + 1): xm(j + 1) = st
it = bj(j): bj(j) = bj(j + 1): bj(j + 1) = it
sit = fs(j): fs(j) = fs(j + 1): fs(j + 1) = sit
End If
Next j
Next i
pos = 1
For i = 1 To 8
last = '人数四舍五入取整
Do While fs(last + 1) = fs(last)
last = last + 1 '处理切分位置的同分数学生
Loop
Do While
ffdj(pos) = dj(i)
pos = pos + 1
Loop
Next i
For i = 1 To n
List2.AddItem xh(i) +" "+xm(i) +" "+Str(bj(i)) +" "+ Str(fs(i)) +" "+ ffdj(i)
Next i
End Sub