题库 高中信息

题干

某班级学生为毕业晚会的一个节目设计一个仿“V”字造型,先筛选出班级里所有男生,然后将参演的n名男生按照身高,摆出中间低两边高(先右后左)的造型,如图1 所示。王林同学用VB编写模拟“节目造型”程序,功能如下:从数据库中导出所有学生编号、性别和身高数据;单击“筛选排序”按钮Command2,根据身高仿“V”字和造型进行有序排列,并将结果显示在文本框Text2 中。程序运行界面如图2
所示。举例说明如下:
原1-7号男生身高
171 172 180 174 176 179 178
筛选排序后序列
171 172 174 176 178 179 180
“造型设计”后序列
180 178 174 171 172 176 179
 

图1
身高顺序:男3号〉男6号〉男7号〉男5号〉男4号〉男2号〉男1号

图2
Const n = 7
Dim h2(1 To n) As Integer
Dim height1(1 To n) As Integer
Dim height2(1 To n) As Integer
Dim i As Integer, j As Integer, temp As Integer
Dim sex(1 To n) As Boolean '男生sex=true
Private Sub Form_Load()
'n名学生的身高和性别由数据库导出,分别存储在数组height1 和sex中,代码略!
End Sub
Private Sub Command1_Click()
For i =" 1" To n - 1
For j =" n" To i + 1 Step -1
If  Then
temp =" height1(j):" height1(j) =" height1(j" - 1): height1(j - 1) = temp[:学#科#网]
End If
Next j
Next i
For i =" 1" To n
Text1.Text =" Text1.Text" + " " + Str(height1(i))
Next i
End Sub
Private Sub Command2_Click()
Dim left, right As Integer, i As Integer, mid As Integer
mid =" Int((1" + n) / 2)
left =" 0:" right = 0

For i =" 2" To n Step 2
right =" right" + 1
height2(mid + right) = height1(i)
left =" left" + 1

Next i[ZXXK]
For i =" 1" To n
Text2.Text =" Text2.Text" + " " + Str(height2(i))
Next i
End Sub
上一题 下一题 0.99难度 填空题 更新时间:2017-02-17 10:34:46

答案(点此获取答案解析)

同类题2

小明用 VB编写了一个连续高温天数的统计软件。小明采集了金华市 7-8 月的每日最高气温,并存放在 ACCESS数据库中。程序运行时,读取日期和最高气温并显示在列表框 List1 中,在文本框 Text1 中输入温度值,单击“统计”按钮 Command1,程序自动统计运行在该温度值及以上的最长连续天数,并显示在 Text3 中,同时在 Text2 中显示日期区间,运行界面如下图所示。

实现上述功能的 VB 代码如 下,在划线处填入合适代码。
Dim rq(1 To 100) As String ‘ 存放日期
Dim qw(1 To 100) As Integer ‘ 存放最高气温值
Dim n As Integer '总天数
Private Sub Form_Load()
' 读取数据库内容,其中日期数据存放在数组 rq 中,最高气温数据存放在 qw 中,第 i 个日期保存在 rq(i)中,对应的气温保存在 qw(i)中,并显示在列表框 List1 中,代码略
End Sub
Private Sub Command1_Click()
Dim ntempend As Integer ‘ 记录当前结束日期的下标
Dim max As Integer   ‘ 记录最大连续天数
Dim nend As Integer ‘ 记录最大连续天数下的结束日期的下标
Dim ncount As Integer ‘ 统计连续天数
Dim tjqw As Integer   ‘ 存放输入的温度
tjqw = Val(Text1.Text)
ncount = 0
max = 0
For i = 1 To n
If  ___________①___________ Then
ncount = ncount + 1
ntempend =i
Else
ncount = 0
End If
If max < ncount Then
max = ncount
___________②___________
End If
Next
If max <> 0 Then Text2.Text = ___________③___________ & "-" & rq(nend)