当前位置: 高中信息技术 / 综合题
  • 1. (2019·上海模拟) 某班级学生为毕业晚会的一个节目设计一个仿“V”字的造型,先筛选出班级里所有男生,然后将参演的n 名男生按照身高,摆出中间低两边高(先右后左)的造型,如图所示。

    原1-7号男生身高

    171 172 180 174 176 179 178

    筛选排序后序列

    171 172 174 176 178 179 180

    “造型设计”后序列

    180 178 174 171 172 176 179

    王林同学用VB编写模拟“节目造型”程序,功能如下:从数据库中导出所有学生编号、性别和身高数据;单击“筛选排序”按钮Command1,选出“男生”且按身高升序排列显示在文本框Text1中;单击“设计造型”按钮Command2,根据身高仿“V”字的造型进行有序排列,并将结果显示在文本框Text2 中。程序运行界面如图所示。举例说明如下:

    Const n = 7

    Dim h2(1 To n) As Integer

    Dim height1(1 To n) As Integer, height 2 (1 To n) As Integer

    Dim i As Integer, j As Integer, temp As Integer

    Dim sex(1 To n) As Boolean ' 男生sex=true

    Private Sub Form_Load()

        'n名学生的身高和性别由数据库导出,分别存储在数组height1和sex中,代码略!

    End Sub

    Private Sub Command1_Click()

        For i = 1 To n - 1

            For j = n To i + 1 Step -1

                IfThen

                    temp = height1(j): height1(j) = height1(j - 1): height1(j - 1) = temp

                End If

            Next j

        Next i

        For i = 1 To n

            Text1.Text = Text1.Text + " " + Str(height1(i))

        Next i

    End Sub

    Private Sub Command2_Click()

        Dim left, right As Integer, i As Integer, mid As Integer

        mid = Int((1 + n) / 2)

        left = 0: right = 0

       

        For i = 2 To n Step 2

            right = right + 1

            height2(mid + right) = height1(i)

            left = left + 1

            

        Next i

        For i = 1 To n

            Text2.Text = Text2.Text +“ “ + Str(height2(i))

        Next i

    End Sub

    为实现以上功能,请在画线处填写正确代码。

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