题目

小王基于选择排序算法编写了一个VB程序,功能如下:在文本框Text1中显示排序前的数据,单击“排序”按钮,在文本框Text2中显示剔除重复数据后的升序排序结果。程序运行界面如图所示。 实现上述功能的VB代码如下,请回答下列问题: Const n= 10 Dim a(1 To n) As Integer Private Sub Form_ load( ) '数组初始化,生成1~20之间的随机整数并赋值给数组a,代码略 End Sub Private Sub Cmd1_Click()     Dim i As Integer, j As Integer, t As Integer     Dim bottom As Integer     bottom= n     For i=1 To bottom-1         For j= bottom To i+1 Step -1             If  Then    '①改错                 t=a(j) : a(j)=a(i) : a(i)=t             ElselIf a(j)=a(i) Then                       '②填空                 bottom= bottom- 1             End If         Next j     Next i     Text2. Text=" "     For i=1 To bottom         Text2. Text= Text2. Text+Str(a(i))     Next i End Sub (1) 程序窗体中“排序”按钮的对象名是。 (2) 程序代码中,加框处①有错,请改正; (3) 为实现上述功能,请在加框处②填入合适的代码: (4) 要想生成范围是1~20的随机整数,VB表达式是。 答案: 【1】Cmd1 a(j) < a(i) a(j) = a( bottom) 【1】Int(Rnd* 20)+1
信息技术 试题推荐
最近更新