题库 高中信息

题干

小明编写了一个字符串加密程序,运行界面如图所示。功能如下:在文本框Text1中输入明文,在文本框Text2中输入密钥(密钥值在1到25之间),单击“加密”按钮Command1后,在标签Label1中输出密文。加密算法如下:

(1)若是字母,则将其变为按字母顺序往后数密钥个数的字母,若字母超过“Z”或“z”,则将其顺延到“A”或“a”后,大小写保持不变;若为其他字符,则保持不变,例如:
明文
Z
h
e
n
_
H
a
i
密钥
3
密文
C
k
h
q
_
K
d
l
 
(2)在步骤(1)的基础上,奇数位置的字符保持不变,偶数位置的字符逆序排列。
密文
C
l
h
K
_
q
d
k
 
实现上述功能的VB程序如下,加框处有错误,请改正。
Private Sub Command1_Click()
Dim a(1 To 100) As String
Dim s As String, i As Integer
Dim j As Integer, n As Integer
Label4.Caption = ""
s = Text1.Text
n = Val(Text2.Text)
i = 1
Do While i <= Len(s)
c = Mid(s, i, 1)
If c >= "A" And c <= "Z" Then
a(i) = Chr((Asc(c) - Asc("A") + n) Mod 26 + Asc("A"))
ElseIf c >= "a" And c <= "z" Then
a(i) = Chr((Asc(c) - Asc("a") + n) Mod 26 + Asc("a"))
Else
a(i) = c
End If
i = i + 1
Loop
j = Len(s) ‘①
For i = 2 To Len(s) \ 2 Step 2
t = a(i): a(i) = a(j): a(j) = t
j = j – 1 ‘②
Next i
For i = 1 To Len(s)
Label4.Caption = Label4.Caption + a(i)
Next i
End Sub
上一题 下一题 0.99难度 填空题 更新时间:2019-05-15 10:47:04

答案(点此获取答案解析)

同类题1

日期判断:从文本框Text1输入一个8位数字表示的日期,其中第1到4位表示年(第1位确定不为零),第5到6位表示月,第7到8位表示日。单击“判断”按钮,判断该日期是否合法,将结果依次输出到列表框List1。程序界面如下图所示:
提示:年份值符合下列两种情况之一的是闰年。
1.年份是4的倍数,但不是100的倍数;
2.年份是400的倍数。

(1)观察程序代码,可知“判断”按钮的对象名为 。(单选,填字母:
A.Text1/B.List1/C.Command1/D.Judge/E.判断)
(2)为实现上述功能,请在划线处填入合适的代码。
Private Sub Judge_Click()
Dim riqi As String, st As String
Dim year As Integer, month As Integer, day As Integer
Dim rn As Boolean, hefa As Boolean
riqi = Text1.Text
year =" Val(Mid(riqi," 1, 4))
month =" Val(Mid(riqi," 5, 2))
day =    ①     ‘第①处
st =" Str(year)" + "年" + Str(month) + "月" + Str(day) + "日"
rn = False  ‘用于判断是否为闰年
If ②  Then rn = True  ‘第②处
If year Mod 4 =" 0" And year Mod 100 <> 0 Then rn = True
hefa = True  ‘用于判断是否为合法日期
If month =" 0" Or month > 12 Then hefa = False
If day =" 0" Then hefa = False
If (month =" 1" Or month =" 3" Or month =" 5" Or month =" 7" Or  ’与下一行语句同行
month =" 8" Or month =" 10" Or month =" 12)" And day > 31 Then hefa = False
If (month =" 4" Or month =" 6" Or month =" 9" Or month = 11) ’与下一行语句同行
And day > 30 Then hefa = False
If   ③   Then hefa =" False" ’第③处,判断闰年2月的天数是否合法
If month =" 2" And Rn =" False" And day > 28 Then hefa = False
If hefa =" True" Then st =" st" + " 合法日期" Else st =" st" + " 非法日期"
List1.AddItem st
End Sub