当前位置:首页 > VB控件 - 数组 - 过程复习题 - 参考答案2
a = 10 : b = 20 Call ff(a,b) Print a,b End Sub
Private Sub ff(x As Integer, y As Integer) x = x + y y = x + y End Sub
程序运行时,单击窗体后,在窗体上输出的结果是_______D__。 A.10 20 B.20 20 C.30 30 D.30 50 7.下列程序 Dim b
Private Sub Command1_Click() a=1:b=1
Print \Call mult(a)
Print\End Sub
Private Sub mult(x) x=2*x b=3*b End Sub
运行后的输出结果为____B_____。
A.A=1 B=1 B.A=1 B=1 C.A=1 B=1 D.A=1 B=l
A=1 B=1 A=2 B=3 A=1 B=3 A=2 B=l 8.下列定义的函数过程正确的是____C_____。 A.Private Function F1(x,y)
Dim z As Single z=x+y F1=z
End Function End Sub B.Private Function F1(x,y) As Single
Dim x As Single,y As Single F1=x+y
End Function
C.Function F1(x As Single, y As Single)
F1=x+y
End Function
D.Function F1(x,y )As Single
Dim z As Single z=x+y *缺 :F1=z End Function
9.以下关于过程的叙述中,错误的是_____B____。 A.事件过程是由某个事件触发而执行的过程 B.函数过程可以有多个返回值
C.可以在事件过程中调用通用过程 D.不能在事件过程中定义函数过程 10.已知一窗体中有如下函数过程和一命令按钮Command1,且Command1的Click事件中只有一行命令:Print Max(1,2,3),则单击Command1时,输出结果为______C___。 Private Function Max( a,b,c) m=a
if b>m then m=b if c>m then m=c Max=m
End Function
A. 1 B. 2 C. 3 D. 6 11.已知一窗体中有如下函数过程和一命令按钮Command1,且Command1的Click事件中只有一行命令:Print Sum(1,2,3),则单击Command1时,输出结果为_____D____。 Private Function Sum( a,b,c) Sum=a+b+c End Function
A. 1 B. 2 C. 3 D. 6
12.已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为____B_____。 Private Function Sum( a,b,c) a=a+1:b=b+1:c=c+1 Sum=a+b+c End Function
Private Sub Command1_Click( ) a=1:b=2:c=3 y=Sum(a,b,c) Print a;b;c
End Sub
A. 1 2 3 B. 2 3 4 C. 3 4 5 D. 4 5 6
13.已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为_______A__。 Private Function Sum( ByVal a, ByVal b,ByVal c) a=a+1:b=b+1:c=c+1 Sum=a+b+c End Function
Private Sub Command1_Click( ) a=1:b=2:c=3 y=Sum(a,b,c) Print a;b;c End Sub
A. 1 2 3 B. 2 3 4 C. 1 3 4 D. 1 2 4*A
14.已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为______A___。 Public Function even(x) If x Mod 2 = 0 Then
even = 1 else
even = 0 End If
End Function
Private Sub Command1_Click() n = 20
If even(n) = 1 Then
Print n; \ Else
Print n; \ End If End Sub
A. 20 is a even number. B. 20 is not a even number. C. n is a even number. D. n is not a even number.
15.已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为______A___。 Public Function Fn(n) If n = 0 Then
Fn = 1 Else
Fn = Fn(n - 1) * n End Function
Private Sub Command1_Click() Print Fn(1) End Sub
A. 1 B. 2 C. 4 D. 24
16.已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为_____C____。 Public Function Fn(n) If n = 0 Then
Fn = 1 Else
Fn = Fn(n - 1) * n End Function
Private Sub Command1_Click() Print Fn(6) End Sub
A. 0 B. 1 C. 720 D. 6
17.已知一窗体中有如下函数过程和一命令按钮Command1,则单击Command1时,输出结果为_____C____。 Public Function Fun(x, y) Fun = 1
For I = 1 To y Fun = Fun * x Next I
End Function
Private Sub Command1_Click() Print Fun(3, 4) End Sub
A. 3 B. 4 C. 81 D. 256
18.已知一窗体中有如下子过程和一命令按钮Command1,则单击Command1时,输出结果为____A_____。 Public Sub change(ByVal x, ByVal y) t = x: x = y: y = t End Sub
Private Sub Command1_Click() a = 12: b = 34: Call change(a, b) Print a; b
End Sub
A. 12 34 B. 34 12 C. 21 43 D. 43 21
19.已知一窗体中有如下子过程和一命令按钮Command1,则单击Command1时,输出结果为_____B____。 Public Sub change(x, y) x = y End Sub
Private Sub Command1_Click()
a = 12: b = 34: Call change(a, b) Print a; b End Sub
A. 12 34 B. 34 34 C. 34 12 D. 12 12
20.已知一窗体中有如下子过程和一命令按钮Command1,且Command1的Click事件中只有一行命令:Print_Number,则程序运行中第三次单击Command1时,输出结果为____B_____。 Private Sub Print_Number( ) Dim x
x = x + 10 Print x End Sub
A. 0 B. 10 C. 20 D. 30
21.已知一窗体中有如下子过程和一命令按钮Command1,且Command1的Click事件中只有一行命令:Print_Number,则程序运行中第三次单击Command1时,输出结果为_____D____。 Private Sub Print_number( ) Static x x = x + 10 Print x End Sub
A. 0 B. 10 C. 20 D. 30
22.以下定义的函数中____B_____不是按“传址”方式传递参数的。 A.Public Function Sum(x,y)
B.Public Function Sum(ByVal x, ByVal y)
C.Public Function Sum(x As Integer,y As Integer) D.Public Function Sum(x%, y%)
23.以下过程的定义中,____A_____是错误的。 A. Public Sub Sum(x ; y)
B. Public Sub Sum(ByVal x, ByVal y)
C. Public Sub Sum(x As Integer,y As Integer) D. Public Sub Sum(x%, y%)
24.函数过程是以_____A____保留字开始的。 A. Function B. Sub C. Property D. Event 25.子过程是以______B___保留字开始的。
A. Function B. Sub C. Property D. Event
26.在函数过程中的任意位置要退出当前函数过程,应用___C______命令。 A. End Function B. Exit C. Exit Function D. Exit Sub 27.在子过程中的任意位置要退出当前子过程,应用_____D____命令。 A. End Function B. Exit C. Exit Function D. Exit Sub 28.在以下事件过程中,Private表示____B_____。 Private Sub txtName_Change() …… End Sub
A. 此过程可以被任何其它过程调用 B. 此过程只可以被本窗体模块中的其它过程调用 C. 此过程不可以被任何其它过程调用 D. 此过程是一个不可用过程 29.在以下事件过程中,Public表示_____D____。 Public Sub txtName_Change() …… End Sub
A. 此过程不可以被本模块中的过程调用 B. 此过程只可以被本窗体模块中的其它过程调用 C. 此过程不可以被任何其它过程调用 D. 此过程可以被本工程中的所有模块调用 二:填空题
1.以下事件过程的功能是:从键盘输入一个实数,将其四舍五入后输出。请在空白行填写适当的语句。 Private Sub Command1_Click() x=InputBox(\请输入一个实数\y=_Fix(val(x)+0.5)________ Print y End Sub
2.以下事件过程的功能是:第1次单击命令按钮,输出**;第2次单击命令按钮,输出****;如此继续。即每单击一次命令按钮,比上一次多输出2个\。请在空白处填写适当的语句。 Dim str As String
Private Sub Command1_Click() _str=str+”**”________ Print Str; End Sub
3.需要对过程名进行赋值的过程是___函数______过程。
4.如下程序,运行的结果是____2_____,函数过程的功能是__求最大公约数__。 Public Function f(h As Integer,i As Integer) Do While h<>i Do While h>i
h=h-i Loop
Do While i>h i=i-h Loop Loop f=h
End Function
Private Sub Command1_Click() Print f(32,6) End Sub
5.通用过程与事件过程不同的是__通用过程=自定义Sub过程 事件过程=VB系统给予定义好框架的Sub过程_______。
6.Private Sub P(b()As Integer)
For i=1 To 4 b(i)=2*i Next i End Sub
Private Sub Form_Click() Dim a(1 To 4)As Integer a(1)=2 a(2)=3 a(3)=4 a(4)=5 Call P(a) For i=1 To 4 Print a(i); Next i End Sub
运行上面的程序,单击命令按钮,输出结果为__2 4 6 8_______。
7.要定义一个过程可以在程序的任何地方调用它,应使用__Public__关键字来定义该过程。 8.本程序的功能是计算输入数的阶乘,请在画线处填上适当的内容使程序完整。 Private Sub Form_Click()
n=Val(InputBox(\请输入一个大于0的整数: \Print Fact(n) End Sub
Private Function Fact(m) Fact= [1] 1
For i=2 To [2] m Fact= [3] Fact*i Next i
End Function
9.要确定虚实结合为“传值”方式,应在虚参表中使用__Byval__关键字。
10.本程序的功能是由输入的分数确定结论,分数是百分制,0~59分的结论是“不及格”,60~79分的结论是“及格”,80~89分的结论是“良好”,90~100分的结论是“优秀”,分数小于0或大于100是“数据错!”。请在画线处填上适当的内容使程序完整。
Option Explicit
Private Function jielun(ByVal score%)As String Select Case score
Case [1] 0 to 59 jielun=\不及格\
Case [2] 60 to 79 jielun=\及格\
Case [3] 80 to 89 jielun=\良好\
Case [4] 90 to 100 jielun=\优秀\
Case [5] else jielun=\数据错! \End Select End Function
Private Sub Form_Click() Dim s1 As Integer
s1=InputBox(\请输入成绩: \Print jielun(s1) End Sub
11.如下程序运行的结果是___2 5 3 4 0______。 Public Sub pr(x()As Integer) Static i As Inreger Do
x(i)=x(i)+x(i+i) i=i+1
Loop While i<2 End Sub
Private Sub Command1_Click() Dim i As Integer,x(10) As Integer For i=0 To 3:x(i)=i+1: Next i For i=0 To 2:Call pr(x): Next i For i=0 To 4:Print x(i); : Next i End Sub
12.用Static定义过程的作用是__使过程中的局部变量都是静态变量__。 13.程序填空:在程序的空白行写上适当的语句,使程序完成相应的计算。
程序的功能是:用随机函数给数组元素赋任意3位整数。然后计算一数组Am的元素之和。 Private Sub Form_Click()
Dim Arr1(10) As Integer, k As Integer, s As Integer For k=0 To 10
[1] Arr1(k)=int(rnd*900)+100 Next k
Call Sum(Arr1,s)
Print \数组元素之和是:\End Sub
[2] Sub Sum(Arr2() as integer,ss as integer) Dim j As Integer For j=0 To 10 ss = ss +Arr2(j) Next j End Sub
三、程序改错题
1. 程序功能:求10的阶乘,程序中有一行有错误。改正错误,使它能输出正确的结果。 Private Sub Command1_Click() Print fun(10) End Sub
Private Function fun(n As Integer) As Long
If n > 0 Then * If n=1 Then 因为f(n)=n*f(n-1),直到 f(1)=1为至 fun = 1
Else: fun = n * fun(n - 1) End If
End Function
2.程序功能:计算两个数的最小公倍数。程序中有错误,改正错误,使程序能输出正确结果。 Private Sub Command1_Click() Print fun(248, 848) End Sub
改后: Private Function fun(u, v)
t = u Private Function fun(u, v) Do While t Mod u <> 0 Or t Mod v <> 0 t = u t = t + u
Loop Do While t Mod u <> 0 Or t Mod v <> 0 fun =u *fun=t
t = t + u ?t为u的倍数,故t Mod u=0 End Function
3.程序功能: 建立一个过程来计算12的阶乘,程序中有错误,改正错误,使程序能输出正确的结果。 Loop Private Sub Command1_Click()
fun=t ?函数返回值是t Call n(12)
End Sub
End Function Public Sub n(a As Integer)
改后: Dim i As Integer
Dim f As integer Public Sub n(a As Integer) f = 0
Dim i As Integer For i = 1 To a
f = f * i Dim f As Long ?f代表结果,值比较大 Next i
f=1 ?f后面要做磊乘,初值应为1 Print f
End Sub For i = 1 To a f = f * i Next i Print f End Sub
共分享92篇相关文档