好文档 - 专业文书写作范文服务资料分享网站

《VisualBasic程序设计基础》陈庆章课后习题参考答案

天下 分享 时间: 加入收藏 我要投稿 点赞

1 3 3 1 1 4 6 4 1 四、程序填空题

1.(1)ByeVal (2)k Mod i (3)k = k \\ i 2.(1)a() Aa Double (2)n-1 (3)a(j) < a(k) 3.(1)a() As Double, n As Integer 五、程序设计题

程序1.界面设计略,过程设计如下:

Private Function fsum(x() As Double, n As Integer) As Double Dim i As Integer For i = 1 To n

fsum = fsum + x(i) Next i

fsum = fsum / n End Function

程序2.界面设计略,过程设计如下:

Private Sub ff(a() As Single, n As Integer) Dim i As Integer, x As Single For i = 1 To n \\ 2

x = a(n - i + 1): a(n - i + 1) = a(i): a(i) = x Next i End Sub

程序3.界面设计略,过程设计如下:

Private Sub find(x() As Single, m As byte, n As Byte, _

xmax As Single,ki As Byte,kj As Byte)

xmax = x(1,1): ki = 1: kj = 1 For i = 1 To m For j = 1 To n

If Abs(x(i, j)) > Abs(xmax) Then xmax = x(i, j): ki = i: kj = j Next j, i End Sub

(2)t = t * x

(3)f = s (4)Call pp(i)

第5章 常用控件

一、判断题

1.× 2.× 3.× 4.√ 5.× 6.√ 7.× 8.√ 9.√ 10.√ 11.× 12.× 13.√ 14.√ 15.× 16.× 17.× 18.√ 19.√ 20.× 21.√ 22.× 23.√ 24.× 25.√ 二、选择题

1.C 2.D 3.B 4.B 5.B 6.C 7.B 8.B 9.B 10.A 11.D 12.C 13.B 14.B 15.A 16.D 17.B 18.B 19.B 20.A 三、填空题

1.上、下、左、左 2.缇、无关 3.&、+ 4.Enabled 5.MaxLength 6.Text1.SetFocus 7.MultiLine 8.Visible 9.Alignment 10.AutoSize 11.ForeColor 12.0或1 13.True 14.1 15.AddItem 16.1 17.List1.Clear 18.文本框、列表框

19.下拉式组合框、简单组合框、下拉式列表框 20.Scroll 21.Value 22.Change 23.定时器不起作用 24.Timer 25.65535

四、程序阅读题

程序1. 116 程序2. 8

程序3. 23451 程序4. 小,你好! 程序5. 您好

34512 小李,你好! 欢迎使用Visual Basic!

程序6. 李子 程序7. y = 6 程序8. n = 1

苹果 y = 14 n = 3 橘子 n = 5 葡萄 柚子 香蕉

五、程序填空题

1.(1)a(i) = Mid(str1, i, 1) 或 a(i) = Mid(Text1.Text, i, 1)

(2)p = j (3)a(i) = a(p) (4)Command2.Enabled = True 2.(1)1 To 2*i–1 (2)Command2.Enabled = True (3)Command2.Enabled = False 3.(1)Text2.Enabled = False (2)p = 2 (3)Print i (4)Val(Text1.Text) < 2 或 Val(Text1.Text) <= 1 (5)KeyAscii = 13 4.(1)List1.ListCount (2)List1.RemoveItem I (3)i = i + 1 5.(1)Timer1.Enabled = True (2)x \\ 3600

(3)(x Mod 3600) \\ 60 或 (x - 3600 * h) \\ 60 (4)x = x + 1 6.(1)Label1.Left (2)Label1.Left = -Label1.Width 六、程序设计题

程序1. 界面设计略,过程设计如下: Private Sub Command1_Click() If Command1.Caption = \显示\

Print \欢迎使用Visual Basic!\清除\ Else

Form1.Cls: Command1.Caption = \显示\ End If End Sub

Private Sub Command2_Click() End End Sub

Private Sub Form_Load()

Form1.Cls: Command1.Caption = \显示\退出\End Sub

程序2.界面设计略,过程设计如下: Private Sub Form_Load()

Text1.MaxLength = 1: Text1.Text = \End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) Label1.Caption = CStr(KeyAscii) End Sub

程序3.界面设计略,过程设计如下:

Const pwd As String = \预设密码为123456 Private Sub Command1_Click() Cls: Print \欢迎进入!\End Sub

Private Sub Form_Load()

Command1.Caption = \进入\ Text1.Text = \End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then If Text1.Text = pwd Then

m = MsgBox(\口令正确,欢迎进入!\ Else

m = MsgBox(\口令错误,请重新输入!\ End If End If End Sub

程序4.界面设计略,过程设计如下:

Dim num As Integer, m As Integer, rec As Integer Private Sub Form_Load()

Command1.Caption = \出题\ Text1.Text = \End Sub

Private Sub Command1_Click()

Randomize: num = Int(Rnd * 100) + 1: Text1.Enabled = True Label1.Caption = \End Sub

Private Sub Command2_Click() End End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii = 13 Then

m = Val(Text1.Text): rec = rec + 1: Text1.SelStart = 0 Text1.SelLength = Len(Text1.Text): Text1.SetFocus If rec > 10 Then

Label1.Caption = \差!重新开始\

Else

If m > num Then

Label1.Caption = Str(m) & \大了!\ ElseIf m < num Then

Label1.Caption = Str(m) & \小了!\ Else

If rec < 5 Then

Label1.Caption = \好!猜对了。\ Else

Label1.Caption = \还行!猜对了。\ End If

Call Form_Load End If End If End If End Sub

程序5.界面设计如图10-3所示,过程设计如下: Private Sub Form_Load()

Command1(0).Enabled = False: Command1(1).Enabled = False Command1(2).Enabled = False: Label1.Caption = \End Sub

Private Sub Command1_Click(Index As Integer) Select Case Index Case 0

Clipboard.Clear: Clipboard.SetText Text1.SelText

Text1.SelText = \请选择要粘贴的位置!\ Command1(0).Enabled = False: Command1(1).Enabled = False Command1(2).Enabled = True Case 1

Clipboard.Clear: Clipboard.SetText Text1.SelText

Label1.Caption = \请选择要粘贴的位置!\ Command1(1).Enabled = False: Command1(2).Enabled = True Case Else

Text1.SelText = Clipboard.GetText(): Form_Load Label1.Caption = \粘贴完成!\ End Select End Sub

Private Sub Text1_MouseUp(Button As Integer, Shift As Integer, _

X As Single, Y As Single) Dim n As Integer n = Text1.SelLength If n > 0 Then

Label1.Caption = \选择了\个字,请选择下一步操作!\ Command1(0).Enabled = True: Command1(1).Enabled = True Else

Label1.Caption = \ End If End Sub

程序6.界面设计如图10-4所示,过程设计如下: Private Sub Form_Load()

Label1.Caption = \当前日期:\

Option1(0).Caption = \显示日期\显示时间\ Option1(0).Value = True: Command1.Caption = \退出\End Sub

Private Sub Option1_Click(Index As Integer) Select Case Index Case 0

Label1.Caption = \当前日期:\ Case 1

Label1.Caption = \当前时间:\ End Select End Sub

Private Sub Command1_Click() End End Sub

程序7.过程设计如下: Private Sub Form_Load()

Label1.Caption = \当前日期:\

Option1(0).Caption = \显示日期\显示时间\ Option1(0).Value = True: Command1.Caption = \退出\ Combo1.AddItem \年-月-日\月-日-年\ Combo1.AddItem \日-月-年\年-月-日\End Sub

Private Sub Combo1_Click() Dim n As String

Select Case Combo1.ListIndex Case 0: n = \ Case 1: n = \ Case 2: n = \ End Select

Text1.Text = Format(Date, n) End Sub

Private Sub Option1_Click(Index As Integer) Select Case Index

Case 0: Label1.Caption = \当前日期:\ Case 1: Label1.Caption = \当前时间:\ End Select End Sub

Private Sub Command1_Click() End End Sub

程序8. 界面设计如图10-5所示,过程设计如下: Private Sub Form_Load()

List1.AddItem \ List1.AddItem \End Sub

Private Sub Command1_Click()

List1.AddItem Text1.Text: Text1.SetFocus

Text1.SelStart = 0: Text1.SelLength = Len(Text1.Text) End Sub

0x8p212v4072h8v7sa970wk4t3v47w00u1f
领取福利

微信扫码领取福利

微信扫码分享