類。 (單選,填字母:A.Form/B.Label/C.TextBox/D.CommandButton) (2)請在橫線處填入合適的代碼。 ①
max=a(i)
max=a(i)
; ②
check(m)或check(m)=true
check(m)或check(m)=true
; ③
total+b(i)
total+b(i)
。 (3)程序中加框處代碼有錯,請改正。 改正:
total<=t
total<=t
。 Const n=4 Dim a(1 To n)As Integer'n道菜由每家餐廳外賣員送達耗時 Dim b(1To n)As Integer'n道菜自取耗時 Private Sub Form_Load
( )
( )
。 '產生外賣送貨各道菜耗時,并存儲到數組a中,并顯示, '產生自取各道菜耗時,并存儲到數組b中,并顯示 '代碼略 End Sub Private Sub Command1_Click
( )
( )
Dim i As Integer,max As Integer,ans As Integer Dim left As Integer,right As Integer,m As Integer For i=1 1 To n If a(i)>max Then ①
max=a(i)
max=a(i)
'外賣員送菜的最長時間 Next i left=1:right=max:ans=max. m=(left+right)\2 If ②
check(m)或check(m)=true
check(m)或check(m)=true
Then ans=m:right=m-1 Else left=m+1 End If Loop Lab3.Caption=“最快“+str(ans)+“分鐘“ End Sub private Function check(t As Integer)As Boolean Dim total As Integer check=False For i=1 To n If a(i)>t Then total=③
total+b(i)
total+b(i)
'如果外賣來不及就自己取 End If Next i If tital>=t Then check=True End Function
1.大部分社交軟件都有好友推薦的功能,當用戶 A 和用戶 B 的共同好友數量超過閾值 p 時,由系統向用戶 A 推薦用戶 B。 編寫 VB 程序,實現好友推薦功能。運行程序,列表框 Listl 中顯示用戶 id 及好友列表,在文本框 Textl 中 輸入推薦目標用戶 id,在文本框 Text2 中輸入閾值 p,點擊“推薦”按鈕,在列表框List2 中顯示用戶之間的關系,在標簽 Label5 中顯示向目標用戶推薦的好友列表。程序運行界面如圖: (1)根據如圖所示數據,若輸入用戶 id 為“3”,輸入閾值為“3”,則推薦好友為: