Dim a(1 To 3) As Single,i As Integer
Randomize
a(1) = 1
For i =2 To 3
a(i) = (Int(Rnd() * 3)) *2- 2
a(i) = Abs(a(i - 1)) / Sqr(a(i))
Next i
List1.AddItem Str(a(i))
运行该程序段,下列错误提示不可能会出现的是( )
Dim a(1 To 6) As Integer
Dim d(1 To 6) As Integer
a(1) = 10: a(2) = 21: a(3) = 28: a(4) = 11: a(5) = 12: a(6) = 30
Const n = 6
For i = n To 1 Step -1
d(i) = 0
For j = n To i +1 Step -1
If a(j) > a(i) Then d(i) = d(j) + 1
Next j
If d(i) > Max Then Max = d(i)
Next i
Text1.Text = Str(Max)
执行该程序段,文本框Text1中显示的是( )
n = 7
d(1) = 123: d(2) = 35: d(3) = 43: d(4) = 23: d(5) = 56: d(6) = 78: d(7) = 132
k = 1
For i =2 To n
For j = ⑴
If ⑵ Then
tmp = d(j): d(j) = d(j + 2): d(j + 2) = tmp
End If
Next j
k = -k
Next i
执行该程序段后,d 数组各元素为“132,23,123,35,56,78,43”,上述程序段中方框处可选语句为:
①i -1 To n - 2
②1 To n - i
③d(j) * k > d(j + 2) * k
④d(j) * (-k) > d(j + 2) * (-k)
则(1)(2)处语句依次可为( )
Private Sub Command1_Click()
Dim d(1 To 10) As Integer, i As Integer, j As Integer
Dim m As Integer, key As Integer, s As String
key = Int(Rnd( ) * 50) *2+ 1
s = "": i = 1: j = 10
Do While i <= j
m = (i + j) \ 2
If key = d(m) Then Exit Do
If key < d(m) Then
j = m - 1: s = s + "L"
Else
i = m + 1: s = s + "R"
End If
Loop
Label1.Caption = s
End Sub
若数组d(1)至d(10)的值依次为"11,13,20,48,51,67,70,73,80,91",若执行后 Label1 上显示2个“L”和1个“R”或2个“R”和1个“L”,则key的可取值个数为( )
图a |
该同学想将图中灰色背景去除,另存为透明背景的图片文件,导入Flash中。正确的操作步骤是⑤-⑦-。(选取序号,按操作顺序填写)
①在工具箱中选择“魔棒”工具;
②在工具箱中选择“套索”工具;
③设置合适的“容差”值;
④设置合适的“羽化”值;
⑤复制“背景”图层;
⑥单击灰色背景部分,点[delete]键;
⑦选择“背景副本”图层;
⑧隐藏“背景”图层;
图b |
编写VB程序,依据上述要求排队。运行程序,在列表框 List1中显示了排序前的人员身高,单击“排序”按钮Command1后,在列表框List2中显示身高升序排序结果,再单击“站位”按钮Command2后,按10人一排站好,结果显示在列表框List3中。界面如图所示。
Dim h(0 To 40) As Integer '学生身高
Dim n As Integer
Private Sub Form_Load()
'从数据库中读取身高,共n条记录,存入h数组中,代码略
End Sub
Private Sub Command1_Click()
For i =2 To n
h1 = h(i): j = i – 1
Do While
j = j - 1
Loop
For k = i To j +2 Step -1
h(k) = h(k - 1)
Next k
①
Next i
'在列表框 List2中输出排序结果,代码略
End Sub
Private Sub Command2_Click()
'按人数每10人一排
Dim x As Integer
x = n \ 10
For i =1 To x
Call fenpai( ② ) '过程fenpai作用:将人员按中间低两边高排好,代码略
Next i
If n Mod 10 >0 Then Call fenpai(x * 10 + 1, n)
'将站位结果输出在列表框 List3 中,代码略
End Sub
① ②
按上述要求,编写VB程序,功能如下:在文本框Text1中输入预计礼物数,在文本框 Text2中输入总金额,单击“计算”按钮Command1,在列表框List1中显示各类商品的编号、单价、数量、喜爱度,以及最佳购买方案、剩余金额和总喜爱度,若有多种最佳方案,则输出第一个找到的方案信息,如图a所示。
图a |
Const m = 4 '有 m 种商品
Dim sph(1 To m) As String '商品号
Dim dj(1 To m) As Single '单价
Dim sl(1 To m) As Integer '数量
Dim xa(1 To m) As Integer '喜爱度
Dim hh(1 To m * 10) As Integer '每件商品对应的货号
Dim p As Integer,n As Integer,nc As Integer 'p个朋友,n元钱,共nc件商品
Dim zxa As Integer '总喜爱度为每件购买商品的喜爱度*购买数量的总和
Private Sub Form_Load()
'各商品的商品号、单价、数量、喜爱度分别存入数组 sph、dj、sl 和 xa 并输出,代码略
End Sub
Private Sub Command1_Click()
Dim goumai(1 To m * 10) As Integer
Dim i As Double,j As Integer,k As Integer,t As Integer
Dim fs As Integer,je As Integer,maxi as Integer,maxje As Integer,maxzxa As Integer
p = Val(Text1.Text): n = Val(Text2.Text)
nc = 0
For i =1 To m
For j =1 To sl(i)
nc = nc + 1: ①
Next j
Next i
For i =0 To 2^ nc - 1
t = i
For j =1 To nc
goumai(j) =②
t = t \ 2
Next j
fs = 0: je = 0: zxa =0 '初始化份数,金额,总喜爱度
For j =1To nc
fs = fs + goumai(j): je = je + dj(hh(j)) * goumai(j): zxa = zxa + xa(hh(j)) * goumai(j)
Next j
If fs = p And ③ Then maxi = i: maxje = je: maxzxa = zxa
Next i
'输出maxi对应的购买方案,代码略
If maxje >0 Then List1.AddItem "剩余金额:" & CStr(n - maxje) & " 总喜爱度:" & CStr(maxzxa)
Else
List1.AddItem "钱太少"
End if
End Sub
图b |