《教材课后习题参考答案(ch1-5).docx》由会员分享,可在线阅读,更多相关《教材课后习题参考答案(ch1-5).docx(7页珍藏版)》请在第壹文秘上搜索。
1、附录二教材课后习题参考答案第一章VisualBasic概述一、填空题1.3,学习版.专业版和企业版2.代码窗口,属性窗口3.窗口、事件和消息二、单选题一、选择题1-5CBABD二、填空题1.属性事件方法4. Form_Click()三、综合题1.控件自行添加,6-10ABADD1.B2.D3.B4.C5.C6.C7.C8.B9.D10.A第二章VB可视化编程基础2.文本信息Caption3.EnabledVisible参考代码如下:5.3*4=126.数值型PrivateSubForm_Load()Labell-Caption=长,Label2.Caption=宽Label3.Caption=
2、长方形面积”TextlText=m,Tet2.Tet=Tet3.Text=,Commandl-Caption=,计算”EndSub2.程序界面自行设计,无特殊要求。参考代码如下:PrivateSubForm_Click()r=InputBoM”请输入圆的半径:“课后题2-2)MsgBox”圆的面积为”&3.14*r*rEndSub第三章VisualBaSiC程序设计基础一、选择题15DDABC610DDBDC二、填空题1.352.10+(Mod10)*103.lnstr(2,sl,s2)4.yMod4=0AndNotyMod100=0OryMod400=05.VariantLong三、1.30
3、0String2.123234String3.FalseBoolean4.55.3Long6.91Double7.65Double8.0.5Double9.2Double10.2012String四、l.(2*Tan(A)(l-Tan(A)2)2.aA2+bA2-2*a*b*Cos(C)3.(-b+Sqr(b2-4*a*c)(2*a)4.Abs(A*x+B*y+C*z)/Sqr(AA2+BA2)Ap(l+尸五、.(l+j六、参考程序如下:PrivateSubCommandl_Click()DimradAsDouble,degAsInteger,mintAsInteger,seedAsInteg
4、erConstPi=3.1415926rad=VaI(TextlJext)*180/Pideg=Fix(rad)mint=Fix(rad-deg)*60)seed=Fix(rad-deg)*60-mint)*60)Text2.Text=deg&mint&”分”&secd&”秒”EndSub第四章控制结构一、选择题1-5DCCCA6-10CBBCA11-14DBDC二、程序填空题1.1x202y=30-0.5*x3else2.1m=m102ls=02xAmin三、程序阅读题1.22.115.13.4324.15.59106.10四、编程题1 .参考代码:PrivateSubcmdCal_Clic
5、k()DimaAsSingle,bAsSingle,cAsSingleDimxlAsSingle,2AsSingle,mAsSinglea= Val(ttA.Text)b = Val(txtB.Text)c = Val(txtC.Text) m=b2-4*a*cIf m OThen两根不等的情况txtl.Text=Str(-b+Sqr(m)2a)fflStr()函数将数值转换为字符串类型txt2.Text=Str(-b-Sqr(m)/2a)EndIfEndSub2 .参考代码:PrivateSubForm_Click()Dimsa,newsasa=Val(lnputBox(inputyours
6、alary:)SelectCasesaCaseIs=2000newsa=sa*1.25CaseIs=3000newsa=sa*1.2CaseElsenewsa=sa*1.15EndSelectMsgBoxyournewsalaryis:&newsaEndSub3 .参考代码:DimnAsInteger,SAsLongs=l:n=0变量赋初值WhilesListl.ListCount-1ThenListl-AddltemTextl.TextTextlJext=Textl-SetFocusEndSubPrivateSubCommand2_Click()DimiAsIntegeri=Listl.Li
7、stlndexIfi-1ThenListl.RemoveltemiEndIfEndSubPrivateSubCommand3_Click()ListKIearEndSubPrivateSubForm_Load()Ustl.Addltem”研发项目经理Ustl.Addltem”主管”Ustl.Addltem高级程序员Ustl.Addltem”程序员及测试人员”Ustl.Addltem”售前支撑经理”Ustl.Addltem综合管理员”EndSub3 .参考代码:PrivateSubHScrolll_Change()Labell-BackCoIor=RGB(HScrolll.Value,HScro
8、ll2.Value,HScroll3.Value)EndSubPrivateSubHScroll2_Change()Labell.BackCoIor=RGB(HScrolll.Value,HScroll2.ValuezHScroll3.Value)EndSubPrivateSubHScroll3_Change()Labell-BackCoIor=RGB(HScrolll.Value,HScroll2.Value,HScroll3.Value)EndSub4 .参考代码:PrivateSubCommandl_Click()Timerl1EnabIed=TrueEndSubPrivateSubFo
9、rm_Load()Picturel.Scale(0,0)-(500,500)Imagel1Picture=LoadPicture(App.Path+tul.jpg)EndSubPrivateSubTimerl_Timer()Iflmagel.Left+lmagel.WidthPicturel-ScaIeLeft+Picturel.ScaleWidthThenCommandlVisibIe=FalseImagel-Height=Imagel.Height+50lmagel.Width=lmagel.Width+50Elselmagel.Width=20Imagel-Height=20Comman
10、dlVisibIe=TrueEndIfEndSub5 .参考代码:PrivateSubCommandl_Click()Timerl1EnabIed=TrueTimerlJntervaI=100Commandl.Caption=开始EndSubPrivateSubCommand2_Click()Timerl1EnabIed=FalseCommandl.Caption=重新开始”EndSubPrivateSubForm_Load()LabeIl.FontSize=20Labell.ForeCoIor=vbBlueLabeIl.FontBoId=TrueEndSubPrivateSubTimerl_Timer