题目

小王用VB编写一个自动统计英文字母和单词个数的程序。功能如下:在文本框Text1中输入任意的英文句子,单击 “统计”命令按钮Command1,程序自动统计出每个字母出现的频率,并将其输出到列表框List1,且将出现次数最多的字母输出在标签Label1中,另外将单词个数在标签label2中输出。程序界面如图所示,实现上述功能的VB程序如下。请回答以下问题: (1) 请在划线处填入合适的代码。 Private Sub Command1_Click()   Dim a(65 To 122) As Integer   Dim i As Integer, ch As String, count As Integer   Dim Max As Integer, Maxi As Integer, flag As Boolean   List1.Clear   flag = False   count = 0   s = Text1.Text   For i = 1 To Len(s)      ch = Mid(s, i, 1)      If ch>= "a" And ch<= "z" Or ch>= "A" And ch<= "Z" Then         a(Asc(ch)) =         If flag = False Then            count = count + 1            flag = True         End If      Else              End If   Next i   Max = 0: Maxi = 0   For i = 65 To 122     ’A的ASCII码值为65,a的ASCII码值为97     If a(i) > 0 Then         List1.AddItem Chr(i) + ":  " + Str(a(i))     End If     If a(i) > Max Then        Max = a(i)        Maxi = i     End If   Next i   Label1.Caption = "频率最高字母:" +    Label2.Caption = "共有单词数:" + Str(count) + "个" End Sub (2) 从代码可知,当出现两个以上的字母次数最高时(例如字母a和d都出现4次,且为最高次数),则程序最终输出的是(单选,填写字母:A .排在前面的第一个频率最高字母/B .中间的某个频率最高字母/C .排在最后的一个频率最高字母/D .无法确定)。 答案: 【1】a(Asc(ch))+1【2】flag = False【3】Chr(Maxi) 【1】A
信息技术 试题推荐
最近更新