posts - 70,comments - 80,trackbacks - 0

第二部分 Visual Basic 程序设计
     

一、选择题(用答题卡答题,答案依次填在21-30答题号内)

21 .无法响应Click事件的控件是_(21)_.
A.Label     
B.Timer   C.TextBox    D.DriveListBox

22 .在窗体上放置了DrivelistBox、 DirListBox和 FileListBox等三个控件,下面_(22)_语句一定不会改变相应控件的Path或Drive属性。
A.Drivel.ListIndex=2         
B.Dir1ListIndex=-2

C.File1.FileName="a:\*.*"       D.File1.Path=Drive1.Drive

23 .对于某对象的SetFocus和GotFocus描述正确的是_(23)_。
A.SetFocus是方法,GotFocus事件    B.
SetFocus是事件,GotFocus是事件
C.SetFocus是方法,GotFocus是方法   D.SetFocus是事件,GotFocus是方法

24.设a为Integer型变量,s为Single变量,把3.75赋值给s后,再执行下列某一语句,则在文本框中显示的结果与执行语句a=s:Text1=a的结果相同的有_(24)_。

(1) a=Int(s):Text1=a              (2) a=Fix(s):Text1=a
(3)a=CInt(s):Text1=a               (4) a=Format(s,“#####”):Text1=a
  A.1         
B.2       C.3      D.4

25 .下列语句运行时系统给出错误提示的是_(25)_。
A.Print-32000-769          
B.Print"IE2"+8

C.Print"AB"&128           D.Print3=2=4

26 .描述X、Y中只有一个小于Z的逻辑表达式是_(26)_。
A.X<Z And Y<Z             B.X<Z Or Y<Z
C.X<Z Xor Y<Z              D. X<Y<Z

27 .以下有关控件数组的说法中错误的是_(27)_。
A.控件数组由一组具有共同名称和相同类型的控件组成
B.控件数组中的每一个控件共享同样的事件过程
C.控件数组中的每个元素的下标由控件的Index属性指定
D.同一控件数组中的元素只能有相同的属性设置值

28 .下列说法_(28)_是不正确的。
A.当程序正常结束时,所有没用Close语句关闭的文件都会自动关闭
B.在关闭文件或程序结束之前,可以不用Unlock语句对已琐定的记录解琐
C.可以用不同的文件打开同一个随机文件

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

29 .VB的数据控件(Data)不能通过Connect属性对数据库_(29)_直接访问。
A.Microsoft Access           B.FoxPro
C.dBASE                 
D.Microsoft SQL Server   

30 .以下有关过程的说法中错误的是_(30)_。
A.在Sub或Function过程中不能再定义其他Sub或Function过程
.在调用过程时,与使用ByRef说明的形参对应的实参只能按地址传递方式结合

C.递归过程既可以是递归Function过程,也可以是递归Sub过程
D.在调用过程时,形参为数组的参数对应的实参只能是数组


填空题(请将答案填写在答题纸的相应答题号内,每个答案只占一行)

.在程序运行时,将保存在C盘Pic文件夹中的名为Fishing.bmp的图片加载到图片框Picture1中的语句为 picture1.picture = load picture("c:\pic\Fishing.bmp")。
2.执行下面的Command1_Click事件过程后,Text1中显示的内容是
VISUAL Text2中显示的内容是 2003.10.11
Private Sub Command1_Click()
Dim S As String,I As Integer
Const Ch As String="0123456789."
S="2L0A03U.1SI0V.1I"
For I=1 To Len(S)
  If InStr(Ch,Mid(S,I,1))=0 Then
    Text1=Mid(S,I,1)&Text1
  Else
    Text2=Text2 & Mid(S,I,1)
  End If
Next I
End Sub

.执行下面程序,单击Command1按钮后,窗体上的第一行内容是 27 3 ,第二行内容是 18 0 ,最后一行内容是 Lcm = 27
Private Sub Command1_Click()
Dim N As Integer,M As Integer,Lcm As Integer
N = 9
M = 27
Lcm=Recursion(N,M)
Print "Lcm=";Lcm
End Sub
Private Function Recursion(A As Integer,B As Integer)As Integer
Static k As Integer
k=k+1
If A Mod B = 0 Then
 Recursion = A

Else
 Recursion = Recursion(A+A/k,B)
End If
 Print A,k
 k=0
End Function

.执行下面程序,当单击Command1后,列表框中显示的第一行是 3 ,第二行是 7 ,第三行是 23
Private Sub Command1_Click()
  Dim x As Integer,k As Integer
  x = 483
  k = 2
  Do Until x<=1
    If x Mod k = 0 Then
      x = x\k
      List1.AddItem Str(k)
    Else
      k=k+1
    End If
  Loop
End Sub

.执行下面程序,单击命令按钮Command1后,窗体上显示的第一行内容是 10 4 6 ,第二行内容是 56 28 28 ,最后一行内容是 k=66
Private Sub Command1_Click()
Dim A As Integer,K As Integer
A = 2
K=Fun((A),A)+ Fun(A,A)
Print"K=";K
End Sub
Private Function Fun(X As Integer,Y As Integer)As Integer
Static K As Integer
K = K+X+y
X = X+Y
Y=Y+K
Fun = X+Y
Print Fun;X;Y
End Function

6.执行下面程序,窗体上显示的第二行是 4 5 6 ,单击命令按钮Cmd1,则窗体上显示的第四行是 1 6 7 ,第五行是 8 5 2 ,第六行是 3 4 9
Option Explicit
Opton Base 1
Private a(3,3)As Integer
Private Sub Form_Activate()
Dim i As Integer,j As Integer,k As Integer
k = 1
For j=1 To 3
  For i=1 To 3
   a(i,j)=k
   k=k+1
   Print a(i,j);

Next i

Print
Next j
End Sub
Private Sub Cmd1_Click()
Dim b(4) As Integer,i As Integer,k As Integer,t As Integer
For i=2 To 4
  b(i)=i-1
Next i
b(1)=2
For i=1 To 2
  t=a(b(1),b(4))
  a(b(1),b(4))=a(b(2),b(1))
  a(b(2),b(1))=a(b(3),b(2))
  a(b(3),b(2))=a(b(4),b(3))
  a(b(4),b(3))=t
Next i
For i=1 To 3
 For k =1 To 3
   Print a(i,k);
 Next k
 Print
Next i
End Sub

7.本程序的功能是求下面数列前n项之和:

S(x,n)=x/2+2!*x^3/2*4+3!*x^5/2*4*6+.....+n!*x^2n-1/2*4*6...2n
Option Explicit
Private Sub Command1_Click()
Dim x As Single,s As Single
Dim n As Integer,i As Integer
x=InputBox("输入X:","求数列和",1)
n=InputBox("输入N:","求数列和",1)
For i=1 To n
 s=s+fun(x,i)
Next i
Label1.Caption=
"s("& x &","& n &")="

Text1=s
End Sub
Private Function fun(x As Single,n As Integer)As Single
 Dim p As Single;i As Integer
p=1
For i=1 To n
  
p=p*n/(2*n)
  fun=x^(2*n-1)*p
End Function

8.下面程序的功能是统计文件中英文字母(不区分大小写)出现的个数。
Option Base 1
Private Sub Command1_Click()
Dim alpha(26) As Integer,n As Integer
Dim i As Integer,s As String
Open "c:\kav2003\readme.txt" For Input As #11
Do While Not EOF(11)
  s=
Input(1,11)

   s=UCase(s)
   If s>="A" And s<="Z" Then
    n=
Asc(s)-64
    alpha(n)=alpha(n)+1
   End If
Loop
For i=1 To 26
  If alpha(i)<>0 Then
   List1.AddItem Chr(i+64)&":"&CStr(alpha(i))
  End If
Next i
Close
End Sub

9.下面程序的功能是依次将给定字符串A中的字符逐个插入到字符串B中,插入的位置是字符串B中第一个与其相同的字符之后(不区分大小写),若B中无相同字符,则依次插入到B的末尾。

Private Sub Command1_Click()
Dim st1 As String,st2 As String
st1 = Text1.Text:st2 =Text2.Text
Call inst(st1,st2)
Text3 = st2
End Sub
Private Sub inst(s1 As String,s2 As String)
Dim i As Integer,p As String,n As Integer,n1 As Integer
For i = 1 To Len(s1)
  p = Mid(s1,i,1)
  If p>="A" And p<="Z" Then
     n = InStr(s2,p)
    n1=instr(s2,chr(Asc(p)+32))
    Call ins(s2,p,n,n1)
  ElseIf p>="a" And p<="z" Then
    n=instr(s2,chr(Asc(p)-32))
    n1 = InStr(s2,p)
    call ins(s2,p,n,n1)
  Else
    MsgBox"字符串A中含有非字母字符!",vbOKOnly,"合并字符串"
     Exit Sub
   End If
Next i
End Sub
Private Sub ins(s As String,p As String,n As Integer,k As Integer)
If n<>0 And k = 0 Or n<>0 And k<>0 And n>k Then
  s = Left(s,n)&p& Right(s,Len(s)-n)
ElseIfn=0 and k<>0 or n<>0 and k<>0 and n<kThen
  s = Left(s,k)&p& Right(s,Len(s)-k)
Else
  s = s&p
End If
End Sub

 

10.下面是一个采用拉锯式排序法对数组元素按升序进行排序的程序,所谓“拉锯式排序法”是这一遍把最小的元素从下到上送到最上的位置,下一遍则是从上到下把最大的元素送到最下的位置。

Option Base 1
Private Sub Command1_Click()
Dim a(10) As Integer,i As Integer
For i = 1 To 10
  a(i) = Int(Rnd * 10)+1
  Text1 = Text1 & Str(a(i))
Next i
Call shaker_sort(a)
For i = 1 To 10
  Text2 = Text2 & Str(a(i))
Next i
End Sub
Private Sub Shaker_sort(k() As Integer)
Dim i As Integer,c As Integer,d As Integer
Dim t As Integer
c = 1
d = 10
Do
 For i=d To c+1 Step-1
  If k(i=1)>k(i) Then
   t = k(i-1):k(i-1) = k(i):k(i) = t
   End If
  Next i
  c=c+1
  For i = c+1 To d
    If k(i-1)>k(i)Then
     t = k(i-1):k(i-1) = k(i):k(i) = t
    End If
  Next i
  d = d-1
Loop While d>c
End Sub

 

 

 

posted on 2006-10-15 10:59 木子李 阅读(526) 评论(0)  编辑 收藏 引用 网摘 所属分类: Visual Basic 课堂

只有注册用户登录后才能发表评论。