河南大学10级VB程序设计课后习题参考答案.doc

上传人:wux****ua 文档编号:7972467 上传时间:2020-03-26 格式:DOC 页数:49 大小:58.50KB
返回 下载 相关 举报
河南大学10级VB程序设计课后习题参考答案.doc_第1页
第1页 / 共49页
河南大学10级VB程序设计课后习题参考答案.doc_第2页
第2页 / 共49页
河南大学10级VB程序设计课后习题参考答案.doc_第3页
第3页 / 共49页
点击查看更多>>
资源描述
河南大学09级VB程序设计课后习题参考答案(编码)2-1PrivateSubForm_Click()ClsEndSubPrivateSubForm_DblClick()FontSize=40FontName=隶书ForeColor=vbRedPrint热烈庆祝FontSize=60FontName=宋体ForeColor=vbGreenPrint河南大学运动会召开EndSub2-2PrivateSubCommand1_Click()Label1.MoveWidth*Rnd,Height*RndEndSub2-3PrivateSubCommand1_Click()Label1.Visible=TrueEndSubPrivateSubCommand2_Click()Label1.Visible=FalseEndSub2-4PrivateSubTimer1_Timer()Text1.Text=NowCaption=Text1.TextEndSub2-5PrivateSubTimer1_Timer()IfBackColor=vbRedThenBackColor=vbYellowElseBackColor=vbRedEndIfEndSub2-6PrivateSubTimer1_Timer()IfLabel1.Left-Label1.HeightThenLabel1.Top=Label1.Top-100ElseLabel1.Top=Form1.HeightEndIfEndSub3-2PrivateSubForm_Click()DimnAsIntegerRandomizen=Int(90*Rnd)+10)PrintnEndSub3-3PrivateSubTimer1_Timer()ClsPrint河南大学环境与规划学院FontSize=Int(71*Rnd+10)EndSub3-4PrivateSubCommand1_Click()n=Text1.TextText2.Text=Hex(Asc(Right(Text1.Text,1)EndSubPrivateSubCommand2_Click()Text1.Text=Text2.Text=Text1.SetFocusEndSub3-5PrivateSubCommand1_Click()DimmAsDatem=Text1.Textn=DateText2.Text=n-mEndSubPrivateSubCommand2_Click()Text1.Text=Text2.Text=Text1.SetFocusEndSub3-6DimbAsStringDimnAsStringDimmAsStringPrivateSubCommand1_Click()m=Left(Text1,1)n=Right(Text1,1)b=Mid(Text1,2,1)Text2.Text=n&b&mEndSubPrivateSubCommand2_Click()Text1.Text=Text2.Text=Text1.SetFocusEndSub3-7PrivateSubForm_click()r=InputBox(请输入字符)PrintLeft(r,1)&Mid(r,3,1)&Right(r,1)EndSub3-8PrivateSubTimer1_Timer()Label1.FontSize=Rnd*40+10Label1.BackColor=RGB(Rnd*256,Rnd*256,Rnd*256)Label1.ForeColor=QBColor(Int(16*Rnd)EndSub3-10PrivateSubForm_Click()r!=InputBox(请输入您的工资:)a=r100b=(r-100*a)50c=(r-100*a-b*50)10d=(r-100*a-b*50-c*10)5e=(r-100*a-b*50-c*10-d*5)2f=r-100*a-b*50-c*10-d*5-e*2Print您的工资是:&rPrint100元张数:&aPrint50元张数:&bPrint10元张数:&cPrint5元张数:&dPrint2元张数:&ePrint1元张数:&fEndSub4-1PrivateSubCommand1_Click()DimpAsSingle,rAsSingle,nAsSinglep=Text1r=Text2n=Text3s=p*(1+r)nMsgBox您的本息是:&Round(s,2)EndSub4-2PrivateSubForm_click()DimmaxAsSingle,minAsSinglea!=InputBox(请输入第一个实数)b!=InputBox(请输入第二个实数)IfabThenPrinta,bElsePrintb,aEndIfEndSub4-3PrivateSubForm_click()Clsa!=InputBox(请输入年份)IfaMod4=0AndaMod1000&aMod400=0ThenPrint您刚刚输入的年份为闰年!ElsePrint您刚刚输入的年份不是闰年!EndIfEndSub4-4PrivateSubForm_click()a!=InputBox(a=)b!=InputBox(b=)c!=InputBox(c=)d!=b*b-4*a*cIfd=0Thenm!=(-b+Sqr(d)/(2*a)n!=(-b-Sqr(d)/(2*a)PrintX1=;m,X2=;nElser=(-b)/(2*a)i=Sqr(Abs(-d)/(2*a)PrintX1=;r&+&Abs(i)&i,X2=;r&-&Abs(i)&iEndIfEndSub4-4(2)Dim a, b, c, d As Singlea = InputBox(输入数据)b = InputBox(输入数据)c = InputBox(输入数据)d = b 2 - 4 * a * cIf d = 0 ThenX1 = (-b + Sqr(d) / (2 * a)X2 = (-b - Sqr(d) / (2 * a)Print x1= & X1 & & x2= & X2Elsex3 = -b / (2 * a) & + & Sqr(-d) / (2 * a) & ix4 = -b / (2 * a) & - & Sqr(-d) / (2 * a) & iPrint x3= & x3 & & x4= & x4End If4-5PrivateSubCommand1_Click()Dimx!x=Text1Ifx60ThenText2=重考!ElseIfx70ThenText2=及格!ElseIfx80ThenText2=中等!ElseIfx90ThenText2=良好!ElseText2=优秀!EndIfEndSubPrivateSubCommand2_Click()Text1=Text2=EndSub4-6PrivateSubCommand1_Click()Dimx!x=Text1SelectCasexCaseIs60Text2=重考!CaseIs70Text2=及格!CaseIs80Text2=中等!CaseIs90Text2=良好!CaseElseText2=优秀!EndSelectEndSubPrivateSubCommand2_Click()Text1=Text2=EndSub4-7DimsAsStringPrivateSubForm_Click()s=InputBox(请输入年龄)Ifs30ThenPrint您的年龄为;s,请参加长跑运动ElseIfs40ThenPrint您的年龄为;s,请参加跳绳运动ElseIfs100Print1-2+3-4+5-6+99-100=;sEndSub4-12PrivateSubForm_Click()DimnAsIntegerDimmAsIntegerDimsAsIntegerm%=InputBox(请输入正整数m(m=1),阶乘)n%=InputBox(请输入正整数n(n=m),阶乘)Form=mTont=1Fori=1Tomt=t*iNextis=s+tNextmPrintm!+(m+1)!+n!=;sEndSub4-13PrivateSubForm_click()Dima%Dimb%Dimc%Fora=1To20Forb=1To20Forc=1To20Ifa*a+b*b=c*cThenPrinta,b,cEndIfNextcNextbNextaEndSub4-14PrivateSubForm_click()Forn=1To500Fori=1Ton-1IfnModi=0Thens=s+iNextiIfs=nThenPrinti;s=0NextnPrintEndSub4-15PrivateSubForm_click()DimiAsIntegerDimnAsLongn=1t=1DoWhilet0.00001e=e+ti=i+1n=n*it=1/nLoopPrinte的近似值是;eEndSub51Private Sub Form_Click()Dim i%, x(1 To 5) As StringFor i = LBound(x) To UBound(x)x(i) = InputBox( x ( & i & ) )Next iFor i = UBound(x) To LBound(x) Step -1Print x(i)Next iPrintEnd Sub5-2PrivateSubForm_Click()Dimi%,ss=Array(1,2,3,4,5,6,7,8,9,10)Fori=0To9Ifs(i)Mod3=0ThenPrints(i);iElsePrintEndIfNextiPrintEndSub5-3OptionBase1PrivateSubCommand1_Click()Dimx()x=Array(1,2,3,4,5,6,7,8,9,10)t=x(1)Fori=1To9x(i)=x(i+1)Printx(i);Nextx(10)=tPrintx(i)EndSubPrivateSubCommand2_Click()Dimx()x=Array(1,2,3,4,5,6,7,8,9,10)t=x(10)Fori=9To1Step-1x(i+1)=x(i)Nextix(1)=tFori=1To10Printx(i);NextiEndSub5-4PrivateSubForm_Click()Dima(5,5)Fori=1To5Sum=0Forj=1To5a(i,j)=Int(Rnd*51+10)Sum=Sum+a(i,j)Printa(i,j);NextjPrintSumNextiPrintFori=1To5Forj=1To5Ifi=jThenPrinta(i,j);NextjNextiPrintEndSub5-5PrivateSubForm_Click()Dima()AsIntegerDimMaxAsInteger,iMaxAsInteger,jMaxAsIntegerDimMinAsInteger,iMinAsInteger,jMinAsIntegerM=InputBox(输入M)N=InputBox(输入N)ReDima(M,N)Fori=1ToMForj=1ToNa(i,j)=Int(Rnd*900)+100NextjNextiFori=1ToMForj=1ToNPrinta(i,j);NextjPrintNextiMax=a(1,1):Min=a(1,1)Fori=1ToMForj=1ToNIfa(i,j)MaxThenMax=a(i,j):iMax=i:jMax=jfa(i,j)MinThenMin=a(i,j):iMin=i:jMin=jNextjNextiPrintMax=;Max,iMax=;iMax,jMax=;jMaxPrintMin=;Min,iMin=;iMin,jMin=;jMinEraseaEndSub5-6PrivateSubForm_Click()n=InputBox(n)ReDima(n,n)Fori=1TonForj=1TonIfi=jThena(i,j)=1Elsea(i,j)=0EndIfNextjNextiFori=1TonForj=1TonPrinta(i,j);NextjPrintNextiEraseaEndSub5-7PrivateSubForm_Click()DimxAsVariantx=Array(1,2,3,4,5,6,7,8,9,10)Fori=1To10Printx(i);NextiPrintFori=1To7x(i)=x(i+3)Printx(i);NextiPrintReDimPreservex(i)x=Array(1,2,3,4,5,6,7)ori=1To7Printx(i);NextiPrintEndSub5-8OptionBase1PrivateSubCommand1_Click(IndexAsInteger)SelectCaseIndexCase1Text3=Val(Text1)+Val(Text2)Case2Text3=Text1-Text2Case3Text3=Text1*Text2Case4Text3=Text1/Text2EndSelectEndSub6-1PrivateSubForm_click()DimxAsSingleDimyAsSingleDimzAsSinglex=InputBox(请输入圆柱体的半径)y=InputBox(请输入圆柱体的高度)volumex,y,zPrint圆柱体的体积为;zEndSub6-2窗体模块PrivateSubForm_click()Dima!,b!,c!a=InputBox(请输入圆柱体的半径)b=InputBox(请输入圆柱体的高度)c=volume(a,b)Print圆柱体的体积为;cEndSub标准模块Functionvolume(rAsSingle,hAsSingle)AsSinglevolume=3.14*r*r*hEndFunction6-3PrivateSubForm_Click()Dimy%y=InputBox(请输入一个整数)Callweek(y)EndSub6-4窗体模块PrivateSubForm_click()DimaAsInteger,bAsStringa=InputBox(请输入一个整数)b=week(a)Printb标准模块Functionweek(sAsInteger)AsStringSelectCasesCase0week=星期日Case1week=星期一Case2week=星期二Case3week=星期三Case4week=星期四Case5week=星期五Case6week=星期六CaseElseMsgBox数据无效EndSelectEndFunction6-5窗体模块PrivateSubForm_click()DimnAsSingle,wAsStringn=InputBox(请输入一个正整数)SelectCasewCasejudge=0Print此数为偶数CaseElsePrint此数为奇数PrintwEndSelectEndSub标准模块Functionw(nAsSingle)AsStringw=n2SelectCasewCasew=0Print此数为偶数CaseElsePrint此数为奇数EndFunction6-7SublenUL(ByValsAsString,U%,L%)DimiAsIntegerFori=1ToLen(s)SelectCaseMid(s,i,1)CaseAToZU=U+1CaseaTozL=L+1EndSelectNextiEndSubPrivateSubCommand1_Click()DimU%,L%CalllenUL(Text1,U,L)Text2=UText3=LEndSubPrivateSubCommand2_Click()Text1=Text2=Text3=Text1.SetFocusEndSub7-1PrivateSubCommand1_Click()Image1.Picture=LoadPicture(c:图片picture5.JPG)EndSubPrivateSubCommand2_Click()Image1.Picture=LoadPicture(c:图片picture3.JPG)EndSubPrivateSubCommand3_Click()Image1.Picture=LoadPicture(c:图片picture4.JPG)EndSub7-2PrivateSubCommand1_Click()StaticaAsIntegera=a+1IfaMod20ThenImage1.Picture=LoadPicture(c:图片p2.JPG)Image2.Picture=LoadPicture(c:图片p1.JPG)ElseImage1.Picture=LoadPicture(c:图片p1.JPG)Image2.Picture=LoadPicture(c:图片p2.JPG)EndIfEndSubPrivateSubForm_Load()Image1.Picture=LoadPicture(c:图片p1.JPG)Image2.Picture=LoadPicture(c:图片p2.JPG)EndSub7-3PrivateSubTimer1_Timer()Form1.Picture=Image3.PictureImage3.Picture=Image2.PictureImage2.Picture=Image1.PictureImage1.Picture=Form1.PictureEndSub7-4PrivateSubForm_Load()Timer1.Enabled=FalseEndSubPrivateSubTimer1_Timer()IfImage2.Top=-Image2.HeightThenImage2.Top=Image2.Top-100ElseImage2.Top=-Image2.HeightEndIfEndSub7-5PrivateSubForm_Load()HScroll1.Min=0HScroll1.Max=Image1.WidthImage1.Width=0EndSubPrivateSubHScroll1_Scroll()Image1.Width=HScroll1Label1=当前图片宽度:&HScroll1.ValueEndSub7-6PrivateSubCommand1_Click()Fori=ProgressBar1.MinToProgressBar1.MaxProgressBar1.Value=i(Forj=1To20000Nextj)(延时)NextiEndSub7-7PrivateSubCommand1_Click()a=IIf(Option1,男,女)b=IIf(Option3,硕士,博士)c=IIf(Check1,音乐,)d=IIf(Check2,演讲,)e=IIf(Check3,体育,)f=IIf(Check4,集邮,)Text2=姓名:&Text1.Text&,&性别:&a&,&学历:&b&,&特长:&c&,&d&,&e&,&fEndSubPrivateSubCommand2_Click()Text1=Text2=Text1.SetFocusEndSub7-8PrivateSubForm_Load()Combo1.AddItem河南省Combo1.AddItem开封市Combo1.AddItem河南大学Combo1.AddItem金明校区Combo1.AddItem环境与规划学院Combo1.AddItem09级Combo1.AddItem地理科学专业Combo1.AddItem刘彬Combo1.AddItem毕业于Combo1.AddItem湖南省Combo1.AddItem衡山县Combo1.AddItem第二中学Combo1.AddItem218班EndSubPrivateSubCombo1_Click()List1.AddItemCombo1.TextEndSubPrivateSubList1_DblClick()List1.RemoveItemList1.ListIndexEndSub8-1DimxAsSingle,yAsSinglePrivateSubPt1_Click()Pt1.Scale(0,100)-(100,0)Pt1.DrawWidth=2Forx=0To100Step0.02Pt1.PSet(x,2),vbRedNextxFory=0To100Step0.02Pt1.PSet(2,y),vbRedNextyPt1.CurrentX=2Pt1.CurrentY=5Pt1.Print(0,0)EndSub8-2PrivateSubP1_Click()P1.Scale(0,100)-(100,0)P1.FillStyle=7P1.DrawWidth=5P1.FillColor=vbGreenP1.Line(10,90)-(90,10),vbRed,BEndSub8-3PrivateSubForm_click()Scale(-100,100)-(100,-100)Line(-100,0)-(100,0)Line(0,-100)-(0,100)CurrentX=2CurrentY=6Print(0,0)EndSub8-4PrivateSubForm_click()Scale(-100,100)-(100,-100)Line(-100,0)-(100,0)Line(0,-100)-(0,100)Forx=-100To100Step0.02y=10*Sin(x)-10*Cos(2*x)PSet(x,y),vbRedNextxEndSub8-7PrivateSubForm_Click()Timer1.Enabled=TrueEndSubPrivateSubTimer1_Timer()RandomizeScale(-120,120)-(120,-120)DrawWidth=2Ifr100Thenr=r+2Forr=0To100Circle(0,0),r,RGB(255*Rnd,255*Rnd,255*Rnd)NextrEndIfEndSub9-1PrivateSubText1_KeyPress(KAsInteger)K=K+3EndSub9-2PrivateSubText1_KeyPress(KAsInteger)SelectCaseKCase48To57K=KCaseElseK=0EndSelectEndSub9-6PrivateSubCommand1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)MousePointer=5EndSubPrivateSubText1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)MousePointer=11EndSubPrivateSubPicture1_Click()MouseIcon=Picture1.MouseIconPicture1.MouseIcon=Image1.MouseIconImage1.MouseIcon=Form1.MouseIconEndSub9-7SubForm_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)IfShift=vbCtrlMaskAndButton=vbLeftButtonThenPrintCtrl+左键+移动IfShift=vbAltMaskAndButton=vbRightButtonThenPrintAlt+右键+移动EndSubSubForm_MouseUp(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)ClsEndSub9-8SubPicture1_MouseMove(ButtonAsInteger,ShiftAsInteger,XAsSingle,YAsSingle)IfButton=vbLeftButtonThenPicture1.PrintStr(X)+,+Str(Y)BackColor=RGB(Rnd*256,Rnd*256,Rnd*256)EndSub10-1PrivateSubCommand1_Click()Opend:data1.txtForOutputAs#1Write#1,601,杨大昌;4550Write#1,603,李文圣;3886Write#1,605,张燕;2235Close#1EndSubPrivateSubCommand2_Click()Opend:data1.txtForInputAs#2DoWhileNotEOF(2)Input#2,X1,X2,x3PrintX1,X2,x3LoopCloseEndSub10-2PrivateSubCommand1_Click()Opend:data1.txtForAppendAs#3Write#3,Text1,Text2,Text3Text1=Text2=Text3=CloseEndSubPrivateSubCommand2_Click()CloseEndEndSub10-5PrivateSubForm_Click()DimsumAsLongForn=1To100Step2sum=sum+nNextnPrintsumEndSubPrivateSubForm_Load()Opend:data5.txtForOutputAs#1Forn=1To100Step1Print#1,n;NextnCloseEndSub10-6PrivateSubForm_Click()DimsumAsIntegerForn=10To100Step10sum=sum+nNextPrintsumEndSubPrivateSubForm_Load()Opend:data6.datForRandomAs#1Forn=1To100Put#1,nNextEndSub11-1PrivateSubCommand1_Click()CommonDialog1.Action=3Text1.BackColor=CommonDialog1.ColorEndSubPrivateSubCommand2_Click()CommonDialog1.Flags=263CommonDialog1.Action=4Text1.FontSize=CommonDialog1.FontSizeText1.FontName=CommonDialog1.FontNameText1.FontBold=CommonDialog1.FontBoldText1.FontStrikethru=CommonDialog1.FontStrikethruText1.ForeColor=CommonDialog1.ColorText1.FontUnderline=CommonDialog1.FontUnderlineEndSubPrivateSubCommand3_Click()CommonDialog1.Action=2EndSub11-2PrivateSubCommand1_Click()CD1.InitDir=C:DocumentsandSettingsAdministrator桌面CD1.Filter=图片|*.jpg|文本文件|*.txtCD1.ShowOpenIfCD1.FilterIndex=1ThenImage1.Picture=LoadPicture(CD1.FileName)ElseOpenCD1.FileNameForInputAs#1DoWhileNotEOF(1)LineInput#1,nText1=Text1+n+vbNewLineLoopEndIfEndSub113Private Sub Form_Load()Text1.Text = 河南大学首页Text1.FontName = 黑体Text1.FontSize = 20End SubPrivate Sub Form_Resize()Text1.Left = 50Text1.Top = 50Text1.Width = Width - 500Text1.Height = Height - 1000End SubPrivate Sub mnublue_Click()Text1.ForeColor = vbBlueEnd SubPrivate Sub mnuclear_Click()Text1.Text = End SubPrivate Sub mnugreen_Click()Text1.ForeColor = vbGreenEnd SubPrivate Sub mnured_Click()Text1.ForeColor = vbRedEnd Sub11-4PrivateSubForm_Resize()Text1.Left=50Text1.Top=50Text1.Width=Width-2000Text1.Height=Height-5000EndSubPrivateSubmnuName_Click(IndexAsInteger)SelectCaseIndexCase5Text1.FontName=宋体Case10Text1.FontName=黑体Case15Text1.FontName=隶书EndSelectEndSub11-5Private Sub mnuinput_Click()Dim a As Integera = InputBox(输入整数)If a 0 Then MsgBox (输入无效)Label4.Caption = aEnd SubPrivate Sub mnuoct_Click()Dim a As Integera = InputBox(输入整数)If a 0 Then MsgBox (输入无效)Label5.Caption = Oct(a)End SubPrivate Sub mnuhex_Click()Dim a As Integera = InputBox(输入整数)If a 0 Then MsgBox (输入无效)Label6.Caption = Hex(a)End Sub11-6PrivateSubForm_Load()Text1.Width=WidthText1.Height
展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 图纸专区 > 考试试卷


copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!