修改时间:2024-07-31 浏览次数:92 类型:月考试卷
key=Val(Text1.text)
i=1:j=10
Text2.text=””
Do While i<=j
m=Int((i+j)/2+0.5)
If key=a(m) Then Exit Do `Exit Do表示退出循环
If key<a(m) Then j=m-1 Else i=m+1
Text2.text=Text2.text+Str(a(m))
Loop
数组元素a(1)到a(10)的值依次为“8、17、24、30、36、40、55、58、61、66”,文本框Text1中输入的值是30,执行该程序段,文本框Text2中显示的是( )
将密码字符分为数字、字母和其他符号三类。
密码强度的检测方法为:
⑴若密码位数少于8位,则不进行强度检测,给出提示“密码位数不能少于8位,请重新输入!”。
⑵若密码位数在8位及以上,则进行强度检测:
若密码字符属于同一类字符,则密码强度为“弱”;若密码字符属于不同的二类字符,则密码强度为“中等”;若密码字符属于不同的三类字符,则密码强度为“强”。
Private Sub Command1_Click()
Dim password As String, st As String
Dim i As Integer, n As Integer, tj1 As Integer, tj2 As Integer, tj3 As Integer
password = Text1.Text
n = Len(password)
If ① Then
Label3.Caption = "密码位数不能少于8位,请重新输入!"
Else
tj1 = 0: tj2 = 0: tj3 = 0
i = 1
Do While ②
st = Mid(password, i, 1)
If st >= "0" And st <= "9" Then
tj1 = 1
ElseIf st >= "a" And st <= "z" Or st >= "A" And st <= "Z" Then
tj2 = 1
Else
Tj3 = 1
End If
i = i + 1
Loop
If tj1 + tj2 + tj3 = 3 Then
Label3.Caption = "强"
ElseIf ③ Then
Label3.Caption = "中等"
Else
Label3.Caption = "弱"
End If
End If
End Sub
① ② ③
图 a
图 b
实现上述功能的VB程序如下,但横线处代码有错,请改正。
Const n = 8
Dim a(1 To n) As Integer
Private Sub Form_Load()
'排序前数据存储在数组a中,并在文本框Text1中显示代码略
End Sub
Private Sub Command1_Click()
Dim k As Integer, i As Integer, j As Integer, t As Integer
i = 1
Do While i <= n - 1
k = i
For j = i + 1 To n
If a(i) Mod 2 = 1 And a(k) Mod 2 = 0 Then '①
k = j
ElseIf a(k) Mod 2 = 0 And a(j) Mod 2 = 0 And a(j) > a(k) Then
k = j
End If
Next j
If k <> i Then
t = a(k): a(k) = a(i): a(i) = t
End If
i = i + k '②
Loop
'依次输出排序后的数据。代码略
End Sub
① ②
Private Sub Command1_Click()
Dim a(1 To 100) As Single
Dim b(0 To 100) As String
Dim s As String, c As String
Dim sz As Integer, i As Integer, k As Integer
s=Text1.Text,
k=0
For i=1 To Len(s)
c=Mid(s, i, 1)
If c>="0" And c <= "9" Then
sz=0
Do While c>="0" And c<="9"
sz= ①
i=i+1
c=Mid(s, i, 1)
Loop
k=k+1:a(k)=sz:b(k)=c
End If
Do While k>1 And ②
If b(k-1)="+"Then a(k-1)=a(k-1)+a(k)
If b(k-1)="-"Then a(k-1)=a(k-1)-a(k)
If b(k-1)="*"Then a(k-1)=a(k-1)*a(k)
If b(k-1)="/"Then a(k-1)=a(k-1)/a(k)
b(k-1)=b(k)
k=k-1
Loop
Next i
Label1.Caption="运算的结果是:"+Str(a(1))
End Sub
Function yxj (x As String) As Integer
If x="*"Or x="/"Then
yxj=1
ElseIf x="+"Or x="-"Then
yxj=2
Else
③
End If
End Function
① ② ③
试题篮