16.小李統(tǒng)計2017年各國在浙江省旅游人數(shù),設(shè)計了一個程序。程序運行時在列表框List1中輸出已經(jīng)按照大洲類別分類的信息,在文本框Text1中輸入“大洲類別”如:,歐洲,單擊“查找排序”按鈕Command2,將在列表框List2中輸出該“大洲類別”旅游人數(shù)從低到的高信息。程序運行界面如圖所示: 實現(xiàn)上述功能的VB代碼如下,但加框處代碼有錯,請改正。 DimkAsInteger′k變量用來存放國家的個數(shù)Private Sub Form_ Load ( ) ′從數(shù)據(jù)庫中讀取數(shù)據(jù)并存儲在相關(guān)變量中。aa( )數(shù)組用來存放國家名稱,bb ( )數(shù)組用來存放大洲類別,cc ( )數(shù)組用來存放旅游人數(shù)。 ′代碼略 End Sub Private Sub Command2_ Click ( ) Dim zb(1 To 10)As String用來存放大洲類別 Dim wz(1 To 10)As Integer用來存放每類大洲開始的位置 Dim cd(1 To 10 As Integer用來存放每類大洲的國家個數(shù) Dim c As String,pos As Integer,ld As Integer zb(1)=bb(1):wz(1)=1:cd(1)=I n=1 c=Text1.Text Fori=2To k If Then① cd(n)=cd(n)+1 Else n=n+1 zb(n)=bb(i):cd(n)=1:wz(n)=i End If Next i Fori=1Ton If zb(i)=c Then pos=wz(i):Id=ed(i) Next i Fori= ② Forj=pos+ld-1Toi+I Step-1 Ifcc(j)<cc(j-1)Then t=aa(j-1):aa(j-1)=aa(j):aa(j)=t t=cc(j-1):cc(j-1)=cc(j):cc(j)=t End If Next j Next i Fori=pos To pos+1d-1 List2.AddItem aa(i)+”“+bb(i)+““+Str(cc(i))” Next iEnd Sub 程序中①處改為
17.數(shù)組a ( )中相鄰兩個數(shù)據(jù)無重復,現(xiàn)要查找連續(xù)最大步長的升序段。具體描述如下: (1)步長指的是升序段中最后元素和最初元素的差值; (2)有相同步長的升序段則輸出最先找到的升序段。程序界面如圖所示。 實現(xiàn)上述功能的VB代碼如下: Dim a( 100)As Integer′用來存放數(shù)據(jù) Dim k As Integer′用來存放數(shù)據(jù)的數(shù)組元素的個數(shù) Private Sub Form_ Load ( ) '從數(shù)據(jù)庫中讀取數(shù)據(jù)并存儲在相關(guān)數(shù)組變量中。并將數(shù)據(jù)輸出在文本框中。 Textl.Text=s End Sub Private Sub Commandl _Click ( ) Dim f1ag As Boolean,pmax As Integer,mstep As Integer,steps As Integer,max As Integer,stAs String,tmax As Integer st=“:pmax=1:mstep=0:max=0:t=0:tmax=0 Ifa(2)>a(1)Then flag=True Else flag=False Fori=1 Tok-I Ifa(i+1)>a(i) Then If flag=True Then
t=t+I If mstep>max Then max=mstep pmax=i+1
End If Else mstep=a(i+1)-a(i) t=I If mstep>max Then max=mstep pmax=i+1 tmax=I End If flag=True End If Else
End If Next i Fori=pmax-tmaxTopmax st=st+Str(a(i)) Next i Listl.AddItem st End Sub (I1)若數(shù)據(jù)為“24,7,2,16,25,68,45,32,2,23,46,67,26”則最大步長的升序段為