当前位置: 高中信息技术 / 综合题
  • 1. (2019·上海模拟) 全班45位同学拍毕业照,每排15人共3排,全班最高的一批站第3排,最低的一批站第一排,每排最高的站中间(第8个),两边依次身高递减。小王设计一个程序,实现队列安排功能,程序界面如下图所示。

    代码如下:

    Dim a(1 To 100) As String, a1(1 To 100) As String, b(1 To 100) As Integer, b1(1 To 100) As Integer

    Private Sub Form_Load()

        '读取数据库中学生相关信息,姓名存数组a,身高存数组b

    End Sub

    Private Sub Command1_Click()

        Dim temp As Integer, temp2 As String, k As Integer, s As String, s1 As String

        For i = 1 To 44

            For j = i + 1 To 45

                If b(i) > b(j) Then

                    temp = b(i): b(i) = b(j): b(j) = temp

                    temp2 = a(i): a(i) = a(j): a(j) = temp2

                End If

            Next j

        Next i

        For x = 1 To 3

            k = 0

            For y = 15 * x ToStep -1

                If x Mod 2 = 1 Then

                    If y Mod 2 = 1 Then

                        b1(15 * (x - 1) + 8 - k) = b(y)

                        a1(15 * (x - 1) + 8 - k) = a(y)

                    Else

                        k = k + 1

                        b1(15 * (x - 1) + 8 + k) = b(y)

                        a1(15 * (x - 1) + 8 + k) = a(y)

                    End If

                Else

                    If y Mod 2 = 1 Then

                        k = k + 1

                        b1(15 * (x - 1) + 8 - k) = b(y)

                        a1(15 * (x - 1) + 8 - k) = a(y)

                    Else

                        b1(15 * (x - 1) + 8 + k) = b(y)

                        a1(15 * (x - 1) + 8 + k) = a(y)

                    End If

                End If

            Next y

        Next x

        For i = 1 To 45

            s = s + " " + a1(i)

            s1 = s1 + " " + Str(b1(i)) + " "

            IfThen

                Label1.Caption = Label1.Caption + " 第" + Str(i \ 15) + " 排" + s + vbCrLf + s1 + vbCrLf

                ' fvbCrLf 表示回车换行

                s = ""

                s1 = ""

            End If

        Next i

    End Sub

    要使程序实现此功能,在画线处填入适当的语句或表达式,将程序补充完整。

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