2011至2012年VB高考题

发布时间 : 星期五 文章2011至2012年VB高考题更新完毕开始阅读

Print a(yu); Next yu

八、程序填空

1.下面的程序前部分功能考生自己分析,后部分功能是输入一数据,然后在数组中找此数据,若找不到则程序结束,若找到将数组元素下标小于此数据下标的数据由大到小排列并输出,请在空白位置填写正确的命令(Visual Basic题)。

Dim a(9) As Integer Dim i As Integer Dim t As Integer

a(0) = 20 + Int(Rnd * 91) For i = 1 To 9

t = 20 + Int(Rnd * 91) If t < a(i - 1) Then i = i - 1 Else a(i) = t End If Next i For i = 0 To 9 Print a(i); Next i Print

t = InputBox(\For i = 0 To 9

If t = (1) Then Exit For End If Next i

If i = 10 Then End i = i - 1

For k = 0 To i / (2) t = a(k) a(k) = a(i - k) a(i - k) = t Next k

For i = 0 To 9 Print a(i); Next i

2.下面程序可以打印一个九九表完整九行或部分行,思路是在窗体中加入两个文本框,第一个文本框(text1)用于指定输出九九表的起始行,第二个文本框用于指定输出九九表的结束行,如在第一个文本框中输入2,第二个文本框中输入6,打印出如图所示的2到6 行。命令按钮的单击事件中有打印九九表的程序,请在空白位置填写正确的命令(程序要求:第一个文本框数字必须比第二个文本框小,两个文本框中不能为空)(Visual Basic题)。

Private Sub Command1_Click() Dim a As Integer Dim b As Integer

If Text1.Text <> \(3)Text2.Text <> \Then

a = Text1.Text b = Text2.Text If a < b Then Dim i As Integer Dim j As Integer For i = a To b For j = 1 To i

Print j; \

Next j Print Next i

Else

MsgBox \起始行大于结束行,重新输入!\

Text1.Text = \Text2.Text = \Text1.SetFocus End If Else

MsgBox \文本框中不能为空\Text1.SetFocus End If End Sub

3.阅读下面的VB程序,分析程序中k=k+a的执行次数是____________ Dim a%,i%,j%,k% A=0:k=0 For i =1 to 10 For j=1 to i a=a+i+j K=k+a K=k-1 Next j,i

4.有10个元素的一维数组A,已经按由小到大的顺序排列好,现输入一个数据,然后在数组中查找此数,若找到则求小于等于它的元素之和。请填空。 Option base 1 Dim a

Dim k as integer,s as integer,i as integer,b as integer

A=array(-2,4,7,8,12,25,26,31,89,95) B=inputbox(“请输入数据”,“”,””) S=0

For i =1 to 10

If b=a(i) then _______________ Next i

If i <= 10 then For k=1 to ___________ S=s+a(k)

Next k End if Print s

5.窗体中有三个标签,三个文本框从上到下依次是Text1,text2,text3,一个命令按钮Command1。三个标签用来标示右边文本框的用途,Text1用来输入数据,数据之间用空格分开,Text2用来存放奇数和,Text3用来存放偶数和。在Text1中输入一组数据后,单击求和命令按钮,Text2将显示Text1中的奇数和,Text3中将显示Text1中的偶数和。代码如下。请填空 Private sub command1_click() Dim s$,c$,c1$ Dim k%,w%,i%,t1%,t2% I=0:T1=0:T2=0 S=Trim(Text1.text) W=len(s) C=”” C1=mid(s,1,1) I=i+1

Do while i <=w

Do while c1 <> chr(32) and _________

C=_________________ I=i+1

C1= mid(s,i,1) Loop K =val(c)

If k mod 2 <> 0 then t1 = t1+k else t2=t2+k

I=i+1 C1=mid(s,i,1) C=”” Loop

Text2.text =t1 Text3.text =t2 End sub

联系合同范文客服:xxxxx#qq.com(#替换为@)