当前位置: 高中信息技术 / 综合题
  • 1. (2020高三上·浙江期中) 某高一班主任需要对刚入学的新生排座位,教室座位按 6 排 8 列进行摆放(班级学生数不超过48个),并且要求每列的学生按身高从低到高排列。编写 VB 程序,实现教室排座位功能:单击“读取数据”按钮 Command1,从数据库中读取该班所有同学的班内学号(两位数字)和身高数据(3位数字),并在列表框List1中按8个一行显示;单击“排座位”按钮 Command2,对每列数据按身高从小到大排列,并显示在列表框List2中。程序运行界面如图所示,请回答下列问题:

    1. (1) 要使窗体的标题栏文字显示为“排座位”,则应设置窗体的属性(单选,填字母:A .Text / B .Name /C .Caption)。
    2. (2) 实现上述功能的VB程序如下,请在划线处填入合适的代码。

      Const m = 6

      Const n = 8

      Dim a(1 To m * n) As String      '存储学号

      Dim b(1 To m * n) As Integer     '存储身高

      Dim num As Integer            '班级总人数

      Private Sub Command1_Click( )

          '从数据库中读取该班的学号和身高数据存入数组a和数组b,班级人数存入变量num,代码略

          '以下代码为在列表框List1中输出数据

          s = "" : List1.AddItem "          ( 讲 台 )"

          For i = 1 To num

              s = s & Str(b(i)) & "[" & a(i) & "] "

              If  Then

                  List1.AddItem s : s = ""

              End If

          Next i

          If s <> "" Then List1.AddItem s

      End Sub

      Private Sub Command2_Click( )

          Dim i As Integer, j As Integer, imin As Integer

          Dim t1 As String, t2 As Integer,  s As String

          List2.AddItem "               ( 讲 台 ) "

          For i = 1 To

              s = ""

              For j = (i - 1) * n + 1 To (i - 1) * n + n

                  If j <= num Then

                      

                      If imin <> j Then

                          t1 = a(imin): a(imin) = a(j): a(j) = t1

                          t2 = b(imin): b(imin) = b(j): b(j) = t2

                      End If

                      s = s & Str(b(j)) & "[" & a(j) & "] "

                  End If

              Next j

              List2.AddItem s

          Next i

      End Sub

      Function fPos(p As Integer) As Integer

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

          k = p

          For i =

              If b(i) < b(k) Then k = i

          Next i

          fPos = k

      End Function

    3. (3) 程序中加框处代码有错,请改正。

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