课后习题参考答案第1章VisualBasic6.0一、判断题1--5:√×√×√6――10:××√×√11――13:√××二、选择题1――5:ADBBB6――10:.CACDB三、填空题1、图片框和框架2、对象3、控件屏幕4、Load5、LoadActivate四、程序设计题1、PrivateSubCommand1_Click()PrintText1.TextEndSubPrivateSubCommand2_Click()EndEndSub2、PrivateSubCommand1_Click()Form1.FontSize=Form1.FontSize+3Print青春无悔EndSubPrivateSubCommand2_Click()FontSize=FontSize-3Print青春无悔EndSubPrivateSubCommand3_Click()Form1.FontBold=TruePrint青春无悔EndSubPrivateSubCommand4_Click()FontBold=FalsePrint青春无悔EndSub3、PrivateSubCommand1_Click()Text1.Visible=FalseEndSubPrivateSubCommand2_Click()Text1.Visible=TrueText1.FontName=楷体_gb2312Text1.FontSize=15Text1.Text=我学会了创建一个应用程序了!EndSub第二章判断题:1~5错错错错错第3章顺序结构程序设计一、思考题略二、程序阅读题1.A=2B=1C=22.123.BABCBACBC4.12False5.1-12-123-1234-三、选择题1.B2.D3.B4.B5.D6.C四、程序设计题1.Privatesubform_click()Dimr!,s!R=val(inputbox(“r=”))S=3.14159*r*rPrint“s=”;sEndsub2.Privatesubform_click()DimxassingleX=val(inputbox(“x=”))Printfix(x*x*1000)/1000,fix(sqr(x)*1000)/1000Endsub第4章选择结构程序设计一、判断题1.错2.错3.错4.错5.对二、选择题1.A2.D3.A4.B5.A6.A三、程序阅读题1.X=3y=72.w=4w=13w=135w=313.X_`a12Uvw&4.129四、程序填空题1.(1)chr(keyascii)(2)chr(keyascii)=”)”(3)count1=count1-1(4)count1=0(5)count102.(1)max(2)min(3)cmax(4)cmin3.(1)xmod3=2andxmod5=3andxmod7=4then(2)text1.setfocus(3)text1.selstrat=0(4)text1.sellength=len(text1.text)五、1.PrivateSubCommand1_Click()DimyAsIntegery=Val(InputBox(y=))If(yMod4=0AndyMod1000)Or(yMod400=0)ThenPrint是闰年ElsePrint不是闰年EndIfEndSubPrivateSubCommand1_Click()DimyAsInteger,y1asstringy=Val(InputBox(y=))If(yMod4=0AndyMod1000)Or(yMod400=0)ThenY1=是闰年ElseY1=不是闰年EndIf?y,y1EndSubPrivateSubCommand1_Click()DimyAsInteger,y1asstringy=Val(InputBox(y=))Y1=不是闰年If(yMod4=0AndyMod1000)Or(yMod400=0)ThenY1=是闰年EndIf?y,y1EndSub2.PrivateSubCommand1_Click()Dima%,b%,c%,x!,s!a=Val(InputBox(a=))b=Val(InputBox(b=))c=Val(InputBox(c=))Ifa+bcAnda+cbAndb+caThenx=(a+b+c)/2s=Sqr(x*(x-a)*(x-b)*(x-c))Prints=;sElsePrint不是三角形,重输a,b,cEndIfEndSubPrivateSubCommand1_Click()Dima%,b%,c%,x!,s!,t%a=Val(InputBox(a=))b=Val(InputBox(b=))c=Val(InputBox(c=))‘a,b,c=3,4,5t=0Ifa+bcAnda+cbAndb+caThenx=(a+b+c)/2s=Sqr(x*(x-a)*(x-b)*(x-c))t=1EndIfIft=0then?“不是“endifEndSub3.PrivateSubCommand1_Click()Dimx!,y!x=Val(InputBox(x=))y=x*x-x–xIfx0Andx-3Theny=x*x+x-6ElseIf0=xAndx10Andx2Andx3Theny=x*x-5*x+6EndIfPrintx=;x,y=;yEndSubPrivateSubCommand1_Click()Dimx!,y!x=Val(InputBox(x=))Ifx0Andx-3Theny=x*x+x–6elseIf0=xAndx10Andx2Andx3Theny=x*x-5*x+6elsey=x^2-x-1EndIfPrintx=;x,y=;yEndSubPrivatesubform_click()Dimy%,z%,dj%,p!,t!Y=val(inputbox(“月”))Z=val(inputbox(“订票数”))Dj=val(inputbox(“票价”))Selectcaseycase7,8,9Ifz=20thenp=0.15elsep=0.05case1to5,10,11Ifz20thenp=0.3elsep=0.2CaseelseP=0.2EndselectT=z*dj*p?tendsub5.privatesubform_click()dimm1%,m2%,m3%,dj$m1=val(inputbox(“m1=”)):m2=val(inputbox(“m2=”)):m3=val(inputbox(“m3=”))if(m1+m2+m3)/3=95or(a=100andb=100andc=80)or(a=100andc=100andb=80)or(c=100andb=100anda=80)thendj=”一等”elseif(m1+m2+m3)/3=90or(a=100andb=75andc=75)or(b=100anda=75andc=75)or(c=100andb=75anda=75)thendj=”二等”elseifa=75andb=75andc=75thendj=”三等”elsedj=”没有”endif?“dj=”;djendsub第5章循环结构程序设计1.判断题×√√√××√×2.选择题BBBBCC3.填空题(1)7(2)Do/LoopFor/NextWhile/Wend(3)-364.程序阅读题(1)(2)(3)4(4)5.程序填空题(1)①sign=1②Fori=2to19(2)①Len(str1)②length-1③Mid(str1,i,2)④Sum=0(3)①Imod7=5andiMod5=3AndiMod3=2②i1000(4)①last_one=last_two②last_two=this_one③i=i+1④i-2(5)①Iint(sqr(m))②Int(Sqr(n-m))6.编程题(1)PrivateSubForm_Click()DimiAsInteger,jAsIntegerDimsAsDouble,SumAsDoubles=1886886468864246886421234Sum=10#####################Sum=0Fori=1To11Step2Forj=1Tois=s*jNextjSum=Sum+sNextiPrintSumEndSub(2)PrivateSubForm_Click()Dimm%,n%,mn%,r%,t%m=Val(InputBox(m=))n=Val(InputBox(n=))Ifn=0Orm=0ThenMsgBox数据有误EndEndIfmn=m*nIfmnThent=m:m=n:n=tEndIfDoWhile(n0)r=mModn:m=n:n=rLoopForm1.Print最大公约数=;mForm1.Print最小公倍数=;mn/mEndSub(3)PrivateSubForm_Click()Dimi%,j%Fori=1To5PrintSpc(20-i);Forj=1To2*i-1PrintTrim(Str(i));NextjPrintNextiFori=4To1Step-1PrintSpc(20-i);Forj=1To2*i-1PrintTrim(Str(10-i));NextjPrintNextiEndSub(4)PrivateSubForm_Click()DimxAsIntegerDimyAsIntegerDimzAsIntegerForx=0To100Fory=0To100-xz=100-x-yIf5*x+3*y+z/3=100ThenPrintx,y,zNextyNextxEndSub(5)PrivateSubForm_Click()DimxAsSingle,yAsSingle,aAsSingle,iAsIntegerx=Val(InputBox(输入x:))a=1:y=a:i=0Whilea=0.00001i=i+1:a=a*x/i:y=y+aWendPrinty=;yEndSub第六章答案一、判断题1.错2.错3.错4.错(可以为小数,不过仍然是当作整数来处理)5.错6.错二、选择题1.C2.C3.A4.D三、程序填空1.(1)N-1(2)T=A(J):A(J)=A(J+1):A(J+1)=T(3)PrintA(I)2.(1)a(i,j)=1(2)Print四、程序阅读1.52.123412341234123411112222333344443.(前面空4个空格)11211102131693141584567第7章过程判断题:1、对2、错3、错4、错5、对6、对7、错选择题:1.B2、D3、D4、C5、A程序阅读题:1、y=5a=52、n=1z=4y=15a=10n=2z=7y=30a=15n=3z=103、32644、22216648644645、A1=10B1=20A2=20B2=10程序填空题:1、(1)hwstring(str)(2)(3)AsBoolean(4)n=len(strtxt)(5)True(6)False2.(1)Xsch(Nman,Nkcen)(2)n(3)sum=sum+x(i,j)(4)tt/n(5)x(i,m+1)1.2*verandx(i,m+1)=1.1*ver3.(1)number(i)(2)ByvalnasInteger(3)number=number+7*10^(i-1)4.(1)temp=1(2)temp(3)nFactor(i)(4)sum程序设计题:1、具体程序为:FunctionMaxnum(ByRefa()AsInteger,ByValnAsInteger)AsIntegerDimiAsIntegerMaxnum=a(1)Fori=2TonIfa(i)MaxnumThenMaxnum