当前位置: 高中信息技术 / 综合题
  • 1. (2020高三上·杭州期中) 有如下程序,从数据库获取成绩,单击“读取数据”按钮将n个非降序数保存在数组cj(1)~cj(n)中,并将成绩显示在列表框中。在文本框中输入成绩key,单击“查找”按钮,在标签中显示大于等于该成绩的学生人数。

    1. (1) 界面中“查找”按钮的对象名为
    2. (2) 实现上述功能的 VB 程序如下,请在划线处填入合适的代码

      Dim cj(1000) As Integer, n As Integer

      Private Sub btncmd1_Click( )

      Dim i As Integer, j As Integer

      Dim k As Integer ,tmp As Integer

      For i = 2 To n

        tmp = cj(i)

        j = BinarySearch

        For k = i To j + 1 Step -1

          cj(k) = cj(k - 1)

        Next k

        cj(k) = tmp

      Next i

      For i = 1 To n

        List1.AddItem Str(cj(i))

      Next i

      End Sub

      Private Sub btncmd2_Click()

      Dim i As Integer

      i = BinarySearch(Val(Text1.Text), 1, n)

      Label2.Caption = "共有" ++ "位同学大于等于该成绩。"

      End Sub

      Function BinarySearch(key As Integer,i As Integer,j As Integer) As Integer

      Dim m As Integer

      Do While i <= j

      m = (i + j) \ 2

        If cj(m) >= key Then

          j = m - 1

        Else

          i = m + 1

        End If

      Loop

      BinarySearch =

      End Function

      Private Sub Form_Load()

      '从数据库获取n个成绩存储在 cj(1) ~cj(n)组中,代码略

      End Sub

微信扫码预览、分享更方便