2007年秋至2010年秋江苏省计算机二级VB考试真题及参考答案 联系客服

发布时间 : 星期六 文章2007年秋至2010年秋江苏省计算机二级VB考试真题及参考答案更新完毕开始阅读

Next I End Sub

3.执行下面的程序,单击Commandl,则窗体上第一行显示的是 (7) ,第二行显示的 是(8) 。

Option Explicit Dim X As Integer

Private Sub Commandl_Click() Dim Y as Integer X=10:Y=2 Call process(Y) Print X,Y

Call process((Y)) Print X,Y End Sub

Private Sub process(n As Integer) Dim Y As Integer If n>0 Then X=X—n Y=X Else

X=X+n Y=X+2 End If n=-n End Sub

4.执行下面的程序,连续三次单击命令按钮Commandl之后,A数组共有 (9) 个元 素;数组元素A(2)的值是(10) ,A(4)的值是.(11) 。 Option Explicit Option Base 1

Private Sub Commandl_Click() Static A()As Integer,n As Integer Dim i As Integer,k As Integer k=n ? n=n +2

ReDim Preserve A(n) For i=k+1 To n A(i)=i*n+1 Next i

For i=1 To n Print A(i); Next i Print End Sub

5.执行下面的程序,单击Commandl,在窗体界面上显示的第一行是 (12) ,第二行

是 (13) ,第三行是(14) ,第四行是(15) 。 Option Explicit

Private Sub Commandl_Click()

Dim a As Integer,b As Integer,i As Integer i=1218 a=i\\100

b=i Mod 100 If b<>0 Then Print a Print b

. Print Lcd((a),(b));a;b Print Lcd(a,b);a;b End If End Sub

Private Function Lcd(x As Integer,Y As Integer)As Integer Dim d As Integer ? If x

d=x:x = Y:Y = d End If d=X Do

If x Mod Y=0 Then Lcd=x Exit Do Else X=x+d End If Loop End Function

6.本程序的功能是利用无穷级数求cos(x)的近似值,已知: 当第n项的绝对值小于等于10^-7时计算终止。 Option Explicit

Private Sub Commandl_Click()

Dim X As Single,n As Integer,sum As Single Dim a As Single x=Textl ( 16 ) a=1 n=1 Do a=-a

a=( 17 ) sum=sum+a n=n+1

Loop Until( 18 ) Text2=sum End Sub

7.定义方阵的一种范数为该方阵各列元素的绝对值之和中的最大值。以下程序的功能 是求一个4×4方阵的范数。该方阵的数据是随机生成的-20~20之间的整数。 Option Explicit Option Base 1

Private Sub Commandl_Click() Dim a(4,4) As Integer

Dim i As Integer,j As Integer For i=1 T0 4 For j=1 To 4

a(i,j)= ( 19 )

Picturel.Print Right(\ &Str(a(i,j)),4); Next j

Picturel.Print Next i

Textl.Text= ( 20 ) End Sub

Private Function fan(a()As Integer)As Integer Dim b(4) As Integer,max As Integer Dim i As Integer,j As Integer For i=1 To 4 For j=1 To 4

b(j)=( 21 ) Next J Next i max=b(1)

For i=2 To 4 If max Next i fan=max End Function

8.下面程序的功能是:找出仅由数字1、2、3、4组成的4位素数,要求每个素数由4个不 同数字组成。算法提示:函数Validate用于验证一个4位数是否由4个不同数字组成。在函 数中用A数组的各个元素分别对应数字0~9,只要某数字出现在四位数中,无论几次,均将该数字对应的数组元素值置为1。 Option Explicit

Private Sub Commandl_Click()

Dim i As Integer,Flg As Boolean For i=1234 To 4321

( 22 )

Call Prime(i,Flg) If Flg Then

If Validate(i)Then

Textl=Textl & i & vbCrLf . End If End If Next i End Sub

Private Sub Prime(n As Integer,f As Boolean) Dim k As Integer For k=2 To Sqr(n) ( 23 ) Next k f=True End Sub

Private Function Validate(n As Integer)As Boolean

Dim A(0 To 9)As Integer,s As String,i As Integer Dim sl As String*1 . ( 24 ) For i=1 To Len(s) sl=Mid(s,i,1) ( 25 ) Next i

If A(1)+A(2)+A(3)+A(4)=4 Then ( 26 ) End If End Function

9.下面程序的功能是:首先生成一个由小到大已排好序的整数数组,再输入一个数据,单击“插入”按钮会自动把这个数据插人到原数组适当的位置,并保持数组的有序性。 Option Explicit Dim a( )As Integer

Private Sub Form_Activate() Dim i As Integer ReDim a(10) For i=1 To 10 a(i)=(i-1)*10+1

Textl=Textl & Str(a(i)) Next i

Text2.SetFocus End Sub

Private Sub Commandl_Click() Dim n As Integer,i As Integer n=Text2