试题

试题 试卷

logo

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

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

有如下VB程序段:

For i= 1 To 49

  j=1:a(j)=a(j)+1

  Do While a(j)=5

    a(j)=0

    j = j + 1

    a(j) = a(j) + 1

  Loop

Next i

数组a中各元素初始值均为0,该程序执行后,数组a中各元素之和为(  )

A、9 B、0 C、3 D、49
举一反三
小明编写统计字符串中出现最多的字母和数字的程序。程序运行如下:在文本框Text1中输入一个仅包含字母和数字的字符串。单击按钮Command1后,在标签Label1上显示出现最多的数字字符,在标签Label2上显示出现最多的字母字符(字母不区分大小写,例如字母G和g统计在一起)。程序运行界面如图所示。

实现上述功能的VB程序如下,请在划线处填入合适的代码。

Private Sub Command1_Click()

Dim a(1 To 10) As Integer    ‘存储0~9每个数字出现的次数

Dim b(1 To 26) As Integer    ‘存储a~z每个字母出现的次数

Dim zf As String, x As String, p As Integer

Dim maxa As Integer, maxb As Integer

{#blank#}1{#/blank#}

For i = 1 To Len(zf)

 x = Mid(zf, i, 1)

 If pd(x) = 1 Then

  p = Asc(x) - Asc(“0”) + 1

  a(p) = a(p) + 1

  {#blank#}2{#/blank#}

  p = Asc(x) - Asc(“A”) + 1

  b(p) = b(p) + 1

 Else

  p = Asc(x) - Asc(“a”) + 1

  b(p) = b(p) + 1

 End If

Next i

k = a(1):maxa = 1

For i = 2 To 10

 If a(i) > k Then k = a(i):maxa = i

Next i

k = b(1) :maxb = 1

For i = 2 To 26

 If{#blank#}3{#/blank#}Then k = b(i) :maxb = i

Next i

Label1.Caption =“出现最多的数字是” + Chr(maxa+ Asc(“0”)-1)

Label2.Caption = “出现最多的字母是” + Chr(maxb + Asc(“A”)-1)

End Sub

Function pd(ch As String) As Integer ’函数用于判断每个字符类型

 If ch >= “0” And ch <= “9” Then pd = 2

 If ch >= “A” And ch <= “Z” Then pd = 2

 If ch >= “a” And ch <= “z” Then pd = 3

End Function

返回首页

试题篮