试题

试题 试卷

logo

题型:单选题 题类:常考题 难易度:普通

浙江省浙南名校联盟2020届高三上学期信息技术第一次(10月)联考试卷

有如下 VB 程序段:

 For i = 1 To 2

    For j = 1 To 6 - i

        If a(j) - a(j + 1) > 0 Then

           t = a(j): a(j) = a(j + 1): a(j + 1) = t

        End If

     Next j

  Next i Text1.Text = "" For i = 1 To 6

  Text1.Text = Str(a(i)) + Text1.Text Next i

数组元素a(1)到a(6)的初值依次为15,11,58,38,26,9,执行该程序段,文本框Text1显示的内容是(  )

A、9 58 11 38 15 26 B、11 15 26 9 38 58 C、58 38 9 26 15 11 D、58 9 38 11 26 15
举一反三
【加试题】某校举行班班有歌声比赛,参赛班级的成绩按照班级序号保存在“bbygs.accdb”数据库文件中,为了快速计算每个班级最终的分,设计了一个VB程序,该程序能够将8个评委的打分按照从高到低的顺序排序,然后去掉一个最高分和一个最低分,最后计算平均值作为参赛班级的成绩。程序界面如图:单击“提取”按钮Command1,在列表框list1中显示班级序号和该班级8个评委的打分成绩,单击“排序”按钮Command2后,在列表框list2中按降序排序。单击计算得分按钮Command3,在文本框text1中显示最终成绩。按此要求编写程序如下:

Dim class(1 To 30) As Integer '存放班级序号的数组定义为class

Dim score(1 To 8) As single '存放班级各评委打分的数组定义为score

Private Sub Formload()      '提取某班级的评委打分

   Dim conn As New ADODB.Connection

Dim rs As New ADODB.Recordset

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

   conn.Open

   Set rs.ActiveConnection = conn

   rs.Open "SELECT * FROM score " 

   n = 0

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

   n = n + 1

   class (n) = rs.Fields("班级序号").Value

   score (n) = rs.Fields("评委打分").Value

   rs.MoveFirst      '①指针移动到下一条记录

Loop

rs.Close

cn.Close

Set rs = Nothing

Set cn = Nothing

for i=1 to n

    List1.AddItem str(score(i))

Next i

End sub

Private Sub Command1Click()  

Dim i as integer

Dim j as integer

Dim t as single

For i = 1 to 8

  For j=1 to i

    If   ②  then  

t=score(j) 

score(j)=score(j+1)

score(j+1)=t

End if

  Next j

Next i

For i=1 to 8

   List2.AddItem str(score(i))

Next i

End sub

Private Sub Command2Click()   '计算班级平均得分

Dim i As Integer

Dim sum As single

For i=2 to 7

   sum=sum+score(i)

Next i

Text1.text=  ③ 

End sub

返回首页

试题篮