题型:综合题 题类:常考题 难易度:困难
浙江省嘉兴市、丽水市2017-2018学年选考信息技术教学测试试卷(3月)
明文:HelloWorld
密钥:abcabcabca
密文:HfnlpYosnd
依据上述算法描述设计了如下VB程序。请回答下列问题:
Const MIN_ASC=65 ‘字母”A”的ASCII值
Function x2D(x As String)As String ‘字符串小写转成大写
Dim s As String,zf As String,i As Integer
S=””
For i=1 To Len(x)
zf=Mid(x,i,1)
If zf>=“a”And zf<=“z”Then
s=s+ ①
Else
s=s+ zf
End If
Next
X2D=s
End Function
Private Sub Command1_Click()
Dim M As String,K As String,C As String,flag As Boolean
Dim i As Integer,t As Integer,ch As Integer,pos As Integer·
As Integer
M=Textl.Text ‘明文
K=Text2.Text ‘密钥
t=Len(K)
K=X2D(K) ‘将密钥全部转成大写
C=“ ” ‘加密后的结果
For i=1 To Len(M)
ch=Asc(Mid(M,i,1))
flag=False
If ch>=97 And ch<=122 Then ch=ch-32:flag=True
pos= ② ‘密钥的字符位置值
If pos=0 Then pos=t
j=Asc(Mid(K,pos,1)) ‘密钥字符的ASCII值
ch=ch-MIN_ASC
j=j-MIN_ASC
ch= ③
ch=ch+MIN_ASC
If flag Then ch=ch+32 ‘设置字母的大小写形式
C=C & Chr(ch)
Next i
Text3.Text=C
End Sub
① ② ③
长度小于等于 100),在列表框 List1 里输出所有配对括号在表达式中的位置。例如在文本框 Text1 里入:“12*(3-(1+2))*3”,程序运行效果如图所示。
实现上述功能的 VB 代码如下,在划线的地方填入合适代码,完善程序。Private Sub Command1_Click()
Dim s As String
Dim a(1 To 100) As Integer
|
i = 1 top = 0
Do While i <= Len(s)
If Mid(s, i, 1) = "(" Then
top = top + 1
{#blank#}1{#/blank#}
End If
If Mid(s, i, 1) = ")" Then
List1.AddItem Str(a(top)) + " " + Str(i)
{#blank#}2{#/blank#}
End If
i=i+1 Loop
End Sub
试题篮