题目

编写VB程序统计单词个数。要求:在文本框Text1中输入英语短文,单击“统计”按钮,单词的个数显示在Text2中(假定每个单词仅包含英文字母)。程序界面如图所示,按此要求编写程序如下: Function Stod(ch As String)As String   Dim n As Integer, i As Integer   Dims As String, st As String   For i=1 To Len(ch)     s=Mid(ch, i, 1)     If s>="a" Ands<="z" Then       s=Chr(Asc(s)-32)     End If     ______________     Stod=st   Next i End Function Private Sub Command1_Click()   Dim article, f As String, s1, s2 As String   Dim i As Integer, m As Integer   Dim flag As Boolean   article=Stod(Text1. Text):f=Stod(Text2. Text)   m=0:flag=False   For i=1 To Len(article)     y=Mid(article, i, 1)     If y>="A"Andy<="Z"Then         If flag=False Then             s1=             s2=Mid(article, i+Len(f), 1)             If s1=f And Not(s2>="A" And s2<="Z") Then               m=m+1           End If           flag=True       End If     Else       flag=False     End If   Next i   Label2.Caption="单词"+Text2.Text+“出现"+Str(m)+"次" End Sub (1) 要在文本框Text1中输入这段英文内容,需要修改Text1的属性值(单选,填字母:A .Caption/B .Text/C .Font/D .Height)。 (2) 请将程序代码中的画线处语句补充完整。 (3) 程序代码中的加框处有误,请改正。 (4) 程序代码中,flag=表示一个单词的开始,即当前字一个单词的首字母。 答案: 【1】B st =st +s Mid(article,i,Len(f)) 【1】False
信息技术 试题推荐
最近更新