试题

试题 试卷

logo

题型:综合题 题类:模拟题 难易度:困难

浙江省教育绿色评价联盟2018届高三下学期信息技术选考适应性考试试卷

【加试题】小李基于选择排序算法编写了一个VB程序,功能如下:在文本框Text1中显示排序前的数据,单击“排序”按钮Command1,在文本框Text2中显示剔除重复数据后的升序排序结果。程序运行界面如图所示。

实现上述功能的VB程序如下,但加框处代码有错,请改正。

  Const n=10

  Private Sub Form_Load()

    ‘排序前数据存储在数组a中,并在文本框Text1中显示

    ‘代码略

  End Sub

  Private Sub Command1_Click()

  Dim i As Integer

  Dim bottom As Integer

  Dim j As Integer

  Dim a(1 To n)As Integer

  i=1

  bottom=n

  Do While i<bottom

    k=i

    j=i+1

      Do While i<=bottom

        If a(j)=a(k)Then

           a(i)=a(bottom)

                    ‘(1)

           bottom=bottom-1

        E1seIf a(j)<a(k) Then

           k=j

        End If

        j=j+1

      Loop

      If    Then      ‘(2)

    t=a(i)

    a(i)=a(k)

    a(k)=t

      End If

      i=i+1

  Loop

 ‘排序后数据存储在数组a中,并在文本框Text2中显示

  End Sub

(1)、处加框代码应改为
(2)、处加框代码应改为
举一反三
数组a存储降序排列的m个数据,数组b中存储的是升序排列的n个数据,且两个数组中存储的数据为区间[1,20]范围内的不重复的随机整数。现将两个数组的数据合并到c数组中,使c数组的数据为左右交替上升,如下表所示:

a(1)

a(2)

a(3)

a(4)

a(5)

19

17

6

4

3

a数组

b(1)

b(2)

b(3)

b(4)

b(5)

b(6)

5

7

8

13

15

20

b数组

c(1)

c(2)

c(3)

c(4)

c(5)

c(6)

c(7)

c(8)

c(9)

c(10)

c(11)

3

5

7

13

17

20

19

15

8

6

4

c数组

当窗体Form1加载时,自动产生a、b数组的数据,并分别显示在列表框List1与List2中,单击合并按钮Command1后,在c数组中保存按规则合并后的a、b数组的数据,并显示在列表框List3中。程序截图如下所示:

实现该功能的VB程序如下:

Const m = 5

Const n = 6

Dim a(1 To m) As Integer

Dim b(1 To n) As Integer

Dim c(1 To m + n) As Integer

‘窗体加载时,生成数组a、b中的数据,并按要求排序后显示在列表框中,代码略

Private Sub Command1_Click()

Dim pa As Integer, pb As Integer, pc As Integer, s As Integer, flag As Boolean

pa = m: pb = 1: pc = 1

flag = True

Do While         ①        

    If a(pa) < b(pb) Then

        s = a(pa)

        pa = pa - 1

    Else

        s = b(pb)

        pb = pb + 1

    End If

    c(pc) = s

    If  flag Then

        pc = m + n - pc + 1

    Else

        pc =

    End If

            ②       

Loop

‘处理a、b数组中剩余数据,并在列表框List3中输出数组c,代码略

End Sub

小王基于选择排序算法编写了一个VB程序,功能如下:读取若干数据依次存储在数组a中,并将数据分段排序,每段数据的元素个数及排序的次序要求依次存储在数组b中。如图,在文本框Text1中显示数组a的原始数据,在文本框Text2中显示每段数据的元素个数及排序次序要求(0表示升序、1表示降序);单击“排序”按钮Command1,根据要求输出对每段数据进行排序的结果。实现上述功能的VB程序如下:

Dim n As Integer

Dim a(1 To 100) As Integer

Dim b(1 To 100) As Integer

Private Sub Form Load()

‘读取若干数据依次存储到数组a中,并将数据元素的总个数存储到变量n中。

‘将每段数据的元素个数及排序的次序依次存储到数组b中;

‘b(1)、b(2)分别存储第1段数据的元素个数、排序的次序,

‘b(3)、b(4)分别存储第2段数据的元素个数、排序的次序,.....

“代码略。

End Sub

Private Sub Command1_Click())

    Dim i As Integer, j As Integer, k As Integer, t As Integer

    Dim pb As Integer, endpos As Integer

    pb=1: endpos =b(1)

    For i=1 To n-1

        If i=endpos Then

            pb=pb+2:i=endpos+1

               ①  

        End If

        k=i

        For j =i+1 To endpos

            If  Then k=j     ‘⑵

        Next j

        If k<>i Then

                ②  

        End If

    Next i

    Text3.Text =""     ‘⑷

    For i=1 To n

        Text3.Text=Text3.Text + Str(a(i))

    Next i

End Sub

返回首页

试题篮