题型:综合题 题类:常考题 难易度:困难
浙江省台州市直高中共享发展共同体2018-2019学年高二下学期信息技术5月月考试卷
实现上述功能的VB程序如下,请回答下列问题:
Dim sName(100) As String
Dim kh(100) as string
Private Sub Command1_Click()
Dim y As Integer
Dim start As Integer '考场第1位数据元素的下标
Dim pa As Integer '数据库导入VB时学生数据下标
Dim pb As Integer '考场座位数据下标
Dim i As Integer,j As Integer,k As Integer,m As Integer
Dim kcsName(100) As String
start = 1
pa = start
recCount = x-1
If recCount Mod 30 <> 0 Then
For i = 1 To y ‘将当前考生人数添加到30的整数倍
recCount = recCount +1
sName(recCount) = " "
Next i
End If
For j = 1 To recCount / 30
pa = start
pb = start
For i = 1 To 30
kcsName(pb) = sName(pa)
pb = pb +1
If i Mod 5 = 0 Then
pa = start +i \5
Else
End If
Next i
start = start +30
Next j
Text1.Text = " "
start = 1
For k = 1 To recCount /30
m = start
Text1.Text = Text1.Text + "第" + Str(k) + "考场" + vbCrLf
'vbCrLf为换行标志符,实现Text1中内容换行显示
For i = 1 To 6
For j = 1 To 5
Text1.Text = Text1.Text +" " +kcsName(m)
m = m +1
Next j
Text1.Text = Text1.Text +vbCrLf
Next i
Text1.Text = Text1.Text +vbCrLf +vbCrLf
Next k
End Sub
Private Sub form_load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
conn.ConnectionString = "provider=microsoft.ace.oledb.12.0;data source=" & App.Path & "/kaochang.accdb"
conn.Open
Set rs.ActiveConnection = conn
rs.Open "select * from banji"
x = 1
List1.AddItem " 考号 姓名"
Do While Not rs.EOF '
kh(x) = rs.fields("kh")
sName(x) = rs.fields("xm")
List1.AddItem kh(x) + " " + sName(x)
x = x + 1
rs.MoveNext
Loop
rs.Close
End Sub
⑴预处理。用数组a存放不同的分值,数组b存放相同分数的人数,数组s存放高于此分数的人数,数组下标表示名次。依次从数据库读取每个学生的成绩(数据库中每个学生的成绩已降序存储,即从高到低排列),当读入数与前一个数相同时,该名次的人数加1,当读入数与前一个数不同时,名次加1,即数组下标加1,存储当前分数,求高于本分数的人数并存储。
举例:如果数据库中有一组成绩(降序):95,95,93,93,92,91,90,按上述算法处理,三个数组的最终结果如图所示。
数组/下标 | 1 | 2 | 3 | 4 | 5 |
a | 95 | 93 | 92 | 91 | 90 |
b | 2 | 2 | 1 | 1 | 1 |
s | 0 | 2 | 4 | 5 | 6 |
⑵对需要查找的成绩二分查找。读入需要查找的成绩x,在数组a中二分查找成绩,若找到,输出名次、相同分数的人数和高于本分数的人数;若找不到,输出“查无此分”。
程序代码如下,在横线处填入合适的代码。
Dim rank As Integer
Dim a(1 to 1000) As Integer ‘存放不同的分数值
Dim b(1 to 1000) As Integer ‘存放相同分数的人数
Dim s(1 to 1000) As Integer ‘存放高于此分数的人数
rank=0
Private Sub Form_Load()
Dim conn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim tmp As Integer, n As Integer
tmp=-1: n=0
conn.ConnectionString=“provider=Microsoft.ACE.OLEDB.12.0;data source=“App.Path+”Score.accdb”
conn.open
Set rs.ActiveConnection=conn
rs.open “Select * from score”
n=0
Do While Not rs.EOF
n=n+1
mark=rs.fields(“成绩”)
If mark=tmp Then ‘当前读入分数与上一个分数相同,则对应名次的人数增加1
b(rank)=b(rank)+1
Else ‘当前读入分数与上一个分数不同时
rank={#blank#}1{#/blank#} ‘名次增加1
a(rank)={#blank#}2{#/blank#} ‘存储当前分数到数组a中
s(rank)={#blank#}3{#/blank#} ‘求高于本分数的人数并存储至数组s
b(rank)=1 ‘将自身统计入同分人数
End If
{#blank#}4{#/blank#} ‘更新上一个分数
rs.Movenext
Loop
End Sub
Private Sub Command1_Click()
Dim x As Integer, low As Integer, high As Integer, mid As Integer
x=Val(Text1.Text)
low=1: high=rank
mid=(low+high)\ 2
Do While low <=high and {#blank#}5{#/blank#}
mid=(low+high)\ 2
If a(mid) < x Then
high=mid-1
Else
low=mid+1
End If
Loop
If a(mid)=x Then
Label1.Caption=“名次:“+mid+”同分人数:“+b(mid)+”高于此分人数:”+s(mid)
Else
Label1.Caption=“查无此分”
End If
End Sub
试题篮