11.编写VB程序,生成并输出除主对角线元素为1外,其他元素均为0的五阶方阵。
Private Sub Form_DblClick() Dim a(5, 5) As Integer For i = 1 To 5 For j = 1 To 5
If i = j Or i + j = 6 Then a(i, j) = 1 End If Next j Next i
For i = 1 To 5 For j = 1 To 5
Print a(i, j) & \ Next j Print Next i End Sub
第10章 过程
补充作业题
1.在标准模块中用Public关键字声明的变量和常量有效范围是__B___。 A.整个标准模块 B.整个工程 C.所有窗体 D.所有标准模块
2.通用过程中,要定义某一虚拟参数和它对应的实际参数是值传送,在虚拟参数前要加的关键字是___B__。
A.Optonal B.Byval
C.Missing D.ParamArray 3.有如下程序: Dim b
Private Sub form_click() a = 1: b = 1
Print \ Call mult(a)
Print \End Sub
Private Sub mult(x) x = 2 * x b = 3 * b End Sub
第 11 页 共 15 页
运行后的输出结果是__C___。
A.A=1,B=1 B.A=1,B=1 A=1,B=1 A=2,B=3 C.A=1,B=1 D.A=1,B=1 A=1,B=3 A=2,B=1 4.有如下程序: Option Base 1
Private Sub swap(abc() As Integer) For i = 1 To 10 \\ 2 t = abc(i)
abc(i) = abc(10 - i + 1) abc(10 - i + 1) = t Next i End Sub
Private Sub form_click() Dim xyz(10) As Integer For i = 1 To 10 xyz(i) = i * 2 Next i
swap xyz()
For i = 1 To 10 Print xyz(i); Next i
End Sub运行程序后,输出结果为___C__。 A.1 2 3 4 5 6 7 8 9 10
B.2 4 6 8 10 12 14 16 18 20 C.20 18 16 14 12 10 8 6 4 2 D.显示出错信息 5.有如下程序 Option Base 1
Private Sub form_click() Dim a(3, 3) For j = 1 To 3 For k = 1 To 3
If j = k Then a(j, k) = 1 If j <> k Then a(j, k) = 3 Next k Next j
Call p1(a()) End Sub
Private Sub p1(a()) For j = 1 To 3 For k = 1 To 3
第 12 页 共 15 页
Print a(j, k); Next k Next j End Sub
行程序时,输出结果为___A__。 A.1 3 3 3 1 3 3 3 1 B.3 1 1 1 3 1 1 1 3 C.1 3 3 3 1 3 3 3 1
D.显示出错信息
6.下列程序的功能是计算由输入的分数确定结论,分数是百分制的,0到59分的结论是“不及格”,60到79分的结论是“及格”,80到89分的结论是“良好”,90到100分的结论是“优秀”,分数小于0或大于100是“数据错!”。请在画线处填上适当的内容使程序完整。 Option Explicit
Private Function jielum(ByVal score%) As String Select Case score
Case ___score<60________ jielum = \不及格\
Case _____score>59__and score<80____ jielum = \及格\
Case _____ score>79__and score<90________ jielum = \良好\
Case ____ score>89__and score<101_______ jielum = \优秀\ Case Else jielum = \数据错!\ End Select End Function
Private Sub form_click() Dim s1 As Integer
s1 = InputBox(\请输入成绩:\ Print jielum(s1) End Sub 7. 列程序的功能是计算输入数的阶乘,请在画线处填上适当的内容使程序完整。 Private Sub form_click()
N = Val(InputBox(\请输入一个大于0的整数:\ Print fact(N) End Sub
Private Function fact(M) fact=_ ____
For I=2 to___N________ fact=_ ____
第 13 页 共 15 页
Next I
End Function
8.列程序的功能是计算给定正整数序列中奇数之和Y与偶数之和X,最后输出X平方根与Y平方根的乘积。请在画线处真上适当的内容使程序完整。 Private Sub form_click()
a = Array(9, 16, 8, 25, 34, 13, 22, 43, 22, 35, 26) Y=________ Print Y End Sub
Private Function f1(B) x = 0 Y = 0
For k = 0 To 10
If _____ mod 2=0 then X=___________ Else
Y=___________ End If Next k
f1 = Sqr(x) * Sqr(Y) End Function
9.对窗体编写如下事件过程:
Private Sub form_mousedown(button As Integer, shift As Integer, x As Single, y As Single) If button = 2 Then Print \ End If End Sub
Private Sub form_mouseup(button As Integer, shift As Integer, x As Single, y As Single) Print \End Sub
程序运行后,如果单击鼠标右键,则输出结果为_____。
A.AAAAA B.BBBBB C.AAAAA D.BBBBB BBBBB AAAAA 10.对窗体编写如下代码: Option Base 1
Private Sub Form_KeyPress(KeyAscii As Integer) a = Array(237, 126, 87, 48, 498) m1 = a(1) m2 = 1
If KeyAscii = 13 Then For I = 2 To 5
If a(I) > m1 Then
第 14 页 共 15 页
m1 = a(I) m2 = I End If Next I End If Print m1 Print m2 End Sub
程序运行后,按回车键,输出结果为_____。
A.48 B.237 C.498 D.498
4 1 5 4
11.在窗体中添加三个命令按钮和一个文本框,并分别编写如下代码: Private Sub command1_click() Text1.Text = UCase(Text1.Text) End Sub
Private Sub command2_click() Text1.Text = LCase(Text1.Text) End Sub
Private Sub command3_click() Text1.Text = Text1.Tag End Sub
Private Sub text1_keyup(keycode As Integer, shift As Integer) Text1.Tag = Text1.Text End Sub
程序运行后,在文本框中输入“abc”,分别点击command1,command2,command3,文本框中显示_____。
A.ABC abc abc B.abc ABC ABC C.abc ABC ABC D.ABC ABC abc
12.编写VB程序,求S=A!+B!+C!,分别用Sub子过程和Function函数过程两种方法实现阶乘的计算。 13.分别用Sub子过程和Function函数过程两种方法编写VB程序,求四个整数的最大值,其中四个整数由键盘输入。
第 15 页 共 15 页