Presentation is loading. Please wait.

Presentation is loading. Please wait.

第二章、第三章错题分析.

Similar presentations


Presentation on theme: "第二章、第三章错题分析."— Presentation transcript:

1 第二章、第三章错题分析

2 3.在VB中,若要在窗体中增加一个文本框,在控件工具箱中要选择的控件是
2.1 3.在VB中,若要在窗体中增加一个文本框,在控件工具箱中要选择的控件是 A. B. C. D. 3.1 2.在VB中,定义字符串常量a的正确语句是 Const a As Integer Const a=“hello” as String Dim a As String Const a=“hello” 常量:在程序执行过程中其值不变。 定义: Const x =10 Const x as integer =10

3 C.文本框Text1被激活后,用户在键盘上按下某一个键 D.文本框Text2被激活后,用户在键盘上按下某一个键
3.2 5.某VB程序如下: Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then Text2.Text = Text1.Text + Str(5) End If End Sub 程序运行时,能触发该事件过程的是 A.单击文本框Text1 B.单击文本框Text2 C.文本框Text1被激活后,用户在键盘上按下某一个键 D.文本框Text2被激活后,用户在键盘上按下某一个键 其它常用事件: Form_load():窗体加载 command1_Click():单击按钮 command1_DbClick():双击按钮 Timer1_Timer():时间到触发计时器

4 执行语句s=f(-0.4)后,逻辑型变量s的值是 A.0 B.1 C.True D.False
3.3 3.某VB自定义函数: Function f(i As Single) As Boolean If i <= 0 Then f = True Else f = False End Function 执行语句s=f(-0.4)后,逻辑型变量s的值是 A B C.True D.False

5 运行该程序,单击命令按钮Command1,文本框Text1中显示的是() A.-9 B.9 C.3 D.3.1
3.3 4.在VB中,有如下程序: Function f(x As Integer) As Integer f = Int(Abs(x) / 3) + 0.1 End Function Private Sub Command1_Click() Dim y As Single y = f(-9) Text1.Text = Str(y) End Sub 运行该程序,单击命令按钮Command1,文本框Text1中显示的是() A B C D.3.1

6 5.小明在VB中定义了以下函数,功能是求a和b的最大公约数
3.3 5.小明在VB中定义了以下函数,功能是求a和b的最大公约数 Function gcd(a As Integer, b As Integer) As Integer Do While b > 0 c = a Mod b a = b b = c Loop End Function 调试中发现计算结果一直是0。错误的原因是() A.函数名有错 B.变量名C没有定义 C.函数没有返回值 D.b>0 应改为b>=0

7 3.3 8.两个素数的差为2,称此两个素数为素数对。下列程序是找出100以内的素数对,并成对地在列表框List1中显示结果,其中函数s判断参数m是否为素数。 Function s(m) As Boolean Dim i As Integer s = True For i = 2 To Int(Sqr(m)) If m Mod i = 0 Then s = False: Exit For Next i End Function Private Sub Command1_Click() p1 = s(3) For i = 5 To 100 Step 2 p2 = s(i) If p2 = True Then List1.AddItem Str(i - 2) + " " + Str(i) p1 = p2 End Sub

8 3.4 6.有如下VB程序段: Dim x As Single, y As Single x = Val(text1.Text) If x > 10 Then y = x * x ElseIf x > 0 Then y = 10 * x Else y = 0 End If Text2.Text = Str(y) 为了测试该程序中所有分支程序代码是否正确,以下测试数据中,最恰当的一组是 0, B. -2 , 2, C. 11,2, D.12,100,-100

9 3.4 11.有一“进制转换”程序,运行时,在文本框Text1中输入15后,界面如图3-4-4所示。 “开始”按钮Command1的单击事件处理过程如下: Private Sub Command1_Click() Const x = "转换成八进制数为" Dim y As Integer Dim s As String Dim r As Integer y = Val(Text1.Text) s = "" Do While y <> 0 r = y Mod 8 s = Str(y) + s y = y \ 8 Loop Label1.Caption = Text1.Text + x Text2.Text = s End Sub 单击“转换”按钮Command1后,标签Label1中显示的是(),文本框Text2中显示的是()


Download ppt "第二章、第三章错题分析."

Similar presentations


Ads by Google