VB课后习题参考答案.pdf
《VB课后习题参考答案.pdf》由会员分享,可在线阅读,更多相关《VB课后习题参考答案.pdf(21页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、第 1 章 习题参考答案一、思考题略二、选择题1.C2,B第 2 章习题参考答案一、判断题题号1234567891011答案XXVXXVVV二、填空题1.窗体font2.不能在代码中设置3.seistart_4.Locked5.T a b i n d e x、06.vbModal 或 17.Ac t i v a t e、Deactivate8.PictureBox 和 Frame三、选择题题号12345678910答案DCDADBBBAB第三章习题参考答案一、思考题1、double2、xyCabc,15eyd,Is,#END X8P3、变 量 有(1)(4)(6)(8),常 量 有(2)字符串
2、型(3)逻 辑 型(5)字符串型(7)字符串型(9)日期型(10)实型4、ab+d+r-5、(1)26(2)3.75(3)36、写Hi下列Visual Basic表达式的值:(1)False(2)True(3)True(4)False(5)True(6)True(7)False(8)False7 将下列命题用Visual Basic布尔表达式表示:(1)zx and zy(2)abs(a)b+2(3)p mod q=0(4)x-2 and x5(5)xz or xz and yz(6)a0 and y0 o xvO and yvO 或 x*y 0。10.s=A and sv=Z or s=a
3、and sv=z 三、选择题题号12345答案cBBBD四、编程题Private Sub Form_Click()Dim x%,Ten%,hundred%x=Val(Textl.Text)Ten=(x 10)Mod 10hundred=x 100Print”百位数是:&hundredPrint 十位数是:“&TenEnd Sub2Private Sub Form_Click()Dim char As String*1Forml.CurrentX=Rnd*Form 1 .ScaleWidthForml.CurrentY=Rnd*Form 1 .ScaleHeightchar=Chr(Int(Rn
4、d*16)+65)Print charEnd Sub第 4 章 习 题 参 考 答 案一、判断题题号12345678答案XXXVVJJX二、选择题题号12345答案ADBBB三、程序阅读写出下列各段程序执行后的输出结果。1.785786357864135786422.w=4、w=13、w=135、w=313.此题有点错误,修改如下:是将语句 If k Asc(uAM)Then k=k+26w 改为:Ifk Asc(nZn)And k Asc(uan)Then k=k+26改后的答案:xyzal2 uvw&4.ABBBCCCCCDDDDDDDEEEEEEEEE5.此题的“HF KeyAsci=1
5、3 Then”改为 HF KeyAscii=13 Then”答案是:129四、程序填空题1.(1)Sing=-1(2)For i=2 to 19(3)Sing=一 SingX17x)zX)/17a(2(3(42.(1)L e n(ol d se n)(2)M i d(ol d se n,i,1)(3)Uc a se(c h a r)(4)c h a r3.L e n(strl)L e ng th-1M i d(strl,i,2)S um=04.(1)Tri m(S tr(i)(2)Tri m(S tr(i*i)(3)R i g h t(x2,L e n(xl)=xl5.(1)last_one=
6、last_two(2)last_two=this_one(3)i=i+1(4)i-1五、编程题1.Private Sub Form_Click()Dim RI As Double,R2 As Double R I,R2 表示两电阻值Dim Rp As Double,Rs As DoubleRI=Val(InputBox(输入电阻 RI=?)R2 二 Val(InputBox(输入电阻 R2=?”)Rp=Rl*R2/(R1+R2)Rs=Rl+R2Rp=Fix(Rp*1000+0.5)/1000,保留小数点后 3 位Rs=Fix(Rs*1000+0.5)/1000,保留小数点后 3 位MsgBox
7、”并联电阻是:“&Rp&vbCrLf&”串联电阻是:&RsEnd Sub2.Private Sub Form_Click()Dim N As LongN=Val(InputBox(”请输入年份“,“提示框”)If(N Mod 400=0)Or(N Mod 4=0 And N Mod 100 0)Then,判断条件Print N&”年是闰年”ElsePrim N&年不是闰年End IfEnd Sub3.Private Sub Form_Click()Dim a!,b!,c!,s!,x!a=Val(InputBox(HEnter A=?M)b=V al(Inpu tBox(Enter B=?)c=
8、Val(InputBox(Enter C=?H)If a+b c And b+c a And a+c b Then,如果能构成三角形x=(a+b+c)/2s=Sqr(x*(x-a)*(x-b)*(x-c)Print S=u;sElsePrint”数据有错,不能构成三角形”End IfEnd Sub4.(此题不适合使用Select语句)Private Sub Command 1 _Click()Dim x As Double,fx As Doublex=Val(InputBox(输入 x=?)If x 0 And x -3 Thenfx=x*x+x-6Elself x=0 And x 10 An
9、d x 2 And x 3 Thenfx=x*x-5*x +6Elsefx=x*x-x-lEnd IfPrint nx=x;”f(M&x&)=H;fxEnd Sub5.Dim i As IntegerDim s As Long,t As Longt=1For i=1 To 10t=t*is=s+tNext iPrintn S=n&sDim i%,s!,n!,t!,f%i=1 项数s=0 累加和n=1 ,阶乘t=1 通项f=1 嗦数Do While t 0.000001s=s+f*ti=i+1n=n*it=1 /nf=-f 表示符号LoopPrint S=;s方法一Private Sub For
10、m_Click()Dim i As IntegerDim Hundred As Integer,Ten As Integer,One As Integer 定义百位,I,位,个位数For i=100 To 999Hundred=i 100,求百位数Ten=(i 10)-Hundred*10,求十位数One=i Mod 10,求个位数Ifi=Hundred A 3+Ten A 3+One A 3 Then 判断是否为素数Prinli&”是水仙花数”End IfNext iEnd Sub 方法二Private Sub Form_Click()Dim i As IntegerDim Hundred
11、As Integer,Ten As Integer,One As Integer 定义百位,十位,个位数For Hundred=1 To 9,百位数ForTen=0To9 十位数For One=0 To 9i=Hundred*100+Ten*10+OneIf i=Hundred A 3+Ten A 3+One A 3 Then 判断是否为素数Print i&”是水仙花数”End IfNext OneNext TenNext HundredEnd SubDim a As Double,xO As Double,xl As Doublea=Val(InputBox(“输入 a=巧xO=axl=2/
12、3*x0+a/(3*x 0*xO)Do While Abs(xl-xO)0,000001xO=xl初值第一次迭代后的值控制精度迭代x l=2/3*x 0 +a/(3*x 0*xO)LoopPrint 立方根:;xl第 5 章习题参考答案一、判断题题号123456答案JVXXVJ二、选择题题号123答案DAC三、程序填空1.Preserve a(n+l)a(i+l)=a a(i+l)=m n+1 或 Ubourid(a)2.Print_K-lt=a(k,j):a(k,j)=k):k)=t3.Rnd*100P=10p=JP=0四、编写程序1.Private Sub Command 1 _Click
13、()Dim A()As Integer,N As IntegerDim i As Integer,M As Integer,t As Integer,k As IntegerN=Val(InpulBox(请输入数组的大小N=?n)M=Val(InputBox(”请输入移位次数M?)输入循环次数的大小IfN=0 Then Exit SubReDimA(N-1)Print”原始数组值”Fori=0ToN-1 ,给数组赋值A(i)=Int(Rnd*100)Print A(i);Next iPrint 移位For i=1 To M,循环体完成右移一位,循环完成右移j位t=A(N-1)For k=N-1
14、 To I Step-1 循环右移A(k)=A(k-1)Next kA(0)=tNext i 打印右移后的数组值Print”循环右移“&M&”位后的数组值”For i=0 To N-1Print A(i);Next iPrintEnd Sub2.Const NM=100Private Sub Command 1 _Click()Dim a(l To NM)As Single,b(l To NM)As Integer,max As IntegerDim i As Integer,j As Integer,k As Integer,t As IntegerFor i=1 To NM 输 入 100
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- VB 课后 习题 参考答案
限制150内