当前位置: 高中信息技术 / 综合题
  • 1. 小明用VB编写了统计短文(不超过500字)中英语单词频次的程序。在文本框Text1中输入短文,单击“单词统计”按钮Count后,在列表框List1中按字典升序输出单词(不区分大小写)和出现频次,程序运行结果如图所示。

    请回答下列问题:

    1. (1) 观察程序代码,该事件处理过程名为
    2. (2) 实现上述功能的 VB 程序如下,请在划线处填入合适的代码。

      Private Sub Count_Click()

          Dim word(1 To 500) As String, num(1 To 500) As Integer

          Dim s As String, c As String, tmp As String, t As Integer

          Dim i As Integer, j As Integer, k As Integer, low As Integer, high As Integer

          Dim m As Integer, n As Integer, b As Integer

          For i = 1 To 500

              num(i) = 0

          Next i

          s = Text1.Text : n = Len(s)

          i = 1 : b = 1 : m = 0 : j = 0

          Do While i <= n

              c = Mid(s, i, 1)

              If c >= "A" And c <= "Z" Or c >= "a" And c <= "z" Then

                  j = j + 1

              Else

                  If j > 0 Then

                      tmp = 

                      low = 1

                      high = m

                      Do While low <= high

                          t = (low + high) \ 2

                          If tmp = word(t) Then

                              Exit Do

                          If tmp < word(t) Then

                              high = t - 1

                          Else

                              low = t + 1

                      Loop

                      If   Then

                          For k = m To low Step -1

                              word(k + 1) = word(k)

                              num(k + 1) = num(k)

                          Next k
                           

                          num(low) = 1

                          m = m + 1

                      Else

                          num(t) = num(t) + 1

                      End If

                      j = 0

                  End If

                  b = i + 1

              End If

              i = i + 1

          Loop

          List1.Clear

          For i = 1 To m

              List1.AddItem word(i) + ":" + Str(num(i)) + "次"

          Next i

      End Sub

      Function Lowcase(t As String) As String

          Dim c As String, s As String, i As Integer

          s = ""

          For i = 1 To Len(t)

              c = Mid(t, i, 1)

              If c >= "A" And c <= "Z" Then s = s + Chr(Asc(c) + 32) Else s = s + c

          Next i

           

      End Function

微信扫码预览、分享更方便