• 344.00 KB
  • 2022-04-22 11:24:30 发布

华工最新版VB习题答案.doc

  • 40页
  • 当前文档由用户上传发布,收益归属用户
  1. 1、本文档共5页,可阅读全部内容。
  2. 2、本文档内容版权归属内容提供方,所产生的收益全部归内容提供方所有。如果您对本文有版权争议,可选择认领,认领后既往收益都归您。
  3. 3、本文档由用户上传,本站不保证质量和数量令人满意,可能有诸多瑕疵,付费之前,请仔细先通过免费阅读内容等途径辨别内容交易风险。如存在严重挂羊头卖狗肉之情形,可联系本站下载客服投诉处理。
  4. 文档侵权举报电话:19940600175。
'《VB.NET语言程序设计》习题答案第1章概述1.1填空题1.答案:低级语言、高级语言2.答案:编译、解释3.答案:编译、运行、逻辑1.2问答题略1.3编程题1.解答:ImportsSystem.ConsoleModuleModule1SubMain()WriteLine("欢迎使用VisualBasic!")EndSubEndModule2.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dimx,yAsDoubleWrite("请输入的矩形的长:")x=ReadLine()Write("请输入的矩形的宽:")y=ReadLine()WriteLine("圆周长={0:f}",2*x+2*y)"计算输出周长WriteLine("圆面积={0:f}",x*y)"计算输出面积EndSubEndModule第2章基本数据类型与表达式2.1填空题1.答案:关键字2.答案:标识符3.答案:4、8、4、8、164.答案:整、单精度浮点、货币5.答案:函数运算、算术运算、关系运算、逻辑运算6.答案:Round(1234.567,0)4 7.答案:Mid(“VisualBASIC6.0”,8,5)8.答案:Int((b-a+1)*Rnd+a)2.2选择题1.答案:c2.答案:d3.答案:c4.答案:c5.答案:b6.答案:a7.答案:c8.答案:a9.答案:d10.答案:b2.3下列变量名哪些是正确的,哪些是错误的?答:1.n正确。2.3x错误。变量名必须以字母为开始。3.Abs错误。不能和关键字同名。4.85错误。变量名必须以字母开始。5.print_56正确6.名称正确。7.ab#正确。#是类型说明符。8.MyName错误。变量名内不能有空格字符。9.“年龄”错误。这是字符串常量。10.学校$正确。$是类型说明符。2.4把下列数学表达式写成VB表达式。答案:1.1/(1+(1/(1+1/(x+y))))2.x*(x*(x*(a*x+b)+c)+d)+e3.Log(1+Abs((a+b)/(a-b))^10)4.Sqrt(1+3.14159/2*Cos(48*3.14159/180))5.1/Tan((1-x*x)/(1+x*x))或者Cos((1-x*x)/(1+x*x))/Sin((1-x*x)/(1+x*x))6.Log10(a*a+a*b+b*b)2.5写出下列函数的值。答案:1.-123462.12343.12.344.1234.575.1006.27.Visual8.09.$$$2.6写出下列表达式的值。答案:1.42.03.abc123abc4.True5.True6.True7.False8.True4 2.7用关系表达式或逻辑表达式表示下列条件。答案:1.iModj=02.n0OrYearMod400=02.8问答题略2.9阅读下列程序,写出执行结果1.答案:-3VisualBasicFalse0.75x=12.342.答案:3E81.000000E0031,000.00x=1000,y=12.34,x*y=123402.10编程题1.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dimx%,i%,j%,k%Write("请输入x的值:")x=ReadLine()i=x100j=(x-i*100)/10k=x-i*100-j*10WriteLine("{0}{1}{2}",k,j,i)"或WriteLine("{0}",100*k+10*j+i)EndSubEndModule2.解答:ImportsSystem.ConsoleModuleModule1SubMain()DimxAsSingle,yAsSingle,bAsBooleanWrite("请输入x的值:")x=ReadLine()Write("请输入y的值:")4 y=ReadLine()b=(-2<=x)And(x<=2)And(-2<=y)And(y<=2)WriteLine("{0}",b)EndSubEndModule第3章程序流程控制3.1填空题1.答案:s=3.14159*r*r2.答案:Command2.Text="退出"3.答案:IfiMod2=0Thenprintx4.答案:Ifx>0Thens1=s1+xElses2=s2+x5.答案:Ifx>0Theny=2*x+1ElseIfx=0Theny=0Elsey=2*x-16.答案:Ifa=bThenPrint“aisequaltob”End7.答案:IfAsc(ch)>=97AndAsc(ch)<=122ThenPrint“Yes”ElsePrint“No”EndIf8.答案:这些常数中的某一个9.答案:这个范围内的值10.答案:Is后的关系11.答案:循环体、循环条件、结束循环条件12.答案:DoWhile…Loop语句13.答案:For…Next14.答案:循环条件15.答案:ExitFor3.2选择题1.答案:d2.答案:d3.答案:d4.答案:c5.答案:d4 6.答案:c7.答案:c8.答案:c9.答案:c10.答案:a、c11.答案:b12.答案:c13.答案:b3.3问答题略3.4阅读下列程序,写出执行结果1.答案:a=-1b=3c=2S=2w=0t=02.答案:x=2y=4x=8y=9x=4y=8x=15y=2263.答案:t=9454.答案:x=105y=3845.答案:s=366.答案:1020213031327.答案:s=363.5编程题1.解答ImportsSystem.ConsoleModuleModule136 SubMain()Dimscore!Write("请输入score的值:")score=ReadLine()Ifscore>=85ThenWriteLine("Verygood!")ElseIfscore>=60ThenWriteLine("Good!")ElseWriteLine("Nogood!")EndIfEndSubEndModule2.解答ImportsSystem.ConsoleImportsSystem.MathModuleModule1SubMain()Dima!,b!,c!,disc!,x1!,x2!,realpart!,imagpart!Conste!=0.000001Write("请输入a的值:"):a=ReadLine()Write("请输入b的值:"):b=ReadLine()Write("请输入c的值:"):c=ReadLine()IfAbs(a)<=eThenWriteLine("方程不是一个二次方程!")Elsedisc=b^2-4*a*cIfAbs(disc)<=eThenWriteLine("方程有两个相同的实根:x1=x2={0}",-b/(2*a))ElseIfdisc>0.000001Thenx1=(-b+Sqrt(disc))/(2*a)x2=(-b-Sqrt(disc))/(2*a)WriteLine("方程有两个实根:x1={0}x2={1}",x1,x2)ElseIfdisc=1Andx<=5ThenSelectCasexCaseIs<2y=3*x-5CaseIs<4y=2*Cos(x)+1CaseIs<=5y=Sqrt(1+x*x)EndSelectElsey=x*x-4*x+5EndIfWriteLine("x={0}y={1}",x,y)EndSubEndModule4.解答ImportsSystem.ConsoleModuleModule1SubMain()Dimr!,f$Constpi!=3.14159265Write("请输入圆的半径r:"):r=ReadLine()Ifr>=0ThenWrite("请输入运算标志C(计算周长),A(计算面积),B(两者都计算):")f=ReadLine()f=UCase(f)SelectCasef36 Case"C"WriteLine("半径r={0}y=圆周长={1}",r,2*r*pi)Case"A"WriteLine("半径r={0}y=圆面积={1}",r,r*r*pi)Case"B"WriteLine("半径r={0}y=圆周长={1}",r,2*r*pi)WriteLine("半径r={0}y=圆面积={1}",r,r*r*pi)CaseElseWriteLine("输入的运算标志错!")EndSelectElseWriteLine("半径不能是负数!")EndIfEndSubEndModule5.解答ImportsSystem.ConsoleModuleModule1SubMain()Dimn%,s&n=0:s=0Whiles<=1000n=n+1s=s+n^2EndWhileWriteLine("满足1^2+2^2+…-+n^2>1000的最小n值为:{0}",n)EndSubEndModule6.解答(1)用DoWhile…Loop语句ImportsSystem.ConsoleModuleModule1SubMain()Dima!,s!Write("请输入a的值:"):a=ReadLine()DoWhilea>=0s=s+aWrite("请输入a的值:"):a=ReadLine()Loop36 WriteLine("输入的正实数之和为:{0}",s)EndSubEndModule(2)用DoUntil…Loop语句ImportsSystem.ConsoleModuleModule1SubMain()Dima!,s!Write("请输入a的值:"):a=ReadLine()DoUntila<0s=s+aWrite("请输入a的值:"):a=ReadLine()LoopWriteLine("输入的正实数之和为:{0}",s)EndSubEndModule7.解答ImportsSystem.ConsoleImportsSystem.MathModuleModule1SubMain()Dimi&,s#,term#i=1s=0Doterm=1/(i*i)s=s+termi=i+1LoopWhileterm>=0.00000001WriteLine("圆周率的近似值为:{0}",Sqrt(6*s))EndSubEndModule8.解答ImportsSystem.ConsoleImportsSystem.MathModuleModule1SubMain()Dimx0!,x1!x1=036 Dox0=x1x1=x0-(x0^5-3*x0^2+2*x0+1)/(5*x0^4-6*x0+2)LoopUntilAbs(x1-x0)<0.00001WriteLine("方程的根为:{0}",x1)EndSubEndModule9.解答ImportsSystem.ConsoleModuleModule1SubMain()Dimi%,s!,sign%sign=1:s=0Fori=1To100s=s+sign*1/isign=-signNextiWriteLine("s的值为:{0}",s)EndSubEndModule10.解答法1:ImportsSystem.ConsoleModuleModule1SubMain()Dimi%,a%,b%,c%WriteLine("100--999之间的水仙花数为:")Fori=100To999a=i100b=(i-a*100)10第4章复合型数据类型4.1填空题1.答案:10,0,92.答案:Dima(5,6)AsInteger3.答案:四舍五入4.答案:Read和ReadLine,Write和WriteLine5.答案:[Preserve]6.答案:数据成员36 7.答案:Add8.答案:枚举类型名.成员名4.2选择题1.答案:c2.答案:c3.答案:d4.答案:b5.答案:d6.答案:c7.答案:b8.答案:d9.答案:d10.答案:d11.答案:c12.答案:d13.答案:a4.3问答题略4.4阅读下列程序,写出执行结果1.答案:f(0)=1f(1)=1f(2)=2f(3)=3f(4)=5f(5)=8f(6)=13f(7)=21f(8)=34f(9)=55f(10)=892.答案:s(0)=6s(1)=5s(2)=4s(3)=3s(4)=2s(5)=13.答案:1243694.答案:1  1  1  1  12  1  1  1  13  2  1  1  14  3  2  1  15  4  3  2  14.5编程题1.解答:ImportsSystem.ConsoleImportsSystem.MathModuleModule1SubMain()Dimsum1!,sum2!,ave!,dev!,n%,i%n=InputBox("请输入学生人数:")Dims!(n)Fori=1Tons(i)=InputBox("请输入第"&Str(i)&"个学生成绩:")36 Nextisum1=0:sum2=0Fori=1Tonsum1=sum1+s(i)Nextiave=sum1/nFori=1Tonsum2=sum2+(s(i)-ave)^2Nextidev=Sqrt(sum2/n)WriteLine("平均成绩:{0}",ave)WriteLine("均方差:{0}",dev)EndSubEndModule2.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dimi%,num%,p%,a%(11)Randomize()"随机数生成器初始化Fori=1To10a(i)=Int(Rnd()*100+1)NextiWriteLine("插入前数组的元素值:")Fori=1To10"显示插入前数组的元素值Write("{0}",a(i))NextiWriteLine()p=InputBox("请输入插入位置:")num=InputBox("请输入插入数据:")Fori=10TopStep-1a(i+1)=a(i)Nextia(p)=numWriteLine("插入后数组的元素值:")Fori=1To11"显示插入后数组的元素值Write("{0}",a(i))NextiWriteLine()36 EndSubEndModule3.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dima(20),i%,max%Randomize()Fori=1To20a(i)=Int((90*Rnd()+10))NextiWriteLine("产生的随机数为:")Fori=1To20Write("a({0})={1}",i,a(i))IfiMod4=0ThenWriteLine()NextiWriteLine()max=a(1)Fori=2To20Ifa(i)>maxThenmax=a(i)NextiWriteLine("最大值为:{0}",max)WriteLine("最大值所在数组元素的下标为:")Fori=1To20Ifa(i)=maxThenWrite("{0}",i)NextiWriteLine()EndSubEndModule4.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dima()AsSingle={1,2,7,8},b()AsSingle={3,4,8,8,9,10,12,12},c%(11)Dimi%,j%,k%i=0:j=0:k=0Whilei<4Andj<8Ifa(i)>b(j)Thenc(k)=b(j):k=k+1:j=j+1"比较a和b中的元素,把较大的元素移到36 Else"c中,直到其中一个数组搬空为止c(k)=a(i):k=k+1:i=i+1EndIfEndWhileWhilei<4c(k)=a(i):i=i+1:k=k+1"把a中剩余的元素搬到c中EndWhileWhilej<8c(k)=b(j):j=j+1:k=k+1"把b中剩余的元素搬到c中EndWhileWriteLine("合并后的升序数组C:")Fori=0To11Write("{0}",c(i))NextiWriteLine()EndSubEndModule5.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dimi%,j%,m%,n%,sum!,ave!,max!,min!m=InputBox("请输入矩阵的行数:")n=InputBox("请输入矩阵的列数:")Dima!(m,n)WriteLine("输入的矩阵为:")Fori=1TomForj=1Tona(i,j)=InputBox("输入第"&Str(i)&"行"&"第"&Str(j)&"列元素:")Write("{0}",a(i,j))NextjWriteLine()Nextisum=0Fori=1TomForj=1Tonsum=sum+a(i,j)"求和NextjNexti36 ave=sum/(m*n)"求平均值max=a(1,1)Fori=1TomForj=1TonIfa(i,j)>maxThenmax=a(i,j)"求最大值NextjNextimin=a(1,1)Fori=1TomForj=1TonIfa(i,j)maxThenmax=s(i).ScoreNextiWriteLine("最高分数:{0}",max)WriteLine("分数最高者:")Fori=1TonIfs(i).score=maxThenWriteLine("{0,8}",s(i).name)EndIfNexti36 EndSubEndModule第5章过程5.1填空题1.答案:传值参数、引用参数2.答案:相同或一致3.答案:整个应用程序所有模块4.答案:该模块5.答案:作用域6.答案:全局级过程或项目级过程7.答案:该过程8.答案:该模块。9.答案:整个应用程序或整个项目5.2选择题1.答案:d2.答案:c3.答案:c4.答案:c5.答案:a6.答案:d7.答案:b5.3问答题略5.4阅读程序,写出输出结果。1.答案:******************2.答案:max=4803.答案:a=5b=-5x=10y=5a=5b=104.答案:sum=555.答案:10303020306.答案:x=1y=1x=1y=2x=1y=336 5.5编程题1解答:ImportsSystem.ConsoleModuleModule1SubMain()Dimm&,n&,cmn#,c1&,c2&,c3&Write("n=")n=ReadLine()Write("m=")m=ReadLine()Callfac(m,c1):Callfac(n,c2):Callfac(m-n,c3)cmn=c1/(c2*c3)WriteLine("cmn={0}",cmn)EndSubPrivateSubfac(ByValk&,ByReff&)Dimt&,i&t=1Fori=1Tokt=t*iNextif=tEndSubEndModule2.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dima!,b!,c!,m#Write("a=")a=ReadLine()Write("b=")b=ReadLine()Write("c=")c=ReadLine()m=max(a,b,c)/(max(a+b,b,c)*max(a,b,b+c))WriteLine("m={0}",m)EndSubPrivateFunctionmax(ByValx!,ByValy!,ByValz!)AsSingleDimma!36 Ifx>yThenma=xElsema=yIfz>maThenma=zReturnmaEndFunctionEndModule3.ImportsSystem.ConsoleImportsSystem.MathModuleModule1SubMain()Dimx!,y!Write("x=")x=ReadLine()Write("y=")y=ReadLine()WriteLine("g={0}",g(x,y))EndSubPrivateFunctionf(ByValt!)AsSinglef=(1+Exp(-t))/(1+Exp(t))EndFunctionPrivateFunctiong(ByValx!,ByValy!)AsSingleIfx<=yTheng=f(x+y)/(f(x)+f(y))Elseg=f(x-y)/(f(x)+f(y))EndIfEndFunctionEndModule4.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dimi%,n%n=10Dima%(n)Randomize()"随机数生成器初始化Fori=1Tona(i)=Int(Rnd()*100+1)NextiCalls(a,n)"调用过程显示数组a的元素值36 "在指定位置插入一个数组元素Dimnum%,p%n=n+1ReDimPreservea(n)Write("num=")num=ReadLine()Write("p=")p=ReadLine()Fori=nTopStep-1a(i)=a(i-1)Nextia(p)=numCalls(a,n)"调用过程显示数组元素值"删除指定位置的数组元素Write("p=")p=ReadLine()Fori=pTon-1a(i)=a(i+1)Nextin=n-1ReDimPreservea(n)Calls(a,n)"调用过程显示数组a的元素值EndSubPrivateSubs(ByVala()AsInteger,ByValnAsInteger)Dimi%Fori=1Ton"显示数组a的元素值WriteLine("a({0})={1}",i,a(i))NextiEndSubEndModule5.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dimi%,m%,n%,p%Dima%()={1,2,7,8,9}"初始化数组aDimb%()={3,4,8,8,9,10,12,12}"初始化数组bDimc%()={1,5,5,6,8}"初始化数组c36 m=UBound(a)n=UBound(b)p=UBound(c)WriteLine("m={0}",m)Dimd%(m+n+2)Callgsort(a,b,d)Dime%(m+n+p+3)Callgsort(c,d,e)Fori=0Tom+n+p+2"显示数组e的元素值Write("e({0})={1}",i,e(i))NextiWriteLine()EndSubPrivateSubgsort(ByValx%(),ByValy%(),ByValz%())Dimi%,j%,k%,n1%,n2%i=0:j=0:k=0n1=UBound(x):n2=UBound(y)Whilei<=n1Andj<=n2Ifx(i)>y(j)Thenz(k)=y(j):k=k+1:j=j+1"比较x和y中的元素,把较大的元素移到z中,直到其中一个数组搬空为止Elsez(k)=x(i):k=k+1:i=i+1EndIfEndWhileWhilei<=n1z(k)=x(i):i=i+1:k=k+1"把x中剩余的元素搬到z中EndWhileWhilej<=n2z(k)=y(j):j=j+1:k=k+1"把y中剩余的元素搬到z中EndWhileEndSubEndModule6.解答:ImportsSystem.ConsoleModuleModule1SubMain()36 Dimnumber&Write("number=")number=ReadLine()WriteLine("输入的整数为:{0}",number)Write("输出的结果为:")Callrev(number)WriteLine()EndSubPrivateSubrev(ByValnum&)Write("{0}",numMod10)num=num10Ifnum<>0ThenCallrev(num)EndSubEndModule7.解答:ImportsSystem.ConsoleModuleModule1SubMain()Dima%,b%Write("a=")a=ReadLine()Write("b=")b=ReadLine()WriteLine("a和b的最大公约数为:{0}",gcd(a,b))EndSubPrivateFunctiongcd(ByVala%,ByValb%)AsIntegerDimg%Ifb=0Theng=aElseg=gcd(b,aModb)EndIfgcd=gEndFunctionEndModule第6章面向对象程序设计基础6.1填空题1.答案:特征、性质36 2.答案:对象3.答案:特殊过程4.答案:类中、类外5.答案:Public6.答案:Return7.答案:WithEvents8.答案:自动调用9.答案:一、多10.答案:构造6.2选择题1.答案:d2.答案:c3.答案:c4.答案:c5.答案:b、c6.答案:a7.答案:b8.答案:a6.3问答题略6.4阅读下列程序,写出执行结果1.答案:x=10y=51051552.答案:点(3,2)到点(3,10)的距离是:83.答案:调用基类B的构造函数x=10调用基类B的构造函数x=30调用派生类D的构造函数y=806.5编程题1.解答:ImportsSystem.ConsoleModuleModule1PublicClassBoxPrivatelengthAsSinglePrivatewidthAsSinglePrivateheightAsSingle36 PublicSubNew(ByVall!,ByValw!,ByValh!)length=l:width=w:height=hEndSubPublicFunctionvolume()Returnlength*width*heightEndFunctionEndClassSubMain()Dimbox1AsNewBox(1,3,5)WriteLine("volume={0}",box1.volume())Dimbox2AsNewBox(2,4,6)WriteLine("volume={0}",box2.volume())EndSubEndModule2.解答:ImportsSystem.ConsoleModuleModule1PublicClassrectangleProtectedlengthAsSingleProtectedwidthAsSinglePublicSubNew(ByVallAsSingle,ByValwAsSingle)length=l:width=wEndSubPublicFunctiongetlength()ReturnlengthEndFunctionPublicFunctiongetwidth()ReturnwidthEndFunctionPublicFunctionarea()Returnlength*widthEndFunctionEndClassPublicClassrectangularInheritsrectanglePrivateheightAsSinglePublicSubNew(ByVallAsSingle,ByValwAsSingle,ByValhAsSingle)MyBase.New(l,w)height=h36 EndSubPublicFunctiongetheight()ReturnheightEndFunctionPublicFunctionvolume()Returnlength*width*heightEndFunctionEndClassSubMain()Dimobj1AsNewrectangle(3,5)WriteLine("length={0}",obj1.getlength())WriteLine("width={0}",obj1.getwidth())WriteLine("area={0}",obj1.area())Dimobj2AsNewrectangular(5,8,10)WriteLine("length={0}",obj2.getlength())WriteLine("width={0}",obj2.getwidth())WriteLine("height={0}",obj2.getheight())WriteLine("volume={0}",obj2.volume())EndSubEndModule第7章常用控件7.1填空题1.答案:界面设计、程序功能设计2.答案:控件、组件、组件3.答案:“属性”、程序代码4.答案:Control、所有5.答案:True6.答案:n=val(InputBox(“请输入一个求阶乘的数:”,“求数的阶乘”)7.答案:r=MsgBox(“退出本系统?”,4+32+0,“提示信息”)8.答案:UrI属性、Navigate方法9.答案:Text10.答案:True11.答案:发生改变12.答案:PictureBox1.Image=Image.FromFile("D:samplediannt.jpg")13.答案:AutoSize14.答案:Select15.答案:先后顺序16.答案:Button1.Enabled=True36 17.答案:False18.答案:True19.答案:False20.答案:0、Count-121.答案:ListBox1.Items.Remove(ListBox1.SelectedItem)22.答案:ComboBox1.Items.Add(“计算机学院”)23.答案:LargeChange24.答案:Minimum25.答案:Tick26.答案:5007.2选择题1.答案:d2.答案:b3答案:c4.答案:a5.答案:c6.答案:d7.答案:d8.答案:b9.答案:d10.答案:c11.答案:c12.答案:a13.答案:a14.答案:d15.答案:c16.答案:c17.答案:b18.答案:d19.答案:a20.答案:c21.答案:d22.答案:a7.3问答题略7.4编程题1.解答:(1)界面设计和属性设置在窗体上建立两个标签、两个文本框和一个命令按钮。窗体和窗体上控件的主要属性设置如下表所示。属性设置控件名称属性名属性值Form1Text英文单词翻译为中文单词Label1Text英文Label2Text中文TextBox1Text空串TextBox2Text空串Button1Text翻译(2)程序代码PublicClassForm1PrivateSubForm1_Load(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesMe.LoadTextBox1.Text="":TextBox2.Text=""EndSubPrivateSubButton1_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesButton1.ClickSelectCaseLCase(Trim(TextBox1.Text))Case"china"TextBox2.Text="中国"36 Case"france"TextBox2.Text="法国"Case"england"TextBox2.Text="英国"Case"america"TextBox2.Text="美国"Case"india"TextBox2.Text="印度"CaseElseTextBox2.Text="找不到该单词"EndSelectEndSubPrivateSubTextBox1_Click(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesTextBox1.ClickTextBox1.Text="":TextBox2.Text=""EndSubEndClass(3)运行情况上机运行程序后,屏幕出现用户界面。把鼠标移到TextBox1文本框并单击,然后输入英文国家名,例如,China。英文国家名输入后,单击标题为“翻译”的命令按钮Button1,系统执行相应的Click事件过程。翻译结果在TextBox2显示。若继续输入英文国家名,可以单击TextBox1文本框,这时可以再次输入。单击Button1系统执行Button1_Click事件过程完成翻译。2.解答:(1)界面设计和属性设置在窗体上建立一个文本框。窗体和文本框的主要属性设置如下表所示。属性设置控件名称属性名属性值Form1Text判别算术表达式中的圆括号是否配对TextBox1Text空串(2)程序代码PublicClassForm1DimnAsIntegerPrivateSubTextBox1_Click(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesTextBox1.ClickTextBox1.Text=""n=036 EndSubPrivateSubTextBox1_KeyDown(ByValsenderAsObject,_ByValeAsSystem.Windows.Forms.KeyEventArgs)HandlesTextBox1.KeyDownIfe.KeyValue=8Then"e.KeyValue为按键的Asc码n=n+1ElseIfe.KeyValue=9Thenn=n-1EndIfIfe.KeyValue=13ThenIfn=0ThenMsgBox("左右圆括号配对!")ElseIfn>0ThenMsgBox("左圆括号多于右圆括号!")ElseMsgBox("右圆括号多于左圆括号!")EndIfEndIfEndSub(3)运行情况上机运行程序后,屏幕出现用户界面。焦点在TextBox1文本框上,输入算术表达式,例如,((1+2)*8-5),然后按回车键。每按一个键,系统都执行TextBox1_KeyDown事件过程。由消息框显示配对信息。若继续判别另一个算术表达式的左右圆括号是否配对,可以单击TextBox1文本框,系统执行TextBox1_KeyDown事件过程。这时可以再次输入算术表达式和按回车键。3.解答:(1)界面设计和属性设置在窗体上建立两个标签、两个文本框和两个分组框。一个分组框包含两个单选按钮,另一个分组框包含三个单选按钮。窗体和窗体上控件的主要属性设置如下表所示。属性设置控件名称属性名属性值Form1Text计算三角函数的值Label1Text输入Label2Text输出TextBox1Text空串TextBox2Text空串GroupBox1Text输入选择RadioButton1Text角度RadioButton2Text弧度GroupBox2Text函数选择RadioButton3Text正弦RadioButton4Text余弦RadioButton5Text正切(2)程序代码36 ImportsSystem.MathPublicClassForm1ConstPi=3.14159265PrivateSubForm1_Load(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesMe.LoadRadioButton1.Checked=TrueRadioButton3.Checked=TrueTextBox1.Text="":TextBox2.Text=""EndSubPrivateSubTextBox1_Click(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesTextBox1.ClickTextBox1.Text="":TextBox2.Text=""EndSubPrivateSubTextBox1_TextChanged(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesTextBox1.TextChangedDimXAsSingleIf(RadioButton1.Checked)ThenX=Val(TextBox1.Text)*Pi/180ElseX=Val(TextBox1.Text)EndIfIf(RadioButton3.Checked)ThenTextBox2.Text=Sin(X)ElseIf(RadioButton4.Checked)ThenTextBox2.Text=Cos(X)ElseIf(RadioButton5.Checked)ThenTextBox2.Text=Tan(X)EndIfEndSubEndClass(3)运行情况上机运行程序后,屏幕出现用户界面。在文本框TextBox1输入角度,例如,90。系统执行TextBox1_TextChanged事件过程,结果在文本框TextBox2显示。单击标题为“弧度”的单选按钮和标题为“余弦”的单选按钮,并把鼠标移到文本框TextBox1中和单击,在文本框TextBox1输入弧度,例如,3.14159。系统执行TextBox1_TextChanged事件过程,结果在文本框TextBox2显示。4.解答:(1)界面设计和属性设置在窗体上建立两个文本框、一个列表框、一个组合框和两个命令按钮。窗体和窗体上控件的主要属性设置如下表所示。36 属性设置控件名称属性名属性值Form1Text输入和显示职工个人信息Button1Text显示Button2Text退出(2)程序代码PublicClassForm1PrivateSubForm1_Load(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesMyBase.LoadListBox1.Items.Add("计算机")ListBox1.Items.Add("信息")ListBox1.Items.Add("机械")ListBox1.Items.Add("建筑")ListBox1.Items.Add("材料")ListBox1.Items.Add("食品与轻化")ListBox1.Items.Add("外国语")ListBox1.Items.Add("交通")ComboBox1.Items.Add("教授)ComboBox1.Items.Add("副教授")ComboBox1.Items.Add("讲师")ComboBox1.Items.Add("助教")EndSubPrivateSubButton1_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesButton1.ClickTextBox2.Text="姓名:"&TextBox1.Text&"学院:"&ListBox1.Text&"职称:"&ComboBox1.TextEndSubPrivateSubButton2_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesButton2.ClickClose()EndSubEndClass(3)运行情况上机运行程序后,在文本框输入姓名,在列表框选择学院名称,在组合框选择职称名称,信息输入后,单击“显示”按钮,在文本框显示该职工个人信息。单击标题为“退出”按钮,系统执行相应的Click事件过程,结束程序的执行。5.解答:(1)界面设计和属性设置36 在窗体上建立一个图像框、一个计时器和一个命令按钮。窗体和窗体上控件的主要属性设置如下表所示。属性设置控件名称属性名属性值Form1Text使图片从左至右移动PictureBox1Image一幅图片(在程序中装入)Timer1IntervalEnabled1000(在程序中给定)TrueButton1Text结束(2)程序代码PublicClassForm1PrivateSubForm1_Load(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesMe.LoadPictureBox1.Image=Image.FromFile("D:PictureFACE03.ico")Timer1.Interval=1000"设定Timer事件每隔1000毫秒发生一次PictureBox1.Left=0EndSubPrivateSubTimer1_Tick(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesTimer1.TickIfPictureBox1.LeftNothingline=F2.ReadLine()i=i+1sun=sun+Val(line)LoopTextBox1.Text=Str(sun/i)F2.Close()"关闭与输出流类对象F2关联的文件EndSubPrivateSubButton2_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesButton2.ClickMe.Close()EndSubEndClass(3)运行情况单击标题为“求平均成绩”的命令按钮,系统执行相应的Click事件过程求平均成绩,并在TextBox1上显示。单击标题为“关闭窗体”命令按钮,系统关闭窗体,结束程序的执行。36 3.解答:(1)界面设计和属性设置在窗体上建立五个标签、五个文本框和两个命令按钮。窗体和窗体上控件的主要属性设置如表所示。控件名称属性名属性值Form1Text建立职工通讯录文件Label1Text编号Label2Text姓名Label3Text电话号码Label4Text邮政编码Label5Text住址TextBox1、TextBox2、TextBox3Text空串TextBox4、TextBox5Text空串Button1Text添加记录Button2Text退出(2)程序代码ImportsSystem.IOStructuretxrDimnumAsStringDimnameAsStringDimtelAsStringDimpostcAsStringDimaddrAsStringEndStructurePublicClassForm1PrivateSubButton1_Click(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesButton1.ClickDimFSAsNewFileStream("D:txrf.dat",FileMode.Append,_FileAccess.Write)DimBWAsNewBinaryWriter(FS)DimzgrAstxrWithzgr.num=Trim(TextBox1.Text).name=Trim(TextBox2.Text).tel=Trim(TextBox3.Text).postc=Trim(TextBox4.Text).addr=Trim(TextBox5.Text)EndWithWithzgrBW.Write(.num)36 BW.Write(.name)BW.Write(.tel)BW.Write(.postc)BW.Write(.addr)EndWithWithzgrTextBox1.Text=""TextBox2.Text=""TextBox3.Text=""TextBox4.Text=""TextBox5.Text=""EndWithBW.Close()FS.Close()EndSubPrivateSubButton2_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesButton2.ClickMe.Close()EndSubEndClass(3)运行情况上机运行程序后,把鼠标分别移到各个文本框并单击,然后输入某个职工记录相应的数据。一个职工记录相应的数据输入后,单击标题为“添加记录”的命令按钮,系统执行相应的Click事件过程,把该记录添加到职工通讯录文件“D:txrf.rec”中。重复上述操作,直到所有记录输入完为止。单击标题为“退出”命令按钮,系统执行相应的Click事件过程,关闭窗体,结束程序的执行。4.解答:(1)界面设计和属性设置在窗体上建立五个标签、五个文本框和两个命令按钮。窗体和窗体上控件的主要属性设置如表所示。控件名称属性名属性值Form1Text游览职工通讯录文件Label1Text编号Label2Text姓名Label3Text电话号码Label4Text邮政编码Label5Text住址TextBox1、TextBox2、TextBox3Text空串TextBox4、TextBox5Text空串Button1Text游览记录36 Button2Text退出(2)程序代码ImportsSystem.IOStructuretxrDimnumAsStringDimnameAsStringDimtelAsStringDimpostcAsStringDimaddrAsStringEndStructurePublicClassForm1PrivateSubButton1_Click(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesButton1.ClickDimzgrAstxrDimFS1AsNewFileStream("D:txrf.dat",FileMode.Open,FileAccess.Read)DimBR1AsNewBinaryReader(FS1)WhileBR1.PeekChar()<>-1Withzgr.num=BR1.ReadString().name=BR1.ReadString().tel=BR1.ReadString().postc=BR1.ReadString().addr=BR1.ReadString()EndWithWithzgrTextBox1.Text=.numTextBox2.Text=.nameTextBox3.Text=.telTextBox4.Text=.postcTextBox5.Text=.addrEndWithMsgBox("浏览下一个!")EndWhileMsgBox("浏览完毕!")BR1.Close()FS1.Close()EndSubPrivateSubButton2_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesButton2.Click36 Me.Close()EndSubEndClass(3)运行情况上机运行程序后,单击标题为“游览记录”的命令按钮,系统执行相应的Click事件过程,把第一个记录的各个数据项分别显示在相应文本框上。重复上述操作,直到把所有记录游览完为止。单击标题为“退出”命令按钮,系统执行相应的Click事件过程,关闭窗体,结束程序的执行。5.(1)界面设计和属性设置在窗体上建立五个标签、五个文本框和两个命令按钮。窗体和窗体上控件的主要属性设置如表所示。控件名称属性名属性值Form1Text查找职工通讯录文件中记录Label1Text编号Label2Text姓名Label3Text电话号码Label4Text邮政编码Label5Text住址TextBox1、TextBox2、TextBox3Text空串TextBox4、TextBox5Text空串Button1Text查找记录Button2Text退出(2)程序代码ImportsSystem.IOStructuretxrDimnumAsStringDimnameAsStringDimtelAsStringDimpostcAsStringDimaddrAsStringEndStructurePublicClassForm1PrivateSubButton1_Click(ByValsenderAsObject,_ByValeAsSystem.EventArgs)HandlesButton1.ClickDimzgrAstxrDimFS1AsNewFileStream("D:txrf.dat",FileMode.Open,FileAccess.Read)DimBR1AsNewBinaryReader(FS1)WhileBR1.PeekChar()<>-1Withzgr36 .num=BR1.ReadString().name=BR1.ReadString().tel=BR1.ReadString().postc=BR1.ReadString().addr=BR1.ReadString()EndWithIfzgr.num=TextBox1.TextThenMsgBox("该职工记录找到了!")WithzgrTextBox1.Text=.numTextBox2.Text=.nameTextBox3.Text=.telTextBox4.Text=.postcTextBox5.Text=.addrEndWithGoTo10EndIfEndWhileMsgBox("该职工记录找不到!")10:BR1.Close()FS1.Close()EndSubPrivateSubButton2_Click(ByValsenderAsSystem.Object,_ByValeAsSystem.EventArgs)HandlesButton2.ClickMe.Close()EndSubEndClass(3)运行情况上机运行程序后,把鼠标移到文本框TextBox1并单击,然后输入需查找职工的编号。输入后,单击标题为“查找记录”的命令按钮,系统执行相应的Click事件过程。若找到相应的记录,则显示一个MsgBox对话框,报告“该职工记录找到了!”的信息。单击“确定”按钮,系统把该记录的各个数据项分别显示在相应文本框上。若找不到相应的记录,则显示另一个MsgBox对话框,报告“该职工记录找不到!”的信息。如果继续查找记录,则先把鼠标移到文本框TextBox1并单击,然后重复上述操作。单击标题为“退出”命令按钮,系统执行相应的Click事件过程,结束程序的执行。36'