试题

试题 试卷

logo

题型:单选题 题类:模拟题 难易度:普通

浙江省杭州市2016年信息技术高考模拟卷五

【加试题】一组数据 22,94,17,125,63,若采用冒泡排序算法对其进行升序排列,则需要经历几遍加工?第一次加工交换多少次?(   )
A、2,2 B、4 ,2 C、2,3 D、4,3
举一反三
小月设计了一个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

【加试题】字符串排序。编写VB程序,实现如下功能:程序运行时,单击命令按钮Command1 产生100个随机字符串(每个字符串长度不超过10),并显示在列表框List1中,单击命令按钮Command2对产生的100个随机字符串按权值进行降序排序,将排序结果显示在列表框List2中。每个字符串的权值定义为该字符串中ASCII码值最大的字母的ASCII码值,例如字符串“Hello”中ASCII码值最大的字母是“o”(ASCII码值为111),则字符串“Hello”的权值为111。程序运行效果如图所示。实现上述功能的VB代码如下,但加框处代码有错,请改正。

Dim a(1 To 100) As String '依次存放100 个随机字符串

Dim b(1 To 100) As Integer '依次存放每个字符串的权值

Private Sub Command1_Click() '产生100 个随机字符串

Dim i As Integer, k As Integer, t As Integer, x As Integer

Randomize

For i = 1 To 100

k = Int(Rnd * 10 + 1) : t = 0  'k 表示第i 个字符串的长度

Do While t < k '通过循环依次产生第i 个字符串a(i)的k 个字符

If Int(Rnd * 2 + 1) = 1 Then '产生一个小写字母的ASCII 码值

x = Asc("a") + Int(Rnd * 26)

Else

x = Asc("A") + Int(Rnd * 26) '产生一个大写字母的ASCII 码值

End If

                '①

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

t = t + 1

Loop

List1.AddItem a(i)

Next i

End Sub

Private Sub Command2_Click() '对100 个字符串按字符串权值降序排序

Dim i As Integer, j As Integer, y As Integer

Dim s As String

For i = 1 To 99

k = i

For j = i + 1 To 100

    '②

Next j

If k <> i Then

s = a(k): a(k) = a(i): a(i) = s

y = b(k): b(k) = b(i): b(i) = y

End If

Next i

For i = 1 To 100

List2.AddItem a(i)

Next i

End Sub

①{#blank#}1{#/blank#} ②{#blank#}2{#/blank#} 

返回首页

试题篮