您好,欢迎访问三七文档
第1章一.选择题1-5DCDBB6-10DCCCC第2章二.选择题1A2D3C4B5A6D7A8B9C10C三.填空题1.对象、属性、值2.视图、工具箱3.属性、对象、事件、方法4.事件和方法5.窗体对象第3章VB语言基础参考答案一.选择题1.B2.B3.B4.C5.C6.D7.A8.B9.B10.B11.A第4章一.选择题1-5BCCAC6-10BCBCA11-14ABDD二.编程题1.顺序结构,选择结构,循环结构2.PrivateSubForm_Click()DimiAsInteger,sAsSingles=0Fori=1To5x=Val(InputBox(请输入第&i&个数))Printx;s=s+xNextiPrintPrint五个数的和为:;s,平均值为:;s/5EndSub3.PrivateSubForm_Click()n$=InputBox(请输入您的姓名)AGE$=InputBox(请输入您的年龄)addr$=InputBox(请输入您的通信地址)pos$=InputBox(请输入您的邮政编码)tel$=InputBox(请输入您的电话号码)PrintPrintTab(6);姓名;Space$(3);年龄;Space$(3);通信地址;Space$(5);邮政编码;Space$(3);电话号码PrintPrintTab(5);n$;Space$(3);AGE$;Space$(3);addr$;Space$(3);pos$;Space$(3);tel$EndSub4.PrivateSubForm_Click()DimzAsString,xAsInteger,yAsStringRandomizeTimerx=Int(Rnd*9000)+1000Print产生的随机数为:;xy=CStr(x)Fori=4To1Step-1z=z&Mid(y,i,1)NextiPrint倒序数为:;zEndSub5.PrivateSubForm_Click()DimpAsDoubleDimrAsSingleDimnAsIntegerp=1300000000#r=0.01n=0DoUntilp=1700000000#p=p*(1+r)n=n+1LoopPrintn;年后,我国人口达到17亿EndSub6.PrivateSubForm_Click()DimaAsSingle,bAsSingle,cAsSingle,sAsSingle,areaAsSinglea=Val(InputBox(请输入a边的边长))b=Val(InputBox(请输入b边的边长))c=Val(InputBox(请输入c边的边长))Ifa+b=cOrb+c=aOrc+a=bThenMsgBox所输入的值不能构成三角形Elses=(a+b+c)/2area=Sqr(s*(s-a)*(s-b)*(s-c))Print三角形的面积为:;areaEndIfEndSub7.PrivateSubCommand1_Click()DimrAsSingle,taxAsSingler=Val(Text1.Text)Ifr=800Thentax=0ElseIfr800Andr=2000Thentax=(r-800)*0.1ElseIfr2000Thentax=(r-800)*0.2EndIfText2.Text=Str(tax)EndSub8.PrivateSubForm_Click()DimiAsInteger,jAsInteger,kAsInteger,tAsIntegerPrint水仙花数如下:Fori=1To9Forj=0To9Fork=0To9t=i*100+j*10+kIfi^3+j^3+k^3=tThenPrintt;NextkNextjNextiEndSub9.PrivateSubForm_Click()s=1:i=1DoWhiles=400000i=i+2s=s*iLoopPrint其大于400000的最小值为:;sEndSub10.PrivateSubForm_Click()DimaAsInteger,iAsInteger,nAsInteger,tAsSingle,sAsSingleRandomizeTimera=Int(Rnd*9)+1n=Val(InputBox(输入累加的项数:))Print产生的随机数为:;a;项数为:;nFori=1Tont=t*10+as=s+tNextiPrint累加的结果为;sEndSub第5章一、选择题1.D2.D3.B4.D5.C6.C7.A8.B9.C10.C11.D12.B13.A14.A15.B16.A二、填空题1.NameIndex2.Preserve3.变体4.12或arr1(1)Min=arr1(i)5.a(i,j)a(i,j)=a(j,i)t6.2to6arr(i)max7.Left(c1,i)四、编程题1.Dima(1to10)asIntegerDimiAsIntegerFori=1To10‘输入a(i)=Val(InputBox(输入a(&i&)的值))NextiFori=1To10‘打印printa(i);NextiFori=1To10\2‘倒置t=a(i)a(i)=a(10-i+1)a(10-i+1)=tNextIPrint‘换行Fori=1To10‘输出printa(i);Nexti2.程序要点:Max=a(1,1)Fori=1ToNForj=1ToMIfa(i,j)MaxThenMax=a(i,j)EndIfNextjNextiPrint最大元素是;Max3.OptionExplicitDimaddress(100,2)AsStringPrivateSubCommand1_Click()DimiAsIntegerDimnameAsStringDimfoundAsBooleanfound=False'name=InputBox(请输入查询的姓名,数据输入)name=Text1.TextFori=0To100Ifaddress(i,0)=nameThenfound=TrueMsgBoxname+的家庭地址是:+address(i,1)ExitForEndIfNextiIffound=FalseThenMsgBox查无此人!EndSubPrivateSubForm_Load()address(0,0)=张洪address(0,1)=湖北宜昌address(1,0)=王玉address(1,1)=江苏淮阴address(2,0)=李明address(2,1)=湖南长沙EndSub4.设计方法:在窗体上添加6个命令按钮,用来触发有关运算的事件过程;3个图片框,分别用来显示A矩阵、B矩阵及各种运算结果。参考程序如下:OptionExplicitOptionBase1DimA(4,4)AsInteger,B(4,4)AsIntegerPrivateSubCommand1_Click()'生成并显示A、B矩阵Dimi%,j%Picture1.ClsPicture2.ClsPicture3.ClsFori=1To4Forj=1To4A(i,j)=Int(Rnd*11+30)Picture1.PrintA(i,j);;B(i,j)=Int(Rnd*11+10)Picture2.PrintB(i,j);NextjPicture1.PrintPicture2.PrintNextiEndSubPrivateSubCommand2_Click()'矩阵AB相乘存入CDimC(4,4)AsInteger,i%,j%,Max%,H%,L%Picture3.Cls:Picture3.PrintPicture3.Print矩阵AB相乘存入C&vbCr;vbCr;矩阵C为:Picture3.PrintFori=1To4Forj=1To4C(i,j)=A(i,1)*B(1,j)+A(i,2)*B(2,j)+A(i,3)_*B(3,j)+A(i,4)*B(4,j)Picture3.PrintC(i,j);NextjPicture3.PrintNextiPicture3.PrintEndSubPrivateSubCommand3_Click()',并找出C中最大、最小元素及其下标Dimi%,j%Picture3.ClsPicture3.Print找出C中最大、最小元素及其下标:Picture3.Print'Max中存最大值,H(L)中存最大值所在行(列)下标Max=C(1,1):H=1:L=1Fori=1To4Forj=1To4IfC(i,j)MaxThenMax=C(i,j)H=iL=jEndIfNextjNextiPicture3.Print最大值=;Max&vbCr;vbCr;所在下标=;H;,;L'MIN中存最大值,H(L)中存最大值所在行(列)下标Min=C(1,1):H=1:L=1Fori=1To4Forj=1To4IfC(i,j)MinThenMin=C(i,j)H=iL=jEndIfNextjNextiPicture3.Print最小值=;Min&vbCr;vbCr;所在下标=;H;,;LEndSubPrivateSubCommand4_Click()'矩阵A第一行与B第三行交换Dimi%,j%Picture3.Cls:Picture3.PrintPicture3.Print矩阵A第一行与B第三行交换:Fori=1To4T=A(1,i):A(1,i)=B(3,i):B(3,i)=TNextiEndSubPrivateSubCommand5_Click()'两条对角线元素平均值Dimi%,S1%,S2%,S%Picture3.ClsPicture3.Print两条对角线元素平均值:S1=0Fori=1To4Picture3.PrintSpc((i-1)*4);Picture3.PrintA(i,i)S1=S1+A(i,i)NextiPicture3.Print元素之和=;S1;vbCrPicture3.Print矩阵A右上左下对角元素:S2=0Fori=4To1Step-1Picture3.PrintSpc((i-1)*4);Picture3.PrintA(5-i,i)S2=S2+A(5-i,i)NextiPicture3.Print元素之和=;S2Picture3.Print两条对角线元素平均值=;(S1+S2)/8EndSubPrivateSubCommand6_Click()'一维数组Dimi%,j%,k%,D(1To16)AsIntegerPicture3.Cls:Picture3.PrintPicture3.Print将矩阵A按列顺存入一维数组D&vbCrPicture3.PrintD数组各元素为:&vbCrFori=1To4Forj=1To4k=(i-1)*4+j'数组D元素下标D(k)=A(j,i)'按列顺序存入数组DPicture3.PrintD(k);'显示'根据图片框宽度限制每行显示的元素个数IfkMod6=0ThenPicture3.PrintNextjNextiEndSub5.PrivateSubForm_Click()Dima(20)ForI=1To20a(I)=Val(InputBox(输入数据:))Printa(I);NextIForI=1To20\2T=a(I)a(I)=a(20-I+1)a(20-I+1)=TNextIPrintForI=1To20Printa(I);NextIEndSub第6章一.选择题1B2B3D4C5A6D7C8B9C10B11C12C第7章一.选择题1.B2.D3.A4.D5.A6.D7.A8.D9.A10.B11.A12.C13.D14.B
本文标题:VB课后习题答案1
链接地址:https://www.777doc.com/doc-2854367 .html