江苏省高校计算机等级考试命题研究院 江苏省高校计算机等级考试辅导
2005秋江苏省等级考试笔试卷(2)

第二部分 VB程序设计

一、 选择题

21.以下所列的8个控件中,具有Caption属性的有         个。

CheckBox(复选框)、ComboBox(组合框)、HscrollBar(水平滚动条)、DirListBox(文件夹列表框)、Image(图像框)、Frame(框架)、Label(标签)、Line(线条)

A5              B4               C3             D2

22.执行下面语句后,Len函数值最大的是         

Dim IA As Integer, B As Single, S As String *5, Ch As String

IA=32767  : B=23.5  : S=”A”  :Ch=”abcd”

ALen(IA)        BLen(B)           CLen(S)        DLen(Ch)

23.假设变量Lng为长整形变量,下面不能正常执行的语句是

ALng=16384*2                      BLng=4*0.5*16384

CLng=190^2                        D32768*2

24.数学表达式 对应的正确Visual Basic表达式为

A-b+Sqr(b*b-4*a*c)/2*a

B-b+Sqr(b*b-4*a*c)/(2*a)

C(-b+Sqr(b*b-4*a*c))/(2*a)

D(-b+Sqr(b*b-4*a*c))/ 2*a

25.设Mys1,Mys2均为字符串型变量,Mys1=”Visual Basic”,Mys2=”b”,则下面关系表达式中结果为的是

ALen(Mys1)<>2*InStr(Mys1,”1”)

BMod(Mys1,8,1)>Mys2

CChr(98)&Right(Mys1,4)=”Basic”

DInStr(Left(Mys1,6),”a”)+60

26.在窗体模块代码窗口的通用声明处,可以使用语句说明数组

Public A(10) As Integer     ② Dim A(10) As Integer

Private A(10)As Integer     ④ Static A(10) As Integer

A①②    B②③    C③④    D①④

27.设A=7,B=4,C=6,,则表达式A Mod3+B^3/C\5的值为

A1       B2       C3       D.出错

28.下列说法中,错误的是

A. 当程序正常结束时,所有没用Close语句关闭的文件都会自动关闭

B. 在关闭文件或程序结束之前,可以不用Unlock语句对已锁定的记录解锁

C. 可以用不同的文件号同时打开一个随机文件

D. Output模式打开一个顺序文件,即使不对它进行写操作,原来内容也被清除

29.程序中有两个过程Private Sub Fun1(S As String)Private Sub Fun2(a() As String 6),在调用过程中用Dim  St(6)  As  String6定义了一个字符串数组。下面调用语句中正确的是。

Call Fun1(St(3)) Call Fun2(St) Call Fun1(St) Call Fun2(St(6) )

A.①②   B.①③   C.②③   D.②④

30DrawStyle属性用于设置图形方法输出的线型,它受属性的限制

AFillStyle    BFillColor   CBorderStyle    DDrawWidth

二、

填空题

1.若窗体有列表框,则List1.List(List1.ListIndex)的值等于List1__Text___属性值。

2.执行下面的程序,当单击Command1时,列表框List1的第2列表项内容是 3 ,第4列表项内容是_15_,第5列表项内容是  28    

  Private Sub Command1_Click()

     Dim I As Integerj As Integer

     For I =1 To 10

        j=I+j

        List1.AddItem j

     Next I

     For I =1 To 4

        List1.RemoveItem List1.ListCount - I

     Next I

  End Sub

3.运行下面的程序,当单击Command1时,窗体上显示的第一行内容是DCB,第三行内容是 D,第四行内容是3

  Private Sub Command1_Click()

    Print Text3

  End Sub

  Private Function Textt As IntegerAs Integer

    Dim i As Integer

    If t=1 Then

       Call Testt-1

       For i = 3 To t Step - 1

           Print ChrAsc(“A”)+ i);

       Next i

Print

     End if

     Test = t

  End Function

4.运行下面的程序,当单击窗体时,窗体上显示的第一行内容是10 8,第三行内容是5 2,第四行内容是12  -10

  Dim x As Integery As Integer

  Private Sub Form_Click()

    Dim a As Integerb As Integer

    A=5b=3

    Call sub1ab

    Print ab

    Print xy

  End sub

  Private Sub sub1ByVal m As Integern As Integer

    Dim y As integer

    X=m+ny=m-n

    M=fun1xy

    N=fun1yx

  End sub

  Private Function fun1a As Integerb As IntegerAs Integer

    X=a+by=a-b

    Print xy

    Fun1=x+y

  End function

5.执行下面的程序,当单击COMMAND1时,picute1中显示内容的第二行与第四行分别是5 6 7 813 14 15 16picture2中显示内容的第一行和第三行分别是4 8 12 162 6 10 14

  Private Sub Command1_Click()

     Dim a44As IntegerI As Integerj As Integer

     Dim b44As Integer

     For I=1 To 4

        S=“”

        For j =1to 4

           AIj=((I-1*4+j

           S=s&Right(“ & StraIj)),3

        Next j

        Picture1.Print s

      Next i

      For I=1 To 4

         For j=1 To 4

            B5-jI=aIj

         Next j

      Next i

      For I=1 to 4

         S=“”

         For j = 1 To 4

            If  Len((CStrbIj)))<2 Then

               S=s&“” & CStrbIj))&

            Else

               S=s& CStrbIj))&

            End if

         Next j

         Picture2.Print s

      Next i

  End Sub

6.下面程序的功能时,输入x的值,利用递推法分别求出级数前n项(n=0123…)之和。

S=a0+a1++an+

其中,

 a 0=1   a n=a n-1 *    n=1,2,3……

计算积数,直到第n项的绝对值小于等于0.001时停止,完善程序,实现以上功能。

  Option Explicit

  Private Sub Command1_Click()

     Dim x As Single I As Integer s As Single

     Dim a As Single a1 As Single

     X = Text1

     A=1s = a

     List1.AddItems(“&0= & Strs

     Do

        I=I+1

       ____a1=a*x*(3-2*i)/(2*i)______

        S=s+a1

        List1.AddItems(” &CStrI&“)= & Strs

        If  Absa1)〈=0.001 Then

             Text2=i

                Exit do   

        Else

A=a1

        End if

Loop

  End Sub

7.下面程序的功能时,验证任意一个大于5的奇数可表示为3个素数之和。完善程序,实现以上功能。

  Option Base 1

  Private Sub Command1_Click()

Dim P()As IntegerN As IntegerL As Integer

Dim I As IntegerJ As Integerk As Integer

Dim ch As String

N=InputBox(“输入一个大于5的奇数!”)

Label1.Caption=   str(n) & “=”

Call PrimePN

L=UboundP

For I=1 to L

   For J=1 to L

      For k =1 to L

         If p(i)+p(j)+p(k)=n  then

            Ch=CStrPI&+ &CStrPJ))&+ & CStrPk))

            Text1.text = ch

             Exit sub

         End if

      Next k

   Next J

Next I

  End sub

  Private Sub PrimeA()As IntegerN As Integer

Dim I As IntegerIdx As Integer

Dim J As Integer

For I=2 to N

   For J = 2 To SqrI

       If I Mod J =0 Then Exit For

   Next  J

If J>Sqi(I) then

     ___idx=idx+1______

redim preserve A(idx)

a(idx)=I

     end if

8.将20个棋子围成一圈,按顺时针方向从1-20给棋子编号,从中取出棋子的规则是:从某编号棋子开始取出第1个棋子,然后按顺时针方向围绕周数棋子,从1数到2取第2个,再从1数到3取第3个,再从1数到4取第4……直到取完。本程序的功能就是找出依照上述规则取棋子的编号序列,使得最后一个被取棋子的编号为指定的编号。例如:若指定最后取棋子的编号为9,则必须从编号为17的棋子开始取第一个棋子,取棋子的顺序是:1719261118……。完善程序,实现以上功能。

Option base 1

Private sub command1_click()

   Dim a(20) as integer,I as integer,k as integer

   Dim n as integer,number as integer,s as string

   Number=val(text2)

   For k=1 to 20

      For I=1 to20    

          A(i)=1

      Next I

  S=_left(cstr(k) & “--”,3)

  Call sub1(a,k,n,s)

  If n=number then

     Text1=s

     Exit for

  End if

Next k

End sub

Private sub sub1(a() as integer,byval idx as integer,n as integer,s as string)

   Dim I as integer,js as integer,sum as integer

   Dim ub as integer,step as integer

   _____ub=ubound(A)__________

   js=1:stemp=1

  a(idx)=0

  do while js<20

       step=step+1

       ____sum=0_______

       do while sum

                idx=idx+1

               if idx>ub then ____idx =idx mod ub___

               sum=sum+a(idx)

        loop

    a(idx)=0

     s=s & left(cstr(idx) & “ ”,3)

    ____js=js+1______

if js mod 10=0 then s=s & vbcrlf

loop

n=idx

end sub

9C盘根目录下的数据文件data.txt中有两组数据,第一组数据未排序,并以-1表示该组数据结束;第二组数据按从小到大顺序排列。下面程序的功能是,单击“读入数据”按钮,将文件中的两组数据,分别读入到AB数组中,单击“插入排序”按钮,则把A数组的元素按其大小依次插入到B数组的适当位置,使得B数组中元素仍为从小到大排列。完善程序,实现以上功能。

Dim a() as integer, b() as integer

Private sub command1_click()

  Dim I as integer,j as integer,n as integer, s as string

     __ open “c:\data.txt” for input as #11__

  do

          input #11,n

          if n=-1 then exit do

          I=I+1

          Redim preserve a(i)

          A(i)=n

          S=s & str(a(i))

  Loop

  Text1=s

   S=””

  ___Do while not eof(1)__

         j=j+1

         redim preserve b(j)

         input #11,b(j)

         s=s & str(b(j))

 loop

 text2=s

close 11

end sub

private sub command2_click()

dim I as integer, j as integer, s as string

for I=1 to ubound(a)

    if a(i)  then

         call change(a(i),1)

    elseif a(i)>b(ubound(b))  then

       ___redim preserve b(ubound(b)+1)___

    b(ubound(b))=a(i)

else

  for j=2 to bound(b)

     if(a(i)>b(j-1))  and a(i)<=b(j)  then call change(a(i),j)

  next j

end if

next I

for I=1 to ubound(b)

     s=s & str(b(i))

next I

text3=s

end sub

private sub change( n as integer,k as integer)

dim I as integer

redim preserve b(ubound(b)+1)

for I=ubound(b)  to k+1 step –1

   _____b(I)=b(I-1)_

next I

____b(k)=n__

end sub