下列说法不正确的是( )
Private Sub Command1_Click()
Dim a As Integer
a = Val(Text1.Text)
Text1.Text = Str(Sqr(a))
End Sub
程序运行时,单击命令按钮Command1后弹出如图所示的错误信息提示。出现错误的原因可能是( )
For i = 1 To 2
k = i
For j = i + 1 To 7
If a(j) < a(k) Then k = j
Next j
If i <> k Then
t = a(i) : a(i) = a(k) : a(k) = t
End If
Next i
数组元素a(1)到a(7)的值依次为“19,85,86,90,24,22,62”,经过该程序段“加工”后,数组元素a(1)到a(7)的值依次为( )
key = Val(Text1.Text)
i = 1: j = 10
Do While i <= j
m = (i + j) \ 2
If Then
Text2.Text = "在第" + Str(m) + "个"
Exit Do 'Exit Do 表示退出循环
ElseIf Then
i = m + 1
Else
End If
Loop
If i >j Then Text2.Text = "找不到目标"
上述程序中方框处可选语句为:
①i = m - 1 ②j = m – 1 ③d(m) = key ④d(m) > key ⑤d(m) < key
则(1)、(2)、(3)处语句依次是( )
i = 1
Do While i <= 6
t = Int(Rnd * 10) + 1
If t Mod 2 = i Mod 2 Then a(i) = t : i = i + 1
Loop
For i = 1 To 2
k = 1
For j = 1 To 6 - i * 2
If a(j) * k > a(j + 2) * k Then
t = a(j) : a(j) = a(j + 2) : a(j + 2) = t
End If
k = -k
Next j
Next i
执行该程序段后,数组元素a(1)到a(6)的值可能是( )
图1
图2
实现上述功能的VB程序如下,请回答下列问题:
Function zf(s As String) As Boolean
zf = False
If s >= "A" And s <= "Z" Or s >= "a" And s <= "z" Then
①
End If
End Function
Private Sub rev_Click()
Dim s As String, ch As String, rv As String, rv1 As String
Dim i As Integer, j As Integer, k As Integer
s = Text1.Text
rv = "" : i = 1
Do While True
ch = Mid(s, i, 1)
Do While Not zf(ch) And i < Len(s)
rv = rv + ch
i = i + 1
ch = Mid(s, i, 1)
Loop
j = i
ch = Mid(s, j, 1)
Do While zf(ch) And j <= Len(s)
②
If j > Len(s) Then Exit Do
ch = Mid(s, j, 1)
Loop
rv1 = ""
For '改错
rv1 = Mid(s,k,1)+rv1
Next k
rv = rv + rv1
If j <= Len(s) Then rv = rv + Mid(s, j, 1)
i = j + 1
If i > Len(s) Then Exit Do
Loop
Text2.Text = rv
End Sub
① ②
程序设计过程中数据的存储和计算方法如下:
⑴学生体能分数的存储:如图2所示,第1位学生的游泳、跑步、跳远分数依次存入数组score的第1、2、3个元素里,第2位学生的游泳、跑步、跳远分数依次存入数组score的第4、5、6个元素里,以此类推。
⑵计算名次的算法:先统计每个分数的个数,存入数组a,如图3中a(96)值为9,表示共有9个96分;然后按照分数从高到低依次计算每个有效分数(该分数的个数不为0)对应的名次存入数组b,分数相同时名次并列,如图3中b(96)值为10,表示96分的名次是(并列)第10名,以此类推。
请回答下列问题:
Dim m As Integer ' 学生人数
Dim score(1 To 3000) As Integer ' 存放学生分数
Dim xm(1 To 1000) As String ' 存放学生姓名
Private Sub Command1_Click()
Dim i As Integer, t As Integer, code As Integer, mc As Integer
Dim a(0 To 100) As Integer '存放每个分数的个数
Dim b(0 To 100) As Integer '存放每个分数的名次
Dim code_n(1 To 3) As String
code_n(1) = "游泳" : code_n(2) = "跑步" : code_n(3) = "跳远"
code = Val(Text1.Text)
For i = 0 To 100
a(i) = 0
Next i
sum = 0
For i = 1 To m '计算每个分数的个数及体能测试优秀的人数
t = ①
a(score(t)) = a(score(t)) + 1
If score(t) >= 90 Then sum = sum + 1
Next i
mc = 1
For i = 100 To 0 Step -1 '计算每个分数的名次
If a(i) <> 0 Then
b(i) = mc
mc = ②
End If
Next i
List2.Clear
List2.AddItem " 姓名 " + ③ + " 名次"
For i = 1 To m
'在List2中输出m个学生的姓名、指定项目的分数及名次,代码略
Next i
sum = Int(sum / m * 10000 + 0.5) / 100
Label2.Caption = "优秀率是:" + Str(sum) +"%"
End Sub
Private Sub Form_Load()
’从数据库读取姓名存入数组xm,体能测试数据存入数组score,总人数存入变量m。
’代码略
End Sub
①②③