梦想的边缘

总有梦想,总在追寻,却总在梦想的边缘徘徊,直到有一天,明白了,原来自己的梦想就在这不停追寻之中......

导航

单元测试卷004(过程)

Posted on 2005-06-28 16:19  梦想的边缘  阅读(2181)  评论(4编辑  收藏  举报

第四份单元测试卷没有印刷,请大家参考下面电子稿吧。

 

1、下面的数组说明中,正确的是       

       A  Sub sl(a(),n)      B   Sub sl(a(),n)

          Dim a(n,n)           dim  preserve  a(2,2) 

       C  Sub sl(a(),n)     D  Sub sl(a(),n)

           redim  a(5)        dim a(5)

2、如果编写的过程要被多个窗体及其对象调用,应将这些过程放在哪一类模块中?         

        A  窗体模块             B 标准模块  C  工程        D  类模块

3VB中过程或函数中形参变量的类型声明为“Control” 或“Form”的对象的参数传递是  

   A  按值传递  B 按址传递  C  看前面有无”Byval”  D 看前面有无”Byref”

4Sub过程与Function 函数最根本的区别是        

A  前者可以使用Call或直接使用过程名调用,后者不可以

B  后者可以有参数,前者不可以

C  两重参数的传递方式不同

D  前者无返回值,但后者有

5VB应用程序中,在程序中流动的不是一般的数据而是        

  A 事件     B    属性      C    方法      D   对象

6、系统默认的参数传递方式是         传递。

A  按值    B   按地址     C   BYVAL     D  按实参

7、在调用SUB过程或FUNCTION过程时,采用         传送相应过程的变量名、数组名、常数或表达式。

A 形式参数     B   实际参数    C  对象参数     D  数组参数

8、下面对Function过程的描述正确的是         

A  Function过程可以嵌套定义   B  Function过程应有返回值

C  Function过程不可嵌套调用   D  Function过程不可以定义局部变量

9、设过程的调用方法中,下面哪个是不正确的?        

Private  Sub  Area(x As Single, y As Single, z As Single,s  As Single)

A  P=Area(a,b,c,s)           B  Call  Area(a,b,c,s)

C  Area  a,b,c,s             D  都不正确

10、下面 Function过程Private  Function  Exam(A  As  Integer) 调用方法中哪个是不正确。

A.Tcmp=Exam(x)    B.Call  Exam(x)   C. Exam  x    D.Exam(x)

11 、下面说法正确的是        

A  Sub过程不能嵌套定义          B  Function过程不能嵌套定义

    C  Sub过程可以嵌套Function过程  D  Function过程可以嵌套调用

12、关于参数传递,以下说法中错误的是__________

A 数组只能是地址传递    B 常数只能是值传递

B 变量只能是地址传递    C 表达式只能是值传递

13、下列叙述正确的是:___________

    A  标准模块中既可以有事件过程,也可以有通用过程。

    B  若声明一变量在工程中的所有过程都有效,必须在标准模块中说明。

    C  Private语句不能在过程内出现。

    D  静态变量可以在窗体/模块级声明。

14、下列说法正确的是:_______________

      A  全局变量必须在标准模块中用Public语句声明。

           B   过程级变量除可用Dim声明外,还可用Static声明,含义相同。

         C   标准模块中声明的变量一定是全局的。

         D   模块级变量可在窗体模块中用PrivateDim定义。

15、在过程中可用          语句定义变量。

A DimStatic  B DimPublic  C DimPrivate  D DimPublicStatic

16、在调用Sub过程或Function过程时,下列可以作为实参的有______

   A  常量    B 变量     C 表达式    D 以上都可以

17、在过程中定义的变量,如希望在调用该过程时,还能保存该变量以前的值,则应该使用_______关键字在过程中定义该变量。

   A  Dim         B  Public        C  Static       D  Private

18、标准模块的文件名的扩展名为_______

   A  .vbp             B  .frm       C  .bas   D  .ocx

19、在窗体模块的通用声明处用下列语句声明变量、数组,正确语句有       

   Public A(5) as integer   Public N as integer

   Public Const pi=3.14159  Private b() as integer

     A  2         B  3          C   4         D  1

20、如果在被调用过程中改变了形参值,而不会影响实参变量本身,这种参数传递方式称为       传递

     A 按值        B 按地址      C ByRef        D 按形参

21、下列说法不正确的是       

      A  VB允许将一个数字字符串赋值给一个数值星的变量

      B  VB允许使用未经说明的变量,其类型都是Variant类型

      C  Cls方法只清除运行时在窗体或图片框中显示的文本或图形

      D  事件过程既可建在窗体模块中,也可建在标准模块中

22、下列说法正确的是:_______________

A     全局变量必须在标准模块中用Public语句声明。

B     过程级变量除可用Dim声明外,还可用Static声明,含义相同。

C     标准模块中声明的变量一定是全局的。

D    模块级变量可在窗体模块中用PrivateDim定义。

 

二、阅读程序,回答问题。

1、当Sub过程中的Value形参表中存在ByVal关键字时,运行下面的程序,单击后在窗体上显示的第一行结果是___________;第二行结果是___________;若将形参表中ByVal关键字删除后,再运行下面的程序,单击后在窗体上显示的第一行结果是___________;第二行结果是___________

  Private Sub Form_Click()

Dim x As Integer, y As Integer

x = 10: y = 20

Call value(x, y)

Print "x="; x, "y="; y

  End Sub

 

  Private Sub value(ByVal m As Integer, ByVal n As Integer)

m = m * 2

n = n - 5

Print "m="; m, "n="; n

  End Sub

2、执行下列程序后,当输入3,第一行是__________,第二行是__________

  Private  sub  command1_click()

        Dim n as integer ,f as long

        N=3

        Print fact(n)

        Print n;”!=”;f

    End sub

Private function fact(n as integer) as long

       If n=0 or n=1 then

          Fact =1

       Else

          Fact=n*fact(n-1)

       End if

       Print fact

End function

3、下面程序运行后先点command1再点command2的输出结果为:__________

   Dim a as integer, b as integer

   Private sub command1_click()

        A=6

        B=4

   End sub

   Private sub command2_click()

      Print a,b

   End sub

 

4、运行下面的程序,单击窗体后,从键盘上输入字符串“10,窗体上显示的输出结果为         

Private Sub Form_Click()

Dim n As Integer

Dim s1 As String

s1=InputBox输入一个字符串

n=vals1

Print Factn

End Sub

 

Private Function Fact(m As Integer) As Long

Dim s As Long

If m=1 Then

  s=1

Else

  S=Factm-1*m

End If

Fact=s

End Function

 

5、运行下面的程序,单击窗体后,从键盘上输入字符串“abcdef”,窗体上显示的第一行输出结果为         ,第二行输出结果为            

Private Sub Tryc As Stringd As String

Dim A As String

Static I As Integer

I=I+1

A=MidcI1

If MidcI1<>””  Then  Try cd

d=d & A

 End Sub

 Private Sub Form_Click()

Dim s1 As Strings2 As String

s1=InputBox输入一个字符串

try s1s2

Print s1

Print s2

End Sub

6、下面程序在窗体上显示的两行内容分别是______________________,如果在sub1过程的第二个形参y前加byval修饰,则在窗体上显示的内容是______________________

Private Sub Form_click()

  Dim x as integer,y as integer,z as integer

  X=1y=2z=3

  Call sub1(x,x,z)

  Call sub1(x,y,y)

End sub

Private sub sub1(x as integer,y as integer,z as integer)

  Dim I as integer

  X=3*z y=2*z  z=x+y

  Print x,y,z

End sub

 

三、阅读并完善下列程序:

1、利用递归求1-10的阶乘。程序代码如下,在划线处填上缺少的内容。单击后在窗体上显示的第三行结果是___________

                  Option Explicit

  Private Sub Form_Click()

_________   __ 

For n = 1 To 10

If k <> i Then

For p = 1 To___________

temp = b(i, p)

b(i, p) = b(k, p)

b(k, p) = temp

Next

End If

Next

  End Sub

 

3     已知Fibonacci数列为:112358……,该数列前两个数为1,从第三个数开始,每一个数均为它前面两个数的和,下面的程序用来计算该数列中指定一项的值,它的参数Number用来指明是第几项。

Private Sub Form_Click()

Dim number As Integer, ints As Integer

number = InputBox("输入数据")

___________

Print ints

End Sub

Private Function fib(number As Integer) As Integer

If number = 1 Or number = 2 Then

  ___________

Else

Dim int1 As Integer, int2 As Integer

  Dim intc As Integer, intresult As Integer

  int1 = 1: int2 = 1

  For intc = 3 To ___________

      intresult = int1 + int2

      int1 = int2

      int2 = ___________

   Next intc

   ___________= intresult

End If

End Function

 4、验证歌德巴赫猜想:任意一个大于2的偶数都可以分解成两个素数之和。从用户接收一个大于2的偶数,并在窗体上显示分解成的两个素数之和。

Dim even As Integer, i As Integer

Private Sub Form_Click( )

Do

even = InputBox("请输入一个大于2的偶数:")

Loop Until even > 2 And even Mod 2 = 0

If even = 4 Then

  Print "4=2+2"

Else

  i = 3

  Do

  If                     Then

     y = even - i

     Print even & "=" & Str(i) & "+" & Str(y)

                    

  Else

     i = i + 2

  End If

  Loop

End If

End Sub

 

Private Function judge(n As Integer)

    Dim i As Integer

judge = True

For i = 2 To                

        If (n Mod i = 0) Then

                            

            Exit Function

        End If

    Next i

End Function

5、在C盘根目录下有一数据文件(cj.dat)如下:

20017847

20029078

20036779

20049090

20057879

第一列数据表示学号,第二列数据表示数学成绩,第三列数据表示计算机成绩,要求根据学生学号计算总分,并按总分从高到底次序再写到该文件中。程序如下:

Option Base 1

Dim a(5, 4) As Integer

 

Private Sub Form_Click()

Dim i As Integer, j As Integer

Open "c:\cj.dat" For Input As #1

For i = 1 To 5

  For j = 1 To 3

                     

  Next j

              = a(i, 2) + a(i, 3)

Next i

Close #1

sort

                

For i = 1 To 5

  For j = 1 To 4

                  

  Print a(i, j);

Next j

  Print

  Write #1,

Next i

End Sub

 

Private Sub sort()

Dim i As Integer, j As Integer, k As Integer, temp As Integer

For i = 1 To 4

  For j = 1 To 5 - i

     If                    Then

        For k = 1 To 4

           temp = a(j, k)

           a(j, k) = a(j + 1, k)

           a(j + 1, k) = temp

        Next k

     End If

  Next j

Next i

End Sub

6  若在数组AB中存放十个两位随机整数,要求把这十个数用筛选法升序重新排列。赵文

Private sub form _ click()

Dim ab(10) as integer

Dim I as integer

Print “排序前:”

For I=1 to 10

Ab(i)=_______ ________

Print ab(i);

Next I

Print

Print “排序后:”

___________________

For I= 1 to 10

Print ab(i);

Next I

Print

End sub

Private sub sort(a() as integer)

Dim I as integer , j as integer

 Dim temp as integer

For I=1 to ubound(a)-1

For  _________________

If  _________  then

Temp=a(i)

A(i)=a(j)

 a(j) = temp           

______________

Next j

  ___________________  

End sub

 

7  下是按钮cmd1click事件过程,求2100之间的所有素数,素数的个数显示在窗体上,素数从小到大写入顺序文件c:\dataout.txt中,在划线处填上缺少的内容

   Private  Sub cmd1_click()

  Dim intnum as integer,int1 as integer,int2 as integer

  Open (10)  for  ___________ as #1

  Intnum=0

  For int1=___________ 

For int2=2 to int1\2

   If int1 mod int2 =0  then

      Exit for

   End if

Next int2

If  ___________ then

   Intnum=intnum+1

   Write ___________

End if

  Next int1

  Print intnum

  Close #1

End sub

8  本程序的功能是利用随机函数生成n个三位的各不相同的正整数送给一个数组,将其按从小到大的顺序排列,并在屏幕上显示出来,每行显示5个元素。N的值由用户从键盘输入 

Option  explicit

Option base 1

Private Sub Form_click()

Dim I as integer,n as integer,a( ) as integer

N=inputbox(“输入数组元素的个数:)

___________

  For I=1  to  n

     Do

       A(I)=   ___________ 

     Loop until compare(a,I)

  Next I

  Call sort(a,n)   Print “排序后的结果为:”

  For I=1 to n

   Print a(I),

   If  ___________

  Next I

End sub

 Private function compare(b( ) as integer,m as integer ) as boolean

     Dim I as integer

     ___________ 

     If m=1 then  exit function

     For I=1 to  ___________

        If  b(I)=b(m)  then

           Compare=false

          ___________ 

       Endif

Next I

  End function

 Private sub sort(b( ) as integer,n as integer)

   Dim I as integer, j as integer,temp as integer

   For I=1 to n-1

   For j=  ___________ to n

If  ___________ then

      Temp=b(I)

      b(I)=b(j)

      b(j)=temp

    End if

   Next j

  Next I

End sub

9、下面程序计算f(x)=1/1x-1/2x+1/3x-1/4x+……+ 1/nxx的值由用户通过键盘输入,要求精确到10-7  

Private Sub  form_Click()

  Dim x As Integer, y As Single

  Dim t As Single, n As Integer, flag As Integer

  n = 1

  x = InputBox("请输入x的值")

  y = 1

   ___________

Do

 n = n + 1

 t = 1 / power(n, x)

 y =  ___________

 flag = -flag

Loop  ___________

Print y

End Sub

Private Function power(___________ , x As Integer) As Long

   If x = 0 Then

      power = 1

   Else

      power = n *power(  ___________ )

   End If

End Function

四、编程题:

1  编写一个摄氏温度与华氏温度转换的通用程序。摄氏(C)与华氏(F)温度转换的公式为:F=C×9÷5+32 

要求:在一个文本框中输入摄氏温度,在另一个文本框中显示对应的华氏温度。

2  编写一个验证一个数是否是素数的通用过程。用InputBox函数输入一个正整数,调用该过程判断其是否是素数,在文本框中显示判断结果。例如,输入“11则显示“11是素数”。

3  利用随机函数Rnd()生成20个在1~100之间的各不相同的正整数,并在窗体上显示出来。

4  将第3题生成的20个数首尾相连,找出每相邻四个数之和最大的四个数,并按下面的格式打印出来:n1+n2+n3+n4=sum,其中n1n2n3n4是所求的四个数,sum是这四个数的和

5  利用随机函数生成25个正整数,分别赋给一个5×5数组的每一元素,然后找出最大元素的位置,并按“An1,n2=M”形式打印出来。