题库 高中信息

题干

某VB程序功能如下:输入正整数n,单击命令按钮Command1后,则会生成一串有规律的数字序列,形式为“n  n-1  n-2 … 3  2  1  2  3 … n-2  n-1  n”。例如n=8时,生成的数字序列如图所示。代码如下:

Private Sub Command1_Click()
Dim n As Integer, i As Integer, s As String
n = Val(Text1.Text)
s = ""
For i =" 1" To 2 * n - 1
If i <=" n" Then   Else    
Next i
Label1.Caption = s
End Sub
为实现以上功能,划线①②处应分别填写
A.①s =" s" & Str(n - i + 1)   ②s =" s" & Str(i - n + 1)   
B.①s =" Str(n" - i + 1) ②s =" Str(i" - n + 1)
C.①s =" s" & Str(i - n + 1)   ②s =" s" & Str(n - i + 1)   
D.①s =" Str(i" - n + 1) ②s =" Str(n" - i + 1)
上一题 下一题 0.99难度 选择题 更新时间:2017-02-17 10:22:34

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

同类题1

纪念品分组问题。某教师节晚会的纪念品分组规则如下:按纪念品价值进行分组,每组总价值不超过限定值w且最多包含两件,要求分组数最少。编写VB程序解决该问题,程序运行时,在文本框Text1中依次输入每件纪念品的价格(不超过w),以逗号分隔,在文本框Text2中输人限定值w,单击“分组”按钮,在标签 Label2上输出最少的分组数。程序运行界面如图所示。

(1)要使程序启动后,窗体的标题栏显示“纪念品分组”文字,可在 Form Load事件过程中添加语句   (单选,填字母:
A.Form1="纪念品分组"/B.Form1.Name="纪念品分组"/C.Form1. Caption="纪念品分组"/D.Fom1.Text="纪念品分组")。
(2)实现上述功能的VB程序如下,请在划线处填入合适的代码;并且加框处代码有错,请改正。
Private Sub Command1 Click()

Dim a(l To 1000), n As Integer, w As Integer,cnt As Integer

Dim i As Integer, j As Integer, t As Integer

Dim s As String, ch As String

Dim p As Integer, q As Integer

S= Textl. Text: w =Val(text2. Text): n=0

For i=1 To Len(s)

ch=Mid(s, i, 1)

If ch="."Then

n=n+1:a(n)=t: t=0

Else

t=____________________

 End If

Next i
For i=n To 2 Step-1

For j=1 To '②

If a(j)< a(j+1)Then
t=a(j):a(j)=a(j+1):a(j+1)=t

End If

   Next j
Next i
cnt= 0
p=1: q=n
Do While p<q

cnt=cnt+1

If _________________ Then

p=p+1:q=q-1

Else

p=p+1

End If

Loop
If p=q Then cnt=cnt+1
Label2 Caption- Str(cnt)
End sub
(3)若在文本框Text1中输入“50,30,100,70,80,40,50,20”,文本框Text2中输人“110”,单击“分组”按钮,标签Labe2中显示的内容是____________。