河南大学VB程序设计课后习题参考答案.pdf
《河南大学VB程序设计课后习题参考答案.pdf》由会员分享,可在线阅读,更多相关《河南大学VB程序设计课后习题参考答案.pdf(46页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、河南大学VB程序设计课后习题参考答案(编码)2-1Private Sub Form_Click()CisEnd SubPrivate Sub Form_DblClick()FontSize=40FontName=”隶书”ForeColor=vbRedPrint”热烈庆祝”FontSize=60FontName=宋体ForeColor=vbGreenPrint”河南大学运动会召开”End Sub2-2Private Sub Command1_Click()Label 1.Move Width*Rnd,Height*RndEnd Sub2-3Private Sub Command1_Click()
2、Labell.Visible=TrueEnd SubPrivate Sub Command2_Click()Labell.Visible=FalseEnd Sub2-4Private Sub Timer1_Timer()Textl.Text=NowCaption=Textl.TextEnd Sub2-5Private Sub Timer1_Timer()If BackColor=vbRed ThenBackColor=vbYellowElseBackColor=vbRedEnd IfEnd Sub2-6Private Sub Timeri_Timer()If Labell.Left -Labe
3、ll.Height ThenLabell.Top=Labell.Top-100ElseLabell.Top=Forml.HeightEnd IfEnd Sub3-2Private Sub Form_Click()Dim n As IntegerRandomizen=lnt(90*Rnd)+10)Print nEnd Sub3-3Private Sub Timeri_Timer()CisPrint”河南大学环境与规划学院”FontSize=lnt(71*Rnd+10)End Sub3-4Private Sub Command1_Click()n=Textl.TextText2.Text=Hex(
4、Asc(Right(Text1.Text,1)End SubPrivate Sub Command2_Click()Textl.Text=Text2.Text=”Textl.SetFocusEnd Sub3-5Private Sub Command1_Click()Dim m As Datem=Textl.Textn=DateText2.Text=n-mEnd SubPrivate Sub Command2_Click()Textl.Text=Text2.Text=Textl.SetFocusEnd Sub3-6Dim b As StringDim n As StringDim m As St
5、ringPrivate Sub Command1_Click()m=Left(Text1,1)n=Right(Text1,1)b=Mid(Text1,2,1)Text2.Text=n&b&mEnd SubPrivate Sub Command2_Click()Textl.Text=Text2.Text=Textl.SetFocusEnd Sub3-7Private Sub Form_click()r=InputBox(请输入字符”)Print Left(r,1)&Mid(r,3,1)&Right(r,1)End Sub3-8Private Sub Timer1_Timer()Label 1 .
6、FontSize=Rnd*40+10Labell.BackColor=RGB(Rnd*256,Rnd*256,Rnd*256)Labell.ForeColor=QBColor(lnt(16*Rnd)End Sub3-10Private Sub Form_Click()r!=InputBox(请输入您的工资:)a=r100b=(r-100*a)50c=(r-100*a-b*50)10d=(r-1 0 0*a-b*5 0-c*1 0)5e=(r-100*a-b*50-c*10-d*5)2f=r-1 0 0*a-b*5 0-c*1 0-d*5-e*2Print”您的工资是:“&rPrint”100
7、元张数:n&aPrint”50 元张数:&bPrint”10 元张数:&cPrint”5 元张数:&dPrint”2 元张数:&ePrint 元张数:&fEnd Sub4-1Private Sub Command1_Click()Dim p As Single,r As Single,n As Singlep=Textlr=Text2n=Text3s=p*(1+r)A nMsgBox”您的本息是:&Round(s,2)End Sub4-2Private Sub Form_click()Dim max As Single,min As Singlea!=InputBox(请输入第一个实数”)b!
8、=InputBox(请输入第二个实数”)If a b ThenPrint a,bElsePrint b,aEnd IfEnd Sub4-3Private Sub Form_click()Cisa!=InputBox(请输入年份)If a Mod 4=0 And a Mod 100 0&a Mod 400=0ThenPrint”您刚刚输入的年份为闰年!”ElsePrint”您刚刚输入的年份不是闰年!”End IfEnd Sub4-4Private Sub Form_click()a!=lnputBox(a=H)b!=lnputBox(b=)c!=lnputBox(“c=)d!=b*b-4*a*c
9、If d=0 Thenm!=(-b+Sqr(d)/(2*a)n!=(-b-Sqr(d)/(2*a)Print”X1=;m,”X2=;nElser=(-b)/(2*a)i=Sqr(Abs(-d)/(2*a)Print X1=n;r&Abs(i)&i“,”二 X2=n;r&Abs(i)&i”End IfEnd Sub4-5Private Sub Command1_Click()Dim x!x=TextlIf x 60 ThenText2=重考!”Elself x 70 ThenText2=及格!Elself x 80 ThenText2=中等!”Elself x 90 ThenText2=良好!”
10、ElseText2=”优秀!”End IfEnd SubPrivate Sub Command2_Click()Textl=Text2=H,End Sub4-6Private Sub Command1_Click()Dim x!x=TextlSelect Case xCase Is 60Text2=重考!Case Is 70Text2=及格!”Case Is 80Text2=中等!”Case Is 90Text2=良好!Case ElseText2=”优秀!”End SelectEnd SubPrivate Sub Command2_Click()Textl=Text2=End Sub4-7D
11、im s As StringPrivate Sub Form_Click()s=InputBox(”请输入年龄”)If s 30 ThenPrint”您的年龄为”;s,7,”请参加长跑运动”Elself s 40 ThenPrint”您的年龄为”;请参加跳绳运动”Elself s 100Print”1-2+3-4+5-6+99-100=;sEnd Sub4-12Private Sub Form_Click()Dim n As IntegerDim m As IntegerDim s As Integerm%=InputBox。请输入正整数”阶乘。n%=InputBox。请输入正整数 n(n=m
12、),“阶乘”)For m=m To nt=1For i=1 To mt=t*iNext is=s+tNext mPrint m!+(m+1)!+.+n!=;sEnd Sub4-13Private Sub Form_click()Dim a%Dim b%Dim c%For a=1 To 20For b=1 To 20For c=1 To 20lfa*a +b*b =c*c ThenPrint a,b,cEnd IfNext cNext bNext aEnd Sub4-14Private Sub Form_click()For n=1 To 500For i=1 To n-1If n Mod i=
13、0 Then s=s+Next iIf s=n Then Print i;s=0Next nPrintEnd Sub4-15Private Sub Form_click()Dim i As IntegerDim n As Longn=1t=1Do While t 0.00001e=e+1i=i+1n=n*it=1 /nLoopPrint e 的近似值是;eEnd Sub51Private SubForm_Click()Dim i%,x(1 To 5)As StringFor i=LBound(x)To UBound(x)x(i)=lnputBox(”x(&i&”)”)Next iFor i=U
14、Bound(x)To LBound(x)Step-1Print x(i)Next iPrintEnd Sub5-2Private Sub Form_Click()Dim i%5 ss=Array(1,2,3,4,5,6,7,8,9,10)For i=0 To 9If s(i)Mod 3=0 ThenPrint s(i);iElsePrintnuEnd IfNext iPrintEnd Sub5-3Option Base 1Private Sub Command1_Click()Dim x()x=Array(1,2,3,4,5,6,7,8,9,10)t=x(1)For i=1 To 9x(i)=
15、x(i+1)Print x(i);Nextx(10)=tPrint x(i)End SubPrivate Sub Command2_Click()Dim x()x=Array(1,2,3,4,5,6,7,8,9,10)t=x(10)For i=9 To 1 Step-1x(i+1)=x(i)Next ix(1)=tFor i=1 To 10Print x(i);Next iEnd Sub5-4Private Sub Form_Click()Dim a(5,5)For i=1 To 5Sum=0For j=1 To 5a(i,j)=lnt(Rnd*51+10)Sum=Sum+a(i,j)Prin
16、t a(i,j);Next jPrint SumNext iPrintFor i=1 To 5For j=1 To 5If i=j Then Print a(i,j);Next jNext iPrintEnd Sub5-5Private Sub Form_Click()Dim a()As IntegerDim Max As Integer,iMax As Integer,jMax AsIntegerDim Min As Integer,iMin As Integer,jMin As IntegerM=InputBox。输入 M)N=lnputBox(输入 N)ReDima(M,N)For i=
17、1 To MFor j=1 To Na(i,j)=lnt(Rnd*900)+100Next jNext iFor i=1 To MFor j=1 To NPrint a(i,j);Next jPrintNext iMax=a(1,1):Min=a(1,1)For i=1 To MFor j=1 To NIf a(i,j)Max Then Max=a(i,j):(Max=i:jMax=jf a(i,j)Min Then Min=a(i,j):iMin=i:jMin=jNext jNext iPrint,Max=n;Max,niMax=H;iMax,MjMax=;jMaxPrint Min;Min
18、,”iMin=;iMin,njMin=H;jMinErase aEnd Sub5-6Private Sub Form_Click()n=lnputBox(,nH)ReDim a(n,n)For i=1 To nForj=1 To nIf i=j Thena(i,j)=1Elsea(i,j)=0End IfNext jNext iFor i=1 To nForj=1 To nPrint a(i,j);Next jPrintNext iErase aEnd Sub5-7Private Sub Form_Click()Dim x As Variantx=Array(1,2,3,4,5,6,7,8,9
19、,10)For i=1 To 10Print x(i);Next iPrintFor i=1 To 7x(i)=x(i+3)Print x(i);Next iPrintReDim Preserve x(i)x=Array(1,2,3,4,5,6,7)or i=1 To 7Print x(i);Next iPrintEnd Sub5-8Option Base 1Private Sub Command1_Click(lndex As Integer)Select Case IndexCase 1Text3=Val(Textl)+Val(Text2)Case 2Text3=Textl-Text2Ca
20、se 3Text3=Textl*Text2Case 4Text3=Textl/Text2End SelectEnd Sub6-1Private Sub Form_click()Dim x As SingleDim y As SingleDim z As Singlex=lnputBox(请输入圆柱体的半径”)y=lnputBox(请输入圆柱体的高度”)volume x,y,zPrint”圆柱体的体积为”;zEnd Sub6-2窗体模块Private Sub Form_click()Dim a!,b!,c!a=lnputBox(请输入圆柱体的半径”)b=InputBox。请输入圆柱体的高度”)c
21、=volume(a,b)Print”圆柱体的体积为”;cEnd Sub标准模块Function volume(r As Single,h As Single)As Singlevolume=3.14*r*r*hEnd Function6-3Private Sub Form_Click()Dim y%y=lnputBox(请输入一个整数”)Call week(y)End Sub6-4窗体模块Private Sub Form_click()Dim a As Integer,b As Stringa=lnputBox(请输入一个整数”)b=week(a)Print b标准模块Function wee
22、k(s As Integer)As StringSelect Case sCase 0week=星期 HCase 1week=星期一Case 2week=星期二”Case 3week=星期三Case 4week=星期四”Case 5week=星期五Case 6week=星期六Case ElseMsg Box”数据无效”End SelectEnd Function6-5窗体模块Private Sub Form_click()Dim n As Single,w As Stringn=InputBox(请输入一个正整数”)Select Case wCase judge=0Print”此数为偶数”Ca
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 河南大学 VB 程序设计 课后 习题 参考答案
限制150内