题型:综合题 题类:模拟题 难易度:普通
浙江省杭州市2016年信息技术高考模拟卷八
按指定格式录入数据,例:0373,张乐晓,3.90。编号宽度固定为4位,姓名宽度固定为3个汉字,不足部分以全角空格补齐,第9个字符开始为跳远成绩。
在文本框按回车表示录入一项数据结束,录入的数据经处理后编号、姓名、成绩分别存放在数组编号bh、xm、cj中并将原始数据显示在List1中。
点击命令按钮Command1后进行排序并将排序后的结果显示在List2中。
程序运行界面如图所示。
Dim bh(1 To 8) As String
Dim xm(1 To 8) As String
Dim cj(1 To 8) As Single
Dim num As Integer
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer, tmp_1 As String, tmp_2 As Single
For i = 1 To 7
k = i
For j = k + 1 To 8
If Then k = j
Next j
If k <> i Then
tmp_1 = bh(k): bh(k) = bh(i): bh(i) = tmp_1
tmp_1 = xm(k): xm(k) = xm(i): xm(i) = tmp_1
tmp_2 = cj(k): cj(k) = cj(i): cj(i) = tmp_2
End If
Next i
For i = 1 To 8
List2.AddItem bh(i) & xm(i) & Str(cj(i))
Next i
End Sub
Private Sub Form_Load()
num = 0
End Sub
Private Sub sr_txt_Keypress(KeyAscii As Integer)
Dim srsj As String '输入数据
If KeyAscii = 13 Then
num = num + 1
srsj = sr_txt.Text
bh(num) = Mid(srsj, 1, 4)
xm(num) = Mid(srsj, 6, 3)
cj(num) =
List1.AddItem srsj
If num = 8 Then num = 0
End If
End Sub
排序前 |
86 |
71 |
5 |
41 |
81 |
79 |
37 |
89 |
排序后 |
5 |
37 |
41 |
71 |
79 |
89 |
86 |
81 |
实现上述功能的VB代码如下,但加框处有错,请改正。
Const n=8
Dim a(1 To n)As Integer
Private Sub Commandl_Click()
Dim i As Integer,j As Integer,k As Integer,t As Integer
Dim flag As Boolean
'读取一组正整数,存储在数组a中,代码略
For i= 1 To n-1
'(1)
If IsPrime(a(k))Then flag = True Else flag = False
For j = i + 1 To n
If IsPrime(a(j)) Then
If Then '(2)
k=j
flag = True
End If
End If
Next j
If k <> i Then
t=a(k):a(k)= a(i):a(i)= t
End If
If Not flag Then Exit For 'Exit For表示退出循环
Next i
'依次输出排序后的数据。代码略
End Sub
Function IsPrime(m As Integer)As Boolean
'本函数判断m是不是素数:是素数返回值为True,不是素数返回值为False
'代码略
End Function
⑴{#blank#}1{#/blank#} ⑵{#blank#}2{#/blank#}
试题篮