设有下面程序代码: Private Sub Command1_Click() Dim str As String,ch As String str="Visual Basic Programming":ch="a" n=fun(ch,str):Print

admin2020-04-18  26

问题 设有下面程序代码:
Private Sub Command1_Click()
Dim str As String,ch As String
str="Visual Basic Programming":ch="a"
n=fun(ch,str):Print str,n
End Sub
Privat eFunction fun(ch As String,str As String)As Integer
Dim strbuf As String,c As String,n As Integer
For k=1 To Len(str)
c=Mid$(str,k,1)
If c<>ch Then
strbuf=strbuf & c
Else
strbuf=strbuf & UCase(c):n=n+1
End If
Next k
str=strbuf:fun=n
End Function
程序运行时的输出是

选项 A、Visual Basic Programming0
B、VisuAl BAsic ProgrAmming3
C、Visul Bsic Progrmming3
D、VisualBasicProgramming2

答案B

解析 本题中函数fun除了有返回值外,还通过地址传递的形参str带回修改以后的字符串。在函数中会依次遍历整个字符串,每一次取得一个字符,判断该字符和给定的参数“a”是否相等,如果不等则将其原样连接,否则将此字符转换成大写字符以后连接,而且令计数器加1。所以整个函数的功能就是将形参s仃中所有等于形参ch的字符转换成大写,并且统计这类字符的个数作为函数返回值。
转载请注明原文地址:https://kaotiyun.com/show/slTp777K
0

相关试题推荐
最新回复(0)