试题

试题 试卷

logo

题型:综合题 题类:模拟题 难易度:困难

浙江省普通高校招生信息技术选考模拟卷(一)

【加试题】小李编写一个统计学生选考科目的VB程序,算法的基本思想是:检查每位学生选课组合的编码是否有效,对有效选择结果进行科目统计,根据各科次占有效人数的百分率求出各科排名。程序运行时,单击“显示”按钮Commmad1,学生选课数据显示在列表框List1中,各科编号及对应科目名称显示列表框list2中, 单击“统计”按钮Commmad2,选课结果按各科百分率由高到低显示在列表框list3中,程序运行结果如图所示。

实现上述功能的VB程序如下,请回答下列问题:

(1)、学生选课的编码数据存储在数据表中,其字段名为
(2)、请在划线处填入合适的代码.

Dim ach(1 To 500) As String     '存储各学生选课编码

Dim bno(1 To 10) As Integer     '存储各科目编号

Dim bname(1 To 10) As String    '存储各科目名称

Dim bnum(1 To 10) As Integer    '存储各科目被选次数

Dim bmc(1 To 10) As Integer     '存储各科目被选的名次

Dim n As Integer, num As Integer

Private Sub Command1_Click()

    Dim i As Integer, km As String

    km = "物理化学生物政治历史地理技术"

    Dim cn As New ADODB.Connection, rs As New ADODB.Recordset, sql As String

cn.Open "provider=Microsoft.Jet.oledb.4.0;Data Source=" + App.Path + "\students.mdb"

    rs.Open "select * from choose", cn

    Do While Not rs.EOF

        n = n + 1 : ach(n) = rs.Fields("subject") : rs.MoveNext

    Loop

    rs.Close : cn.Close

    Set rs = Nothing

    Set cn = Nothing

    For i = 1 To 7

       bno(i) = i : bname(i) = Mid(km, (i - 1) * 2 + 1, 2)

       List2.AddItem Str(bno(i)) + "---" + bname(i)

    Next i

End Sub

Private Sub Command2_Click()

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

   Dim c As String, per As Integer

   For i = 1 To n

   If check(ach(i)) = True Then

        For j = 1 To 3

           c = Mid(ach(i), j, 1)

           bnum(Val(c)) =  

        Next j

        num = num + 1

   End If

Next i   

i = 1     

Do While i <= 7      '该循环得到各学科被选人数的名次

bmc(i) = 1

    For j = 1 To 7

      If bnum(j) > bnum(i) Then   

    Next j

    i = i + 1

Loop

For i = 1 To 7

    For j = 1 To 7

         If  Then

         per = Int(bnum(j) * 100 / num * 100) / 100

         List3.AddItem Str(bno(j)) + "---" + bname(j) + "---" + Str(per) + "%"

         End If

    Next j

Next i

End Sub

Function check(s As String) As Boolean

   '代码略!若学生选科代码有效,函数返回True,否则返回False

End Function

举一反三
某超市举行VIP客户积分换购活动,VIP客户根据卡内积分多少可换取不同额度的代金券。假设VIP客户共有n名,VIP卡内积分存放在数据库“customer.accdb”的Integral表中,换购活动的VB程序代码如下,程序运行时界面如图所示。工作人员在文本框Text1中输入VIP卡号后,单击“换购”按钮Command1,在文本框Text2中输出VIP客户的积分数,在标签Label3中显示可以换购的代金券额度,积分清零。按此要求编写程序如下, 但加框处代码有错,请改正。

Dim ID( ) As String    '用于存放客户卡号

Dim total( ) As Long      '用于存放积分数

Dim sc As Long                  'VIP客户人数

Dim jf As Long                  '积分数


Private Sub Command1Click( )

  Dim k As String                '客户卡号

  Dim q As Long               '代金券额度

  Dim i As Long

  k = Text1.Text

  For i = 1 To sc     ’顺序查找

      If ID(i) = k Then

          jf = total(i)     

          cash(jf) = q               ’ ①

          Exit For

      End If

                                     ’ ②

      Label3.Caption = “您可换购的代金券总额为:”+ Str(q) + “元”

    Next i

  End If

End Sub


' cash函数用于计算VIP客户可换购的代金券额度

Function cash(jf As Long) As Long

  If jf >= 2000 And jf <= 20000 Then

       Cash = jf\2000*10

ElseIf jf > 20000 And jf <= 50000 Then

       Cash = jf\2000*11

ElseIf jf > 50000 And jf <= 100000 Then

       Cash = jf\2000*12

ElseIf jf > 100000 And jf <= 150000 Then

       Cash = jf\2000*13

ElseIf jf > 150000 Then

       Cash = jf\2000*14

End If

End Function


Private Sub FormLoad()

   Dim conn As New ADODB.Connection, rs As New ADODB.Recordset

   Dim intSQL As Long

   conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App.Path + "\ customer.accdb"

    conn.Open

   intSQL = "SELECT score  FROM Integral" 

     Set rs.ActiveConnection = conn

     rs.CursorType = adOpenStatic

     rs.Open intSQL

     sc = 0

     Do While Not rs.EOF

       sc = sc + 1

       total(sc) = rs.Fields("score")

       rs.MoveNext

     Loop

rs.Close

     conn.Close

     Set rs = Nothing

     Set conn = Nothing

End Sub

小月设计了一个VB程序,用于对全班55名同学的体质调查分析,该程序能将55名同学的身高与体重录入到数据库中,之后通过如图所示的VB应用程序计算出这些同学的BMI指数,并按BMI指数从小到大进行排序,并显示这些学生的体质情况。

    注:BMI指数的计算公式为:BMI=体重(千克)除以身高(米)的平方(kg/m2)。 BMI<18.5为偏瘦(表明营养不足);BMI=18.5~24.9为体重正常;BMI=25~29.9为超重;BMI>30为肥胖。

该VB应用程序的代码如下:

Dim stuBMI(1 To 55) As Single

Dim stuName(1 To 55) As String

Private Sub Command1_Click()

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

    Dim t1 As Single, t2 As String

    Dim Results As String

    For i = 1 To 54        

        For j = i + 1 To 55

            If stuBMI(j) < stuBMI(k) then      ②    

        Next j

        If  k<>I  Then  

            t1 = stuBMI(i): stuBMI(i) = stuBMI(k): stuBMI(k) = t1

            t2 = stuName(i): stuName(i) = stuName(k): stuName(k) = t2

        End If

    Next i

List1.AddItem "姓名" + vbTab + "BMI指数" + vbTab + "结果"  

    For i = 1 To 55

        If stuBMI(i) < 18.5 Then

            Results = "偏瘦"

        ElseIf stuBMI(i) >= 18.5 And stuBMI(i) < 25 Then

            Results = "正常"

        ElseIf stuBMI(i) >= 25 And stuBMI(i) < 30 Then

            Results = "超重"

        Else

            Results = "肥胖"

        End If

        List1.AddItem stuName(i) + vbTab + str(stuBMI(i)) + vbTab + Results

    Next i

End Sub

Private Sub Form_load()

    Dim conn As New ADODB.Connection

    Dim rs As New ADODB.Recordset

    Dim strSQL As String

    Dim i As Integer

    conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App.Path + "\Student.accdb"

    conn.Open

    strSQL = "SELECT * FROM Student"

    Set rs.ActiveConnection = conn

    rs.Open strSQL

    i = 0

    Do While Not rs.EOF

        i = i + 1

        stuName(i) = rs.Fields("StuName")

        stuBMI(i) = Round(rs.Fields("Weight") / rs.Fields("height") ^ 2, 1)

        rs.MoveNext

    Loop

    rs.Close

    conn.Close

    Set rs = Nothing

    Set conn = Nothing

End Sub

小明利用所学的知识帮助语文老师设计一个语文学考等级查询系统,要求如下:输入某个等级,就能查出该等级的所有学生学号和姓名,并统计出该等级学生的人数,以便语文老师方便了解学生的学考情况。语文学考成绩分A、B、C、D、E五个等级,学生信息存储在数据库文件“stugrade.accdb”的数据表“Chinese”中,数据表“Chinese”的结构如图1所示。

VB程序运行界面如图2所示,在文本框Text1中输入查询的等级,单击“查询”按钮Command1,在列表框List1中显示所有该等级的学生学号和姓名,并按照学号从小到大排序,并在标签Label2处显示学生的人数,如果人数为0,则在列表框中显示“没有该等级的学生”。按此要求编写程序如下,但加框处代码有错误,请改正。

Private Sub Command1_Click()

Dim stuna(1 To 100) As String '存放学生姓名的数组定义为stuna

Dim stunum(1 To 100) As String '存放学生学号的数组定义为stunum

Dim i As Integer, j As Integer, n As Integer

Dim t As String


'连接数据库

Dim cn As New ADODB.Connection

Dim rs As New ADODB.Recordset

Dim strSQL As String

cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + App.Path + "\stugrade.accdb"

cn.Open

strSQL = "select * from Chinese where 语文等级='" + Text1.Text + "'"

Set rs.ActiveConnection = cn

rs.Open strSQL

n = 0

Do While Not rs.EOF

   n = n + 1

   stuna(n) = rs.Fields("姓名").Value

   stunum(n) = rs.Fields("学号").Value

   rs.NextMove          '①

Loop

rs.Close

cn.Close

Set rs = Nothing

Set cn = Nothing


List1.Clear '清除列表框

If n = 0 Then

   List1.AddItem "没有该等级的学生"

Else

   For i = 1 To n - 1       '按姓名排序

      For j = n To i + 1 Step -1

         If stuna(j) < stuna(j - 1) Then       '②

            t = stunum(j): stunum(j) = stunum(j - 1): stunum(j - 1) = t

            t = stuna(j): stuna(j) = stuna(j - 1): stuna(j - 1) = t

         End If

     Next j

   Next i

   For i = 1 To n

      List1.AddItem stunum(i) + "  " + stuna(i)

   Next i

   Label2.Caption = "该等级的学生共有" + Str(n) + "名"

End If

End Sub

学校需要统计学生的作业完成数,需要将学生的完成数按从高到低显示,下列程序模拟该信息处理过程,程序在数据库stud中找到的学生信息(编号和完成次数),并将所有学生按照完成数从高到低显示。先将所有学生的编号和完成次数从数据库stud的info表中ID和finshed两字段中取出分别保存在数组a和数组b中,第i个学生的编号保存在a(i)中,对应的作业完成次数保存在b(i)中。

数据库文件“stud. accdb”信息如图所示。

程序界面如图所示,左边列表框List1中显示所有学生信息(包括编号和完成次数),单击“排序”按钮(Command),所有编号按照作业完成次数从高到低显示在列表框List2中。

代码如下:

Dim conn As New ADODB. Connection

Dim rs As New ADODB. Recordset

Dim n As Integer

Dim a(500)As String

Dim b(500)As Integer

Private Sub Fom Load()

    Dim i As Integer

    conn. Connection String="Provider=Mi-crosoft. AC

    A.OLEDB. 12.0;DATA Source="& App. Path &"\stud. accdb"

    conn Open

    Set rs. Active Connection=conn

    rs. Open "Select*From info"

    n=0

    Do While not rs.EOF            '到记录集最后一条记录后退出循环

        n=n+1

        a(n)=rs. fields("id")

        b(n)=rs. fields("finshed")

        rs. MoveNext                 '移动到下一条记录

    Loop

    For i=1 To n

        List1. AddItem a(i)+" "+Str(b(i))

    Next i

    rs. Close

    conn. Close

    Set rs= Nothing

    Set conn= Nothing

End sub

Private Sub Command1_Click()

    Dim i As Integer, j As Integer, t1 As Integer, t2 As String, k As Integer

    For i=1 To n-1             'n表示学生总数

        k=i           'k保存第i大的数,一开始假定是a(i)

        For j=i+1 To n

            If b(k)<b(j) Then k=j            '比较完成数

                ①      

            If    ②      Then

                t1=b(i): b(i)=b(k): b(k)=t1           '交换完成次数

                t2=a(i): a(i)=a(k): a(k)=t2           '交换编号

            End If

        Next j

    Next i

    For i=1 To n          '在列表框List2中输出排序结果

        Listt2. Addltem a(i)+" "+Str(b(i))

    Next i

End sub

求老师想按学生的成绩进行评级,分数和等级对应关系如下表:

分数

0~59

60~69

70~79

80~89

90~99

等级

E级

D级

C级

B级

A级

现要求根据上表统计出各等级学生人数占总人数的比例。小李编写了一个VB程序帮助老师实现该功能:程序运行时,将每位学生的得分(两位整数)存储到数组a中,并在列表框List1

中显示。单击“统计”按钮后,在列表框List2中显示从A级至E级,各等级的人数占总人数的百分比例(四舍五入保留整数)。程序运行界面如图所示:

请阅读代码,并回答以下问题:

Dim n As Integer

Dim a(1 To 50) As Integer

Private Sub Form_Load( )

    Dim adocn As New ADODB. Connection

    Dim adors As New ADODB. Recordset

    Dim str1 As String

    adocn.ConnectionString = "Provider = Microsof.ACE.OLEDB.12.0;Data source=" +App. Path +”\school. accdb”

    adocn. Open

    str1 =“select * from students”

    ardors.Open str1, adocn

    '将每个学生的得分读入数组a中,并在列表框list1中显示,统计学生总人数n

    '代码略

End Sub

Private Sub Comd1_C1ick( )

    Dim cou As Integer,k as Integer

    Dim b(0 To 4) As Integer

    Const dj = “A级B级C级D级E级”

    For i=1 Ton

    k=a(i)\10-5

    If k<0 Then     ①    

    b(k)= b(k) + 1

    Next i

    For i=0 To 4

      cou =       '⑶改错

      List2. AddItem       ②      + Str(cou) +“%”

    Next i

End Sub

返回首页

试题篮