您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 人事档案/员工关系 > 《VB程序设计基础》习题答案
VisualBasic程序设计基础P16习题一一,判断题1,错2,对3,错4,错5,6,7,对二,单选题1,B2,B3,D4,A5,D6,B7,B8,C9,D三,程序设计题5,PrivateSubCommand1_Click()Form1.FontName=宋体Form1.Print中文字体宋体EndSubPrivateSubCommand2_Click()Form1.FontName=楷体_GB2312Form1.Print中文字体楷体EndSubPrivateSubCommand3_Click()Form1.FontName=仿宋_GB2312Form1.Print中文字体仿宋EndSubP42习题二一,判断题1,2,3,7,10,对4,5,6,8,9,11,12,13,14错二,单选题1,A2,C3,C4,B5,B6,A7,B8,C9,B10,C11,C12,D13,B14,A15,D16,B17,B18,C19,B20,B21,B22,D23,A24,C25,B26,A27,D28,B三,简答题1.(1)2*Cos(alfa)*Sin(alfa/(2*a)(2)Sqr(s*(s–a)*(s–b)*(s-c))(3)(A^2+B*C*(X+Y))/(A+B)(4)(2*3.14159*r+Exp(-5))*Log(x)(5)1/(x+1/(y+1))(6)k/(1+a*Exp(-b*x))(7)5+6*x/(3*(x^2-1)-2*x)(8)Sqr(y^3+3*(a^2+b^2)/(x^2+y^2))2.(1)(a+b)Modc(2)Sqr(Abs(x))(3)Int(x)+1(4)Int(Rnd*101)+2003.PrivateSubForm_Click()DimaAsInteger,bAsIntegerDimcAsInteger,yAsLonga=InputBox(请输入a的值)b=InputBox(请输入b的值)c=InputBox(请输入c的值)y=a^2+2*b^2+2*c^2Printy=;yEndSub4。(1)F(2)T(3)F(4)T5.(1)1=xAndx12(2)T+3V-2And(T+V)100(3)(a+b)=cor(a-c)=c(4)a0AndInt(a)=aAndb0AndInt(b)=bora0Andb0(5)x=yOrx=z(6)a=0Andb0ora0Andb=0四,编程题1.PrivateSubForm_Click()DimaAsInteger,bAsIntegerDimcAsInteger,yAsSinglea=InputBox(请输入正整数a的值)b=InputBox(请输入正整数b的值)c=InputBox(请输入正整数c的值)y=(a+b+c)/3Print平均值y=;yEndSub2.PrivateSubForm_Click()DimrAsInteger,sAsSingleConstPi=3.14159r=InputBox(输入圆半径,输入,10)s=Pi*r*rMsgBox圆面积Area=&Str(s)EndSubP78习题三一,1,A2,B3,B4,A5,C二,1,37,55,64,28,192,y=KIGECA3,1121123211234321123454321123456543214,cHINA!三,1,tAsDoubles=1Abs(t)=1e-5s=s+t2,s+c-1s3,m=nmTonSum=Sum+jSum=i四,1,PrivateSubForm_Click()DimxAsSingle,fAsSinglex=InputBox(输入x:)Ifx-5Thenf=3*x*x+2*x-1ElseIfx=5Thenf=x*Sin(x)+2^xElsef=Sqr(x-5)+Log(x)/Log(10)EndIfLabel1.Caption=fEndSub2.PrivateSubForm_Click()DimiAsInteger,flagAsIntegerDimtAsDouble,yAsDoubley=0flag=1t=0.5i=1WhileAbs(t)=0.00001t=1/i/(i+1)y=y+flag*tflag=-flagi=i+1WendPrinty=;yEndSubY=0.3862893854756693.PrivateSubForm_Click()DimnAsInteger,iAsInteger,flagAsInteger,sAsSingle,tAsIntegern=InputBox(请输入n的值:)sum=0t=1flag=-1Fori=1Tonflag=-flagt=t*is=s+flag*i/tNextiPrints=;sEndSub4.PrivateSubCommand1_Click()Fori=1To9Forj=1ToiPrinti;*;j;=;i*j;NextjPrintNextiEndSub5.PrivateSubForm_Click()Fori=1To5PrintTab(6-i);Forj=1To2*i-1Print*;NextjPrintNextiFori=4To1Step-1PrintTab(6-i);Forj=1To2*i-1Print*;NextjPrintNextiEndSubP104练习四一、单选题1,D2,C3,C4,C5,D二、程序阅读题1,121092,0112323、div=3三、程序填空题1、Len(str1)Mid(str1,i,1)p=jip2、l=Len(St$)a(i)=Mid(St$,i,1)p=s-96x(p)=x(p)+13、a(1To4,1To5)s=0a(i,5)=s/4四、程序设计题1.PrivateSubForm_Click()Dima(50)AsIntegerFori=1To50a(i)=Int(Rnd*71)+30Printa(i);IfiMod5=0ThenPrintNextiMin=a(1):Max=a(1):s=0Fori=2To50IfMina(i)ThenMin=a(i)IfMaxa(i)ThenMax=a(i)s=s+a(i)NextiPrintmax=;Max,min=;Min,average=;s/50EndSub2.PrivateSubForm_Click()DimmaxAsInteger,minAsIntegerDima()AsIntegern=Val(InputBox())ReDima(n)AsIntegerFori=1Tona(i)=Int(Rnd*100)Printa(i);NextiFori=1TonIfa(i)Mod2=0Thenmin=a(i)Elsemax=a(i)Ifmin0Andmax0ThenExitForNextiFori=1TonIfa(i)Mod2=0Andmina(i)Thenmin=a(i)ElseIfa(i)Mod2=1Andmaxa(i)Thenmax=a(i)EndIfNextiPrintmax=;max,min=;minEndSub3.冒泡法:PrivateSubForm_Click()Dima(10)AsIntegerFori=1To10a(i)=Int(Rnd*90)+10Printa(i);NextiPrintFori=1To9Forj=1To10-iIfa(j)a(j+1)Thent=a(j):a(j)=a(j+1):a(j+1)=tNextjNextiFori=1To10Printa(i);NextiEndSub选择法:PrivateSubForm_Click()Dima(10)AsIntegerFori=1To10a(i)=Int(Rnd*90)+10Printa(i);NextiPrintFori=1To9Forj=i+1To10Ifa(i)a(j)Thent=a(i):a(i)=a(j):a(j)=tNextjNextiFori=1To10Printa(i);NextiEndSub4、PrivateSubForm_Click()Dima(20)AsInteger,score(5)AsIntegerFori=1To20a(i)=Int(Rnd*101)Printa(i);NextiPrintFori=1To20Ifa(i)=90Thenscore(1)=score(1)+1ElseIfa(i)=80Thenscore(2)=score(2)+1ElseIfa(i)=70Thenscore(3)=score(3)+1ElseIfa(i)=60Thenscore(4)=score(4)+1Elsescore(5)=score(5)+1EndIfNextiFori=1To5Printscore(i)NextiEndSubP126练习五一.对:1,2,3,4,6,7,9错:5,8二.1,D2,C3,A4,B5,D6,?7,?8,D三.1,1)a()AsSingle,mAsInteger2)j=i+1Tom3)a(i)a(j)4)Callpf(b,n)2,1)Int(Rnd*21)+302)Forj=i+1To103)CallSwap(a(i),a(j))4)a(10)3,1)IfIsprime(i)=TrueAndIsprime(x-i)=TrueThen2)Isprime=True3)IfxModi=0Then四,1.9762,4-93,6464836424,269五、1、PrivateSubCommand1_Click()Dima()AsSingle,nAsInteger,sAsSingleDimvAsSingle,iAsIntegern=InputBox(请输入n的值)ReDima(n)Fori=1Tona(i)=InputBox()Nextiv=f(a,n)Fori=1Tons=s+(a(i)-v)^2Nextis=Sqr(s)/nPrintsEndSub2、PrivateFunctionfsum(a()AsSingle,nAsInteger)AsSingleDimiAsIntegerFori=1Tonfsum=fsum+a(i)NextiEndFunction3、PrivateSubff(x()AsSingle,mAsByte,nAsByte,xmaxAsSingle,kiAsByte,kjAsByte)DimiAsInteger,jAsIntegerxmax=x(1,1):ki=1:kj=1Fori=1TomForj=1TonIfx(i,j)xmaxThenxmax=x(i,j):ki=i:kj=jNextjNextiEndSubP153练习六一,对:5错:1,2,3,4,6,7,8,9,10二.1,D2,D3,题目有错(应改为True)A4,C5,C6,D7,C8,D9,与2重复10,C11,B12,B13,B14,B三.1.(1)DimaAsInteger,bAsInteger(2)Str(n)+Str(n_error)(3)KeyPress(4)KeyAscii13(5)Command1.Enabled=True2.(1)1To2*i–1(2)Command2.Enabled=True(3)Command2.Enabled=False四.1.GFEDCBA2.小,你好!小李,你好!3.您好欢迎使用VisualBasic!五.1.PrivateSubCommand1_Click(IndexAsInteger)DimyAsSingleSelectCaseIndexCase0y=Val(Text1.Text)+Val(Text2.Text)Label4.Caption=Text1.Text+++Text2.Text+=+Str(y)Case1y=Val(Text1.Text)-Val(Text2.Text)Lab
本文标题:《VB程序设计基础》习题答案
链接地址:https://www.777doc.com/doc-2864966 .html