假设使用计算机进行售票其过程如下,2012年计算机二级VB过程练习题及答案

过 程

一、 单选题

1.在过程定义中用 ________表示形参的传值。

A) Var

B) ByRef

C) ByVal

D) ByValue

2.若已经编写一个Sort子过程,在该工程中有多个窗体,为了方便调用Sort子程序,应该将子过程放在 ________中。

A) 窗体模块

B) 类模块

C) 工程

D) 标准模块

3.下面的子过程语句说明合法的是________。

A) Sub f1(ByVal n%())

B) Sub f1(n%) As Integer

C) Function f1%(f1%)

D) Function f1(ByVal n%)

4.要想从子过程调用后返回两个结果,下面子过程语句说明合法的是________。

A) Sub f(ByVal n%, ByVal m%)

B) Sub f(n%, ByVal m%)

C) Sub f(ByVal n%, m%)

D) Sub f(n%, m%)

5.下面程序运行的结果是 ________。

Private Sub Command1_Click()

Dim x%, y%

x = 12 : y = 34

Call f(x,y)

Print x,y

End Sub

Public Sub f1(n%,ByVal m%)

n = n Mod 10

m = m \ 10

End Sub

A) 2 34

B) 12 34

C) 2 3

D) 12 3

6.在窗体上画一个名称为Command1的命令按钮,再画两个名称分别为Label1、Label2的标签,然后编写如下程序代码:

Private X As Integer

Private Sub Command1_Click()

X = 5 : Y=3

Call proc(X,Y)

Label1.Caption = X

Label2.Caption = Y

End Sub

Private Sub proc(ByVal a As Integer, ByVal b As Integer)

X = a * a

Y = b + b

End Sub

程序运行后,单击命令按钮,则两个标签中显示的内容分别是______。

A)5和3

B)25和3

C)25和6

D)5和6

7.下面程序运行的结果是 ________。

Dim a% , b% , c%

Public Sub p1(x%, y%)

Dim c%

x = 2 * x : y = y + 2 : c = x + y

End Sub

Public Sub p2(x%, ByVal y%)

Dim c%

x = 2 * x : y = y + 2 : c = x + y

End Sub

Private Sub Command1_Click()

a = 2 : b = 4 : c = 6

Call p1(a, B)

Print "a = ";a ;"b = ";b ; "c = ";c

Call p2(a, B)

Print "a = ";a ;"b = ";b ; "c = ";c

End sub

A) a = 2 b = 4 c = 6

a = 4 b = 6 c = 10

B) a = 4 b = 6 c = 10

a = 8 b = 8 c = 16

C) a = 4 b = 6 c = 6

a = 8 b = 6 c = 6

D) a = 4 b = 6 c = 14

a = 8 b = 8 c = 6

8.下面程序运行的结果是 ________。

Public Sub Proc(a%())

Static i%

Do

a(i) = a(i) + a(i+1)

i = i + 1

Loop While i < 2

End Sub

Private Command1_click()

Dim m% , i% , x%()

For i = 0 to 4 : x(i) = i + 1 : Next i

For i = 1 to 2 : Call Proc(x()) : Next i

For i = 0 to 4 : Print x(i) : Next i

End Sub

A) 3 4 7 5 6

B) 3 5 7 4 5

C) 2 3 4 4 5

D) 4 5 6 7 8

9.在窗体上画一个名称为Command1的命令按钮,然后编写如下程序:

Private Sub Command1_Click()

Static X As Integer

Static Y As Integer

Cls

Y=1

Y=Y+5

X=5+X

Print X,Y

End Sub

程序运行时,三次单击命令按钮Command1后,窗体上显示的结果为______。

A)15 16

B)15 6

C)15 15

D)5 6

10. 下列叙述中正确的是______。

A)在窗体的Form_Load事件过程中定义的变量是全局变量

B)局部变量的作用域可以超出所定义的过程

C)在某个Sub过程中定义的局部变量可以与其它事件过程中定义的局部变量同名,但其作用域只限于该过程

D)在调用过程时,所有局部变量被系统初始化为0或空字符串

来源:教育联展网-计算机二级考试

11 .以下关于变量作用域的叙述中,正确的是______。

A)窗体中凡被声明为Private的变量只能在某个指定的过程中使用

B)全局变量必须在标准模块中声明

C)模块级变量只能用Private关键字声明

D)Static类型变量的作用域是它所在的窗体或模块文件

12. 单击一次命令按钮之后,下列程序代码的执行结果为______。

Private Sub Command1_Click( )

S=P(1)+P(2)+P(3)+P(4)

Print S;

End Sub

Private Function P(N As Integer)

Static SUM

For I= 1 TO N

Sum=sum+1

Next I

P=SUM

End Function

A)135

B)115

C)35

D)20

13. 可以在窗体模块的通用声明段中声明______。

A)全局变量

B)全局常量

C)全局数组

D)全局用户自定义类型

14. 设有如下通用过程:

Public Function f(x As Integer)

Dim y As Integer

x=20

y=2

f=x*y

End Function

在窗体上画一个名称为Command1的命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Static x As Integer

x=10

y=5

y=f(x)

Print x;y

End Sub

程序运行后,如果单击命令按钮,则在窗体上显示的内容是______。

A)10 5

B)20 5

C)20 40

D)10 40

15. 单击命令按钮时,下列程序代码的执行结果为______。

Dim a As integer,b As Integer,c As Integer

Private Sub Command1_Click( )

a=5:b=8:c=9

Call Proc1(a,B)

Print"a=";a;"b=";b;"c=";c

Call Proc2(a,B)

Print"a=";a;"b=";b;"c=";c

End Sub

Public Sub Proc1(x As Integer,y As Integer)

Dim c As Integer

x=2*x:y=y+2:c=x+y

End Sub

Public sub proc2(x As Integer,Byval y as Integer)

Dim c As Integer

x=2*x:y=y+2:c=x+y

End sub

A)a=20 b=10 c=9

a=10 b=10 c=9

B)a=10 b=10 c=9

a=20 b=10 c=9

C)a=10 b=10 c=9

a=10 b=10 c=9

D)a=20 b=20 c=9

a=20 b=10 c=9

16. 单击命令按钮时,下列程序代码的执行结果为______。

Public Sub Procl(n As Integer,ByVal m As Integer)

n=n Mod 10

m=m\10

End Sub

Private Sub Command1_Click( )

Dim x As Integer,y As Integer

x=23:y=65

Call Procl(x,y)

Print x;y

End Sub

A)3 65

B)23 65

C)3 60

D)0 65

17. 在窗体上画一个名称为Command1命令按钮和三个名称分别为Label1、Label2、Label3的标签,然后编写如下代码:

Private x As Integer

Private Sub Command1_Click()

Static y As Integer

Dim z As Integer

n = 10

z = n + z

y = y + z

x = x + z

Label1.Caption = x

Label2.Caption = y

Label3.Caption = z

End Sub

运行程序,连续三次单击命令按钮后,则三个标签中显示的内容分别是______。

A)10 10 10

B)30 30 30

C)30 30 10

D)10 30 30

18. 以下关于函数过程的叙述中,正确的是______。

A)函数过程形参的类型与函数返回值的类型没有关系

B)在函数过程中,通过函数名可以返回多个值

C)当数组作为函数过程的参数时,既能以传值方式传递,也能以传址方式传递

D)如果不指明函数过程参数的类型,则该参数没有数据类型

19. 单击窗体时,下列程序代码的执行结果为______。

Private Sub Form_Click()

Test 2

End Sub

Private Sub Test(x As Integer)

x=x*2+1

If x<6 Then

Call Test(x)

End If

x=x*2+1

Print x;

End Sub

A)5 11

B)23 47

C)10 22

D)23 23

20. 假定已定义了一个过程Sub Add(a As Single,b As Single),则正确的调用语句是______。

A)Add 12,12

B)Call(2*x,Sin(1.57))

C)Call Add x,y

D)Call Add(12,12,x)

来源:教育联展网-计算机二级考试

21. 一个工程中包含两个名称分别为Form1、Form2的窗体,一个名称为Md1Func的标准模块。假定在Form1、Form2和Md1Func中分别建立了自定义过程,其定义格式为:

Form1中定义的过程:

Private Sub frmFunction1()

……

End Sub

Form2中定义的过程:

Private Sub frmFunction2()

……

End Sub

mdlFunc中定义的过程:

Public Sub md1Function()

……

End Sub

在调用上述过程的程序中,如果不指明窗体或模块的名称,则以下叙述中正确的是______。

A)上述三个过程都可以在工程中的任何窗体或模块中被调用

B)frmFunction2和mdlFunction过程能够在工程中各个窗体或模块中被调用

C)上述三个过程都只能在各自被定义的模块中调用

D)只有Md1Function过程能够被工程中各个窗体或模块调用

22. 在窗体上画一个命令按钮,名称为Command1,然后编写如下程序:

Function Func(ByVal x As Integer, y As Integer)

y = y * x

If y > 0 Then

Func = x

Else

Func = y

End If

End Function

Private Sub Command1_Click()

Dim a As Integer, b As Integer

a = 3

b = 4

c = Func(a, B)

Print a;b;c

End Sub

程序运行后,单击命令按钮,其输出结果为______。

A)3 4 12

B)3 4 3

C)3 12 3

D)3 12 12

23. 以下叙述中错误的是______。

A)一个工程中可以包含多个窗体文件

B)在一个窗体文件中用Public定义的通用过程不能被其他窗体调用

C)窗体和标准模块需要分别保存为不同类型的磁盘文件

D)用Dim定义的窗体层变量只能在该窗体中使用

24. 下面的过程定义语句中合法的是______。

A)Sub Procl(ByVal n())

B)Sub Procl(n) As Integer

C)Function Procl(Procl)

D)Function Procl(ByVal n)

25. 设有如下通用过程:

Public Function Fun(xStr As String) As String

Dim tStr As String, strL As Integer

tStr = ""

strL = Len(xStr)

i = 1

Do While i <= strL / 2

tStr = tStr & Mid(xStr, i, 1) & Mid(xStr, strL - i + 1, 1)

i = i + 1

Loop

Fun = tStr

End Function

在窗体上画一个名称为Text1的文本框和一个名称为Command1的命令按钮,然后编写如下的事件过程:

Private Sub Command1_Click()

Dim S1 As String

S1 = "abcdef"

Text1.Text = UCase(Fun(S1))

End Sub

程序运行后,单击命令按钮,则Text1中显示的是______。

A)ABCDEF

B)abcdef

C)AFBECD

D)DEFABC

26. 在窗体上画1个命令按钮,编写代码如下。程序运行后,单击命令按钮,输出结果为______。

Private Sub Command1_Click()

Dim a(10) As Integer

Dim x As Integer

For i=1 To 10

a(i)=8+i

Next

x=2

Print a(f(x)+x)

End Sub

Function f(x As Integer)

x=x+3

f=x

End Function

A)12

B)15

C)17

D)18

27. 在过程中定义的变量,若希望在离开该过程后,还能保存过程中局部变量的值,则使用______关键字在过程中定义局部变量。

A)Dim

B)Private

C)Public

D)Static

28. 以下正确的描述是:在Visual Basic应用程序中______。

A)过程的定义可以嵌套,但过程的调用不能嵌套。

B)过程的定义不可以嵌套,但过程的调用可以嵌套。

C)过程的定义和过程的调用均可以嵌套。

D)过程的定义和过程的调用均不能嵌套。

29. 有子过程语句说明:Sub fSum(sum%,ByVal m%,ByVal n%),

且在事件过程中有如下变量说明:Dim a%,b%,c!

则下列调用语句中正确的是______。

A)fsum a,a,b

B)fsum 2,3,4

C)fsum a+b,a,b

D)Call fsum (c,a,B)

30. 有如下程序,其运行的结果是______。

Public Function f(m%,n%)

Do While m<>n

Do while m>n : m=m-n : Loop

Do while m  Loop

F=m

End Function

Private Sub Command1_Click( )

Print f(24,18)

End Sub

A)0

B) 2

C)3

D)6

来源:教育联展网-计算机二级考试

31. 假定有如下的Sub过程:

Sub S(x As Single,y As Single)

t = x

x =t/y

y =t Mod y

End Sub

在窗体上画一个命令按钮,然后编写如下事件过程:

Private Sub Commandl_Click ( )

Dim a As Single

Dim b As Single

a =5

b =4

S a,b

Print a,b

End Sub

程序运行后,单击命令按钮,输出结果为______ 。

A) 5 4

B) 1 1

C) 1.25 4

D) 1.25 1

32. 假定有以下两个过程:

Sub S1(ByVal x As Integer,ByBal y As Integer)

Dim t As Integer

t=x : x=y : y=t

End Sub

Sub S2(x As Integer, y As Integer)

Dim t As Integer

t=x : x=y : y=t

End Sub

则以下说法中正确的是______。

A)用子过程S1可以实现交换两个变量的值的操作,S2不能实现

B)用子过程S2可以实现交换两个变量的值的操作,S1不能实现

C)用子过程S1和S2都可以实现交换两个变量的值的操作

D)用子过程S1和S2都不能实现交换两个变量的值的操作

33. 阅读程序:

Sub subP(b( ) As Integer)

For i =1 To 4

b(i)=2*i

Next i

End Sub

Private Sub Commandl_Click()

Dim a(1 To 4)As Integer

a (1)=5: a (2)=6: a (3)=7: a (4)=8

subP a ()

For i =1 To 4

Print a(i);

Next i

End Sub

运行上面的程序,单击命令按钮,输出结果为 ______。

A)2 4 6 8

B)5 6 7 8

C)10 12 14 16

D)出错

34. 在窗体上画一个名称为Command1 的命令按钮,然后编写如下事件过程;

Private Sub Command1_Click()

Static x As Integer

Cls

For i = 1 To 2

y = y + x

x = x + 2

Next

Print x, y

End Sub

程序运行后,连续三次单击Command1按钮后,窗体上显示的是______。

A)4 2

B)12 18

C)12 30

D)4 6

35. 阅读程序:

Function F(a As Integer)

b = 0

Static c

b = b+1

c = c+1

f = a+b+c

End Function

Private Sub Commandl_Click ()

Dim a As Integer

a =2

For i =1 To 3

Print F(A);

Next i

End Sub

运行上面的程序,单击命令按钮,输出结果为 ______。

A) 4 4 4

B) 4 5 6

C) 4 6 8

D) 4 7 9

36. 假定有下面的过程:

Function Func(a As Integer,b As Integer)As Integer

Static m As Integer,i As Integer

m=0

i=2

i=i+m+1

m=i+a+b

Func=m

End Function

在窗体上画一个命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Dim k As Integer,m As Integer

Dim p As Integer

k=4

m=1

p=Func(k,m)

Print p;

p=Func(k,m)

Print p

End Sub

程序运行后,单击命令按钮,输出结果为___________。

A)8 17

B)8 16

C)8 20

D)8 8

37. 在过程调用中,参数的传递可以分为______和按地址传递两种方式。

A)按值传递

B)按地址传递

C)按参数传递

D)按位置传递

38. 单击窗体时,下列程序代码的执行结果为______。

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

m = m - n: n = n + 3

Print m; n

End Sub

Private Sub Form_click()

Dim x As Integer, Y As Integer

x = 5: Y = 6

Call Value(x, Y)

Print x; Y

End Sub

A)-1 9

-1 9

B)5 6

5 6

C)-1 9

5 6

D)9 -1

5 6

39. 要想在过程调用后返回两个结果,下面的过程定义语句合法的是______。

A)Sub Procl(ByVal n,ByVal m)

B)Sub Procl(n,ByVal m)

C)Sub Procl(n,m)

D)Sub Procl(ByVal n,m)

40. 在窗体上画一个名称为Command1的命令按钮和一个名称为Text1的文本框,然后编写如下程序:

Private Sub Command1_Click()

Dim x,y,z As Integer

x = 5

y = 7

z = 0

Text1.Text = ""

Call P1(x,y,z)

Text1.Text = Str(z)

End Sub

Sub P1(ByVal a As Integer,ByVal b As Integer,c As Integer)

c = a + b

End Sub

程序运行后,如果单击命令按钮,则在文本框中显示的内容是______。

A)0

B)12

C)Str(z)

D)没有显示

来源:教育联展网-计算机二级考试

41. 在窗体上画一个名称为Comman1的命令按钮,并编写如下程序:

Private Sub Command1_Click()

Dim x As Integer

Static y As Integer

x = 10

y = 5

Call f1(x, y)

Print x, y

End Sub

Private Sub f1(x1 As Integer, y1 As Integer)

x1 = x1 + 2

y1 = y1 + 2

End Sub

程序运行后,单击命令按钮,在窗体上显示内容是______。

A)10 5

B)12 5

C)10 7

D)12 7

42. 函数过程F1 的功能是:如果参数b为奇数,则返回值为1,否则返回值为0 ,以下能正确实现上述功能的代码是______。

A)Function F1 (b As Integer)

If b Mod 2= 0 Then

Return 0

Else

Return 1

Endif

End Function

B)Function F1 (b As Integer)

If b Mod 2=0 Then

F1=0

Else

F1=1

Endif

End Function

C)Function F1 (b As Integer)

If b Mod 2 =0 Then

F1 =1

Else

F1= 0

End if

End Function

D)Function F1 (b As Iinteger)

If b Mod 2<>0 Then

Return 0

Else

Return 1

End if

End Function

43. 在窗体上画一个命令按钮,名称为Command1,然后编写如下程序:

Function Func(ByVal x As Integer, y As Integer)

y = y * x

If y > 0 Then

Func = x

Else

Func = y

End If

End Function

Private Sub Command1_Click()

Dim a As Integer, b As Integer

a = 3

b = 4

c = Func(a, B)

Print a;b;c

End Sub

程序运行后,单击命令按钮,其输出结果为______。

A)3 12 3

B)3 4 3

C)3 4 12

D)3 12 12

44. 假定有以下函数过程:

Function Fun(S As String)As String

Dim s1 As String

For i = 1 To Len(S)

s1 = UCase(Mid(S,i,1))+s1

Next i

Fun = s1

End Function

在窗体上画一个命令按钮,然后编写如下事件过程:

Private Sub Command1_Click()

Dim Str1 As String, Str2 As String

Str1 = InputBox("请输入一个字符串")

Str2 = Fun(Str1)

Print Str2

End Sub

程序运行后,单击命令按钮,如果在输入对话框中输入字符串"abcdefg",则单击“确定”按钮后在窗体上的输出结果为______。

A)abcdefg

B)ABCDEFG

C)gfedcba

D)GFEDCBA

45. 单击命令按钮时,下列程序代码的执行结果为______。

Private Function FirProc(x As Integer,y As Integer,z As Integer)

FirProc=2*x+y+3*z

End Function

Private Function SecProc(x As Integer,y As Integer,z As Integer)

SecProc=FirProc(z,x,y)+x

End Function

Private Sub Command1_Click()

Dim a As Integer,b As Integer,c As Integer

A=2:b=3:c=4

Print SecProc(c,b,A)

End Sub

A)21

B)19

C)17

D)34

来源:教育联展网-计算机二级考试

二、 填空题

1. 阅读下面程序,子过程Swap的功能是实现两个数的交换,请将程序填写完整。

Public Sub Swap(x As Integer, y As Integer)

Dim t As Integer

t = x : x = y : y = t

End Sub

Private Sub Command1_Click()

Dim a As Integer, b As Integer

a = 10 : b = 20

【1】

Print "a = "; a , "b ="; b

End Sub

2. 下列程序中,fac是求n!的递归函数,请将程序填写完整。

Public Function fac(n As Integer)

If n = 1 Then fac = 1

Else fac = 【2】

End If

End Sub

3.如下程序,运行的结果是 【3】 ,函数过程的功能是 【4】 。

Public Function f(ByVal n% , ByVal r%)

If n <> 0 Then

f = f(n\r,r)

Print n Mod r;

End If

End Function

Private Sub Command1_Click()

Print f(100,8)

End Sub

4.如下程序,运行的结果是 【5】 ,函数过程的功能是 【6】 。

Public Function f(m% , m%)

Do While m <> n

Do While m > n :m = m – n :Loop

Do While m < n :n = n – m :Loop

Loop

f = m

End Function

Private Sub Command1_Click()

Print f(24,18)

End Sub

5.两质数的差为2,称此对质数为质数对,下列程序,是找出100以内的质数对,并成对显示结果。其中IsP是判断m是否为质数的函数过程。

Public Function IsP(m%) As Boolean

Dim i%

【7】

For i = 2 to Int(Sqr(m))

If 【8】 Then IsP = False

Next i

End Function

Private Sub Command1_Click()

Dim i%

p1 = IsP(3)

For i = 5 to 100 step

p2 = IsP(i)

If 【9】 Then Print i-2;i

p1 【10】

Next i

End Sub

6.统计输入的文章中单词数,并将出现的定冠词The全部去除,同时统计删除定冠词的个数。假定单词以一个空格间隔。

Public Sub PWord(s% ,CountWord% ,CountThe%)

Dim len%,i%,st$

CountWord = 0 :CountThe = 0

st = Trim(s)

【11】

Do While i > 0

CountWord = CountWord + 1

st = 【12】

i = InStr(st," ")

Loop

CountWord = CountWord + 1

st = Trim(s)

【13】

Do While i > 0

CountThe = CountThe + 1

st = 【14】

i = InStr(st,"The")

Loop

【15】

End Sub

7.全局变量必须在__【16】__模块中定义,所用的语句为__【17】__。

8.设有以下函数过程:

Function Fun (m as Integer) As Integer

Dim k As Integer, Sum As Integer

Sum =0

For k = m To 1 Step -2

Sum =Sum +k

Next k

Fun =Sum

End Function

若在程序中用语句 s =fun(10)调用此函数,则s的值为 【18】 。

来源:教育联展网-计算机二级考试

参考答案

一、单选题

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

C

D

D

D

A

B

C

B

B

C

B

D

A

C

B

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

A

C

A

B

A

D

C

B

D

C

D

D

B

A

D

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

D

B

A

B

B

D

A

C

C

B

D

B

A

D

A

二、填空题

【1】

Swap a,b

【2】

n * fac(n-1)

【3】

1 4 4

【4】

用递归函数实现将十进制数以r进制显示

【5】

6

【6】

用碾转相减法求m、n的最大公约数

【7】

IsP = True

【8】

m Mod i = 0

【9】

p1 AND p2

【10】

= p2

【11】

i = InStr(st," ")

【12】

Mid(st,i+1)

【13】

i = InStr(st,"The")

【14】

Left(st,i-1)+ Mid(st,i+4)

【15】

s = st

【16】

标准

【17】

Public

【18】

30

来源:教育联展网-计算机二级考试

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值