当前位置: 高中信息技术 / 综合题
  • 1. (2020·浙江模拟) 小杨同学编写了一个vb程序用于学校里7选3选课情况统计。该程序主要功能有: 1.点击“生成选课组合”按钮Command1,生成35种选课组合:2.点击“统计选课情况"按钮Command2,统计出各种组合的选课人数:运行界面如下图。实现上述功能的VB程序如下,请回答下列问题:

    1. (1) 分析程序代码,图里“选课组合”序号为30的组合名称为:
    2. (2) 请在划线处填入合适的代码。请回答下列问题:

      Dim zh(1 To 16) As String,zrs As Integer

      Dim xk(1 To 1000) As String    '存放同学的选课科目组合,已知学生人数少于1000人

      Dim zh2(1 To 35) As String     '存放35种选课科目组合

      Dim rstj(1 To 35) As Integer     '存放各种选课组合选课人数

      Private Sub Form_ Load( )

          '本过程从数据库中读取学生的选课情况数据,存放在数组xk中,学生的总人数存放在变量zrs。

          '代码略

      End Sub

      Private Sub Command1_ Click()

          Dim iAs Integer, j As Integer, m As Integer, n As Integer, k As Integer

          Dim km(1 To 7) As String

          List1.Clear

          List1.AddItem "序号"+ "" + "组合名称"

          km(1) = "物": km(2) = "化": km(3)= "生": km(4)= "政"

          km(5) = "史": km(6) = "地": km(7)= "技"

          m= 1

          For i= 1 To 5

              For k=i+ 1 To 6

                  zh(m) = km(i) + km(k)

                  m=m+1

              Next k

          Next i

          j=3:n= 1:y=j

          For i= 1 To m

              For k=y To 7

                  zh2(n)=

                  If n<= 9 Then

                      List1.AddItemn&""&" " & zh2(n)

                  Else

                      List1.AddItemn&" " & zh2(n)

                  End If

                  n=n+ 1

              Next k

              y=y+ 1

              If y= 8 Then

                  j= : y=j

              End If

          Next i

      End Sub

      Private Sub Command2_ Click()

          Dim i As Integer

          List2.Clear

          List2.Addltem "组合名称" +""+ "选课人数”

          For i= 1 To 35

              rstj(i)=

              List2.AddItem zh2(i) +"" + Str(rsij(0)

          Next i

      End Sub

      Function tj(zhme As String) As Integer      '统计某种选课组合的选课人数

          Dim i As Integer, rs As Integer

          rs= 0

          For i= 1 To zrs

              If zhmc = xk(i) Then

                  rs=rs+ 1

              End If

          Next i

          tj=rs

      End Function

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