题型:综合题 题类:常考题 难易度:困难
浙江省绍兴市诸暨中学2017-2018学年高二下学期信息技术期中考试试卷
实现上述功能的VB程序如下,但加框处代码有错,请改正。
Const n = 10
Dim a(1 To n) As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, t As Integer, bottom As Integer
'获取排序前数据依次存储在数组a 中,并在文本框Text1 中显示。代码略
bottom = n : i = 1
Do While i <= bottom - 1
For j = bottom To i + 1 Step -1
If Then ‘⑴
t = a(j): a(j) = a(j - 1): a(j - 1) = t
ElseIf a(j) = a(j - 1) Then ' 相邻两个数据相等,进行剔除处理
‘⑵
bottom = bottom - 1
End If
Next j
i = i + 1
Loop
Text2.Text = " "
For i = 1 To bottom
Text2.Text = Text2.Text + Str(a(i))
Next i
End Sub
⑴ ⑵
例如,有如下年龄存在数组a中:
a(1) | a(2) | a(3) | a(4) | a(5) | a(6) | a(7) | a(8) | a(9) | a(10) |
20 | 19 | 18 | 19 | 15 | 12 | 15 | 20 | 17 | 19 |
利用一个数组b(b(10 To 20))记录每个数出现的次数:
b(10) | b(11) | b(12) | b(13) | b(14) | b(15) | b(16) | b(17) | b(18) | b(19) | b(20) |
0 | 0 | 1 | 0 | 0 | 2 | 0 | 1 | 1 | 3 | 2 |
根据数组b对数组a进行排序:
a(1) | a(2) | a(3) | a(4) | a(5) | a(6) | a(7) | a(8) | a(9) | a(10) |
12 | 15 | 15 | 17 | 18 | 19 | 19 | 19 | 20 | 20 |
Dim a(10000) As Integer ‘存放读入的年龄数据
Dim b(100) As Integer ‘存放各个年龄出现的个数
Private Sub Command1_Click()
‘从数据库读入年龄数据放入数组a中
End Sub
Private Sub Command2_Click()
For i = 1 To 100
b(i) = 0
Next i
For i = 1 To 10000 ‘统计每个年龄数据的个数
①
Next i
End Sub
Private Sub Command3_Click()
j = 0
For i = 1 To 100
If b(i) <> 0 Then
Do While b(i) <> 0
②
a(j) = i
‘③
Loop
End If
Next i
For i = 1 To 10000
List2.AddItem Str(a(i))
Next i
End Sub
试题篮