修改时间:2024-07-13 浏览次数:110 类型:期末考试
Dim a(1 To 10) As Integer
s = "8+9+10=": n = 1
For i = 1 To Len(s)
ch = Mid(s, i, 1)
If ch >= "0" And ch <= "9" Then
a(n) = a(n) * 10 + Val(ch)
Else
If a(n) > 0 Then n = n + 1
End If
Next i
Text1.Text = Str(n)
数组a各元素的初始值都为0,若执行该程序后,在文本框Text1中显示的值为( )
a(1) = 12: a(2) = 44: a(3) = 65: a(4) = 36: a(5) = 58
x = 0: y = 0
For i = 1 To 4
k = i
For j = i + 1 To 5
If a(j) > a(k) Then
k = j
x = x + 1
End If
Next j
If k <> i Then
t = a(i): a(i) = a(k): a(k) = t
y = y + 1
End If
Next i
Text1.Text = Str(x) + Str(y)
执行该程序段后,文本框Text1中显示的内容是( )
Dim a(1 To 6) As Integer
Const n = 6
a(1) = 98: a(2) = 96: a(3) = 95
a(4) = 90: a(5) = 87: a(6) = 81
i = 1: j = n
Key = Val(Text1.Text)
f = False
Do While And f = False
m = (i + j) \ 2
If a(m) = Key Then
Text1.Text = "已找到": f = True
ElseIf a(m) > Key Then
Else
End If
Loop
上述程序中方框处语句依次为( )
所示。
图a
图b
图a
图b
a(1) |
a(2) |
a(3) |
…… |
a(n-2) |
a(n-1) |
a(n) |
27 |
35 |
39 |
…… |
49 |
39 |
33 |
小华由此设计一个VB程序,功能如下:单击“排序”按钮Command1,随机生成10个两位奇数,将随机生成的数据序列显示在文本框Text1中,在文本框Text2中显示完成排序后的数据序列,运行结果如图所示。
Private Sub Command1_Click()
Dim a(1 To 10) As Integer
Randomize
Const n = 10
For i = 1 To n
a(i) = ①
Text1.Text = Text1.Text + Str(a(i))
Next i
For i = 1 To n \ 2
For j = n - i + 1 To i + 1 Step -1
If a(j) < a(j - 1) Then
t = a(j - 1)
②
a(j) = t
End If
Next j
For j = i + 1 To n - i
If Then
t = a(j): a(j) = a(j + 1): a(j + 1) = t
End If
Next j
Next i
For i = 1 To n
Text2.Text = Text2.Text + Str(a(i))
Next i
End Sub
1)以字节为单位进行加密处理;
2)将1个字节的8位二进制数分割成前4位与后4位两个二进制数;
3)分别将上述两个4位二进制数转换成十进制数;
4)将每个十进制数转换为1个加密字符,对应的“密码表”如下:
值(十进制) |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
加密字符 |
I |
l |
i |
k |
e |
C |
H |
N |
p |
o |
s |
t |
c |
a |
r |
d |
小华按照上述方法,设计了一个字符串(仅包含ASCII字符)解密的VB程序,功能如下:在文本框Text1中输入一串密文,单击“解密”按钮Command1,在文本框Text2中显示解密结果。
下表显示了字符串中一个字符的加密过程:
m |
←转换前字符m |
|||||||
109 |
←字符m的ASCII码十进制值 |
|||||||
0 |
1 |
1 |
0 |
1 |
1 |
0 |
1 |
←对应的二进制数 |
6 |
13 |
←分割、转换后的十进制数 |
||||||
H |
a |
←对应的加密字符 |
||||||
程序运行效果如图所示。
Private Sub Command1_Click()
Dim a(1 To 100) As Integer
Dim s1 As String, s2 As String, c As String
Dim x As Integer, k As Integer, i As Integer, j As Integer
Const code = "IlikeCHNpostcard"
n = Len(code)
s1 = Text1.Text
x = 0: k = 0
For i = 1 To Len(s1)
c = Mid(s1, i, 1)
For j = 1 To n
If Then
pos = j - 1
x = x * 16 + pos
Exit For '退出当前For循环
End If
Next j
If i Mod 2 = 0 Then
a(k) = x
x = 0
End If
Next i
For i = 1 To k
Next i
Text2.Text = s2
End Sub
试题篮