题型:填空题 题类:常考题 难易度:困难
浙江省杭州市第二中学2015-2016学年高二下学期信息技术期中考试试卷
Dim a(1 To 6) As Integer
Dim b(1 To 6) As Integer
Private Sub Command1_Click() '对数组a中的数据进行排序
Dim i As Integer, j As Integer ,k as integer
a(1) = 53 :a(2) = 18:a(3) = 62:a(4) = 22:a(5) = 6:a(6) = 25
s = ""
For i = 1 To 5
k = i
For j = i + 1 To 6
If a(k) > a(j) Then
Next j
If i <> k Then
t = a(k): a(k) = a(i): a(i) = t
End If
Next i
For i = 1 To 6
s = s + Str(a(i))
Next i
Label1.Caption = s
End Sub
Private Sub Command2_Click()
b(1) = 3: b(2) = 8: b(3) = 15: b(4) = 27: b(5) = 38: b(6) = 49
'此处部分代码省略
End Sub
Private Sub Command3_Click()
'将数组a和b中的数据逐个比较后添加到新的字符串s中,并将s在label3中显示
i = 1: j = 1: s = ""
Do While i <= 6 j <= 6 '如果两数组都还有数据未合并
If Then
s = s + Str(a(i)) : i = i + 1
Else
s = s + Str(b(j)) : j = j + 1
End If
Loop
Do While i <= 6 '只有数组a还有数据未合并
s = s + Str(a(i)) : i = i + 1
Loop
Do While j <= 6 '只有数组b还有数据未合并
s = s + Str(b(j)) : j = j + 1
Loop
Label3.Caption = s
End Sub
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
原始数据:
a(1) |
a(2) |
a(3) |
a(4) |
1 |
2 |
3 |
4 |
方法一:
①向右旋转1步:
a(1) |
a(2) |
a(3) |
a(4) |
4 |
1 |
2 |
3 |
②向右旋转2步:
a(1) |
a(2) |
a(3) |
a(4) |
3 |
4 |
1 |
2 |
③向右旋转3步:
a(1) |
a(2) |
a(3) |
a(4) |
2 |
3 |
4 |
1 |
方法二:
①将a(1)值放至旋转3个位置后位置a(4):
a(1) |
a(2) |
a(3) |
a(4) |
1 |
2 |
3 |
1 |
②将原a(4)值放至旋转3个位置后位置a(3):
a(1) |
a(2) |
a(3) |
a(4) |
1 |
2 |
4 |
1 |
③将原a(3)值放至旋转3个位置后位置a(2):
a(1) |
a(2) |
a(3) |
a(4) |
1 |
3 |
4 |
1 |
④将原a(2)值放至旋转3个位置后位置a(1):
a(1) |
a(2) |
a(3) |
a(4) |
2 |
3 |
4 |
1 |
有n个数存储在数组a中,给定一个整数p(1≤p≤n),将数组a的前p个数与后n-p个数分别向右旋转k次。例如数组a的各个数值分别是1,2,3,4,5,6,7,当p=4,k=1时,旋转后的结果为4,1,2,3,7,5,6。小明为此编写了VB程序,功能如下:在文本框Text2、Text3中依次输入p和k的值,单击“旋转数组”按钮Command1后,数组旋转后结果显示在Text4中。程序运行界面如图1所示,请回答下列问题:
图1
试题篮