實現(xiàn)上述功能的 VB 程序如下,但加框處代碼有錯,請改正。 Const n=10,maxn=20 Dim a(1To n) As Integer,index(1To n) As Integer,flag(1To n) As Boolean Private Sub Form_Load ( ?。?br/>Dim i As Integer Randomize For i=1To n flag(i)=False a(i)=Int(Rnd ( )*maxn)+1 List1.AddItem Str(a(i)) Next i End Sub Private Sub Command1_Click ( ?。?br/>Dim i As Integer,j As Integer,k As Integer For i=1To n For j=1To n If flag(j)=False Then k=j:Exit For Next j For m=k+1To n If Then k=m‘(1) Next m index(i)=k flag(k)=True Next i For i=1To n List2.AddItem ‘(2) Next i End Sub
條(填數(shù)字)。 (2)實現(xiàn)上述功能的 VB 程序如下,請在橫線處填入合適代碼。 Const n=20 Dim score(1To n) As Single Function adj(s As String,n As Integer) ‘此函數(shù)功能:在字符串 s 前添加若干個 空格,使其長度變?yōu)?nbsp;n.代碼略 End Function Function search_left(key As Integer) ‘此函數(shù)功能:返回大于等于 key 的數(shù) 組元素的起始位置。代碼略。 End Function Function search_right(key As Integer) Dim i As Integer,j As Integer,m As Integer i=1:j=n Do While i<=j
If key>=score(m) Then i=m+1Else j=m-1 Loop
End Function Private Sub Form_Load ( ?。?br />‘從數(shù)據(jù)庫中讀取成績存數(shù)組 score,記錄數(shù)存 n,并對此數(shù)組 score 升序排序,代碼略 End Sub Private Sub Command1_Click ( ?。?br />Dim num1As Integer,num2As Integer,first As Integer,last As Integer List2.Clear num1=Val(Text1.Text):num2=Val(Text2.Text) first=search_left(num1):last=search_right(num2)
If total<=0Then List2.AddItem“無篩選到的記錄!“Else List2.AddItem“篩選到“+Str(total)+“條記錄!“List2.AddItem“依次是:“ For i=first To last List2.AddItem adj(Str(i),3)+adj(Str(score(i)),6)Next i End If End Sub