《教材课后习题参考答案(ch1-5).docx》由会员分享,可在线阅读,更多相关《教材课后习题参考答案(ch1-5).docx(6页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、附录二 教材课后习题参考答案第一章Visual Basic概述一、填空题1.3,学习版.专业版和企业版 2.代码窗口,属性窗口 3.窗口、事件和消息 二、单选题l.B 2.D 3.B 4.C 5.C 6.C 7.C 8.B 9.D 10.A第二章VB可视化编程基础一、选择题1-5 CBABD 6-10 ABADD二、填空题1.属性事件方法 2.文本信息Caption 3. Enabled VisibleForm_Click() 5. 3*4 = 126.数值型三、综合题.控件自行添加,参考代码如下:Private Sub Form_Load()Labell.Caption =长,Label2.
2、Caption = 宽”Label3.Caption = 11 长方形面积”Text 1.Text = ,H,Text 2.Text = ,H,Text 3.Text = ,nCommandl.Caption =计算”End Sub.程序界面自行设计,无特殊要求。参考代码如下:Private Sub Form_Click()r二lnputBox(“请输入圆的半径:课后题2-2)MsgBox ”圆的面积为,& 3.14 * r * rEnd Sub第三章Visual Basic程序设计基础一、选择题15 DDABC610 DDBDC二、填空题1.352.x 10 + (x Mod 10) * 1
3、0 3.lnstr(2,sl,s2)4.y Mod 4=0 And Not y Mod 100=0 Or y Mod 400=05 .Vari a nt三、1.300 String 2. 123234 String 3.False Boolean 4.5 Long5.3 Long 6.91 Double 7.65 Double 8.0.5 Double9.2 Double 10.2012 String四、l.(2*Tan(A)/(l-Tan(A)A2)2.aA2+bA2-2*a*b*Cos(C)3.(-b+Sqr(bA2-4*a*c)/(2*a)4.Abs(A*x+B*y+C*z)/Sqr(A
4、A2+BA2)+ p)“4Pi2r3五、1.(1 + ”TNF-六、参考程序如下:Private Sub Commandl_Click()Dim rad As Double, deg As Integer,mint As Integer, seed As Integer Const Pi = 3.1415926rad = Va I (Text 1.Text) * 180 / Pideg = Fix(rad)mint = Fix(rad - deg) * 60)seed = Fix(rad - deg) * 60 - mint) * 60)Text2.Text = deg& “度” & mint
5、 & “分“ &secd& “秒”End Sub第四章控制结构一、选择题1-5 D C C C A 6-10 CBBCA 11-14 D B DC二、程序填空题1. 1 x20 2 y= 30-0.5*x 3 else 2, 1 m=m10 2 ls=0 2 xAmin 三、程序阅读题1.2 2. 115.1 3.432 4. 1 5.59 10 6. 1 0四、编程题1 .参考代码:Private Sub cmdCal_Click()Dim a As Single, b As Single, c As SingleDim xl As Single, x2 As Single, m As Si
6、nglea = Val(txtA.Text)用val()函数将文本框中的字符型数据转换为数值类型b = Val(txtB.Text)c = Val(txtC.Text) m = bA2-4*a*cIf m 0 Thentxt 1.Text = Str(-b + Sqr(m) / 2 / a)用 txt2.Text = Str(-b - Sqr(m) / 2 / a) End IfIf m 0 Thentxt 1.Text = Str(-b + Sqr(m) / 2 / a)用 txt2.Text = Str(-b - Sqr(m) / 2 / a) End If,方程无根的情况两根相等的情况两
7、根不等的情况O函数将数值转换为字符串类型End Sub2 .参考代码:Private Sub Form_Click()Dim sa, newsasa = Val(lnputBox(input your salary:)Select Case saCase Is = 2000newsa = sa * 1.25Case Is = 3000newsa = sa * 1.2Case Elsenewsa = sa * 1.15End SelectMsgBox your new salary is: & newsaEnd Sub3 .参考代码:Dim n As Integer s As Longs = l
8、:n = 0变量赋初值While s Listl.ListCount -1 Then Listl.Additem Textl.TextTextl.Text =Textl.SetFocusEnd SubPrivate Sub Command2_Click()Dim i As Integeri = Listl.ListindexIf i -1 ThenListl.Removeitem iEnd IfEnd SubPrivate Sub Command3_Click()Listl.ClearEnd SubPrivate Sub Form_Load()Listl.Addltem ”研发项目经理List
9、l.Addltem ”主管,Listl.Addltem ”高级程序员,Listl.Addltem 程序员及测试人员Listl.Addltem ”售前支撑经理,Listl.Addltem ”综合管理员”End Sub.参考代码:Private Sub HScrolll_Change()Labell.BackColor = RGB(HScrolll.Value, HScroll2.Value, HScroll3.Value) End SubPrivate Sub HScroll2_Change()Labell.BackColor = RGB(HScrolll.Value, HScrolIZ.Val
10、ue, HScroll3.Value) End SubPrivate Sub HScroll3_Change()Labell.BackColor = RGB(HScrolll.Value, HScroll2.Value, HScroll3.Value) End Sub.参考代码:Private Sub Commandl_Click()Timerl.Enabled = TrueEnd SubPrivate Sub Form_Load()Picturel.Scale (0, 0)-(500, 500)Imagel.Picture = LoadPicture(App.Path + tul.jpg)E
11、nd SubPrivate Sub Timerl_Timer()If Imagel.Left + Imagel.Width Picturel.ScaleLeft + Picturel.ScaleWidth Then Commandl.Visible = FalseImagel.Height = Imagel.Height + 50Imagel.Width = Imagel.Width + 50ElseImagel.Width = 20Imagel.Height = 20Commandl.Visible = TrueEnd IfEnd Sub3 .参考代码:Private Sub Command
12、l_Click()Timerl.Enabled = TrueTimerl.Interval = 100Commandl.Caption = 开始”End SubPrivate Sub Command2_Click()Timerl.Enabled = FalseCommandl.Caption =重新开始”End SubPrivate Sub Form_Load()Labell.FontSize = 20Labell.ForeColor = vbBlueLabell.FontBold = TrueEnd SubPrivate Sub Timerl_Timer()If La bell. Left
13、+ Labell.Width Picturel.ScaleLeft + Picturel.ScaleWidth ThenLabell.Move Labell.Left + 10ElseLabell.Left = Picturel.ScaleLeftEnd IfEnd Sub4 .参考代码:Private Sub Commandl_Click()Timerl.Enabled = TrueTimerl.Interval = 100Commandl.Caption =开始End SubPrivate Sub Command2_Click()Timerl.Enabled = FalseCommandl
14、.Caption =重新开始,,End SubPrivate Sub Form_Load()Labell.FontSize = 20Labell.ForeColor = vbBlueLabell.FontBold = TrueEnd SubPrivate Sub Timerl_Timer()If La bell. Left + Labell.Width Picturel.ScaleLeft + Picturel.ScaleWidth ThenLabell.Move La bell.Left + 10ElseLa bell.Left = Picturel.ScaleLeftEnd IfEnd Sub