试题

试题 试卷

logo

题型:单选题 题类:常考题 难易度:普通

浙江省金华市江南中学2020届高三下学期信息技术4月初测试卷

有如下VB程序段,已知a数组各元素值为“7,5,6,3,1,8”,b数组各元素的初始值为“0”。则经过以下程序段处理后,b数组各元素分别为(  )

For i = 1 To 5

 k = i

 For j = i + 1 To 6

  If a(k) > a(j) Then k = j

 Next j

 t = a(k): a(k) = a(i): a(i) = t

 b((i + 2) Mod 6 + 1) = a(i)

Next i

A、1 3 5 6 7 8 B、7 0 1 3 5 6 C、6 7 8 1 3 5 D、6 7 0 1 3 5
举一反三
【加试题】字符串排序。编写VB程序,实现如下功能:程序运行时,单击命令按钮Command1 产生100个随机字符串(每个字符串长度不超过10),并显示在列表框List1中,单击命令按钮Command2对产生的100个随机字符串按权值进行降序排序,将排序结果显示在列表框List2中。每个字符串的权值定义为该字符串中ASCII码值最大的字母的ASCII码值,例如字符串“Hello”中ASCII码值最大的字母是“o”(ASCII码值为111),则字符串“Hello”的权值为111。程序运行效果如图所示。实现上述功能的VB代码如下,但加框处代码有错,请改正。

Dim a(1 To 100) As String '依次存放100 个随机字符串

Dim b(1 To 100) As Integer '依次存放每个字符串的权值

Private Sub Command1_Click() '产生100 个随机字符串

Dim i As Integer, k As Integer, t As Integer, x As Integer

Randomize

For i = 1 To 100

k = Int(Rnd * 10 + 1) : t = 0  'k 表示第i 个字符串的长度

Do While t < k '通过循环依次产生第i 个字符串a(i)的k 个字符

If Int(Rnd * 2 + 1) = 1 Then '产生一个小写字母的ASCII 码值

x = Asc("a") + Int(Rnd * 26)

Else

x = Asc("A") + Int(Rnd * 26) '产生一个大写字母的ASCII 码值

End If

                '①

If b(i) < x Then b(i) = x

t = t + 1

Loop

List1.AddItem a(i)

Next i

End Sub

Private Sub Command2_Click() '对100 个字符串按字符串权值降序排序

Dim i As Integer, j As Integer, y As Integer

Dim s As String

For i = 1 To 99

k = i

For j = i + 1 To 100

    '②

Next j

If k <> i Then

s = a(k): a(k) = a(i): a(i) = s

y = b(k): b(k) = b(i): b(i) = y

End If

Next i

For i = 1 To 100

List2.AddItem a(i)

Next i

End Sub

①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#} 

返回首页

试题篮