條(填數字)。 (2)實現上述功能的 VB 程序如下,請在橫線處填入合適代碼。 Const n=20 Dim score(1 To n)As Single Function adj(s As String,n As Integer) ‘此函數功能:在字符串 s 前添加若干個空格,使其長度變為 n。代碼略 End Function Function search_left(key As Integer) ‘此函數功能:返回大于等于 key 的數組元素的起始位置。代碼略。 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 ①
m=(i+j)\2
m=(i+j)\2
If key>=score(m)Then i=m+1 Else j=m-1 Loop ②
search_right=j
search_right=j
End Function Private Sub Form_Load ( ) ‘從數據庫中讀取成績存數組 score,記錄數存 n,并對此數組 score 升序排序,代碼略 End Sub Private Sub Command1_Click ( ) Dim num1 As Integer,num2 As 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) ③
total=last-first+1
total=last-first+1
If total<=0 Then 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
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: