16.小李基于選擇排序算法編寫了一個(gè)VB程序,功能如下:在文本框Text1中顯示排序前的數(shù)據(jù),單擊“排序”按鈕Command1,在文本框Text2中顯示剔除重復(fù)數(shù)據(jù)后的升序排序結(jié)果。程序運(yùn)行界面如圖所示。 實(shí)現(xiàn)上述功能的VB程序如下,但加框處代碼有錯,請改正。 Const n=10 Dim a(1 To n) As Integer Private Sub Command1_Click ( ?。?br />Dim i As Integer,j As Integer,t As Integer Dim k As Integer,bottom As Integer ’獲取排序前數(shù)據(jù),依次存儲在數(shù)組a中,并在文本框Text1中顯示。代碼略 bottom=n:i=1 Do While i<=bottom-1 k=i:j=bottom Do While j>i If a(j)<a(k) Then k=j ElseIf a(j)=a(i) Then’若發(fā)現(xiàn)重復(fù)數(shù)據(jù),進(jìn)行剔除處理 a(j)=a(bottom) If k=bottom Then’(1) bottom=bottom-1 End If j=j-1 Loop If k<>i Then t=a(k):a(k)=a(i):a(i)=t ’(2) End If i=i+1 Loop Text2.Text=““ For i=1 To bottom Text2.Text=Text2.Text+Str(a(i)) Next i End Sub
。 (2)請?jiān)跈M線處填入合適代碼。 Function Char2Int(c As String) As Integer If c>=“A“And c<=“Z“Then’字母“A”的 ASCII碼是65 Char2Int=Asc(c)-65 Elself c>=“a“And c<=“z“Then’字母“a”的ASCII碼是 97 Char2Int=Asc(c)-71 ElseIf c>=“0“And c<=“9“Then’數(shù)字“0”的ASCII碼是48
ElseIf c=“+“Then Char2Int=62 Else Char2Int=63 End If End Function Private Sub Command1_Click ( )’解密過程 Dim n As Integer,s As String,i As Integer,ss As String Dim a(0 To 3)As Integer’依次存儲一組四個(gè)密文按密碼表換算出的數(shù)值 Dim b(0 To 2)As Integer’依次存儲一組三個(gè)明文字符的ASCII值 s=Text1.Text n=Len(s) ss=““ For i=1 To n Step 4 For j=i To i+3 a(
)=Char2Int(Mid(s,j,1)) Next j b(0)=a(0)*4+a(1)\16
b(2)=(a(2)Mod 4)*64+a(3) For j=0 To 2 ss=ss+Chr(b(j)) Next j Next i Text2.Text=ss End Sub