vb高教版龚沛曾主编课后实验题答案.docx
- 文档编号:25662896
- 上传时间:2023-06-11
- 格式:DOCX
- 页数:59
- 大小:24.12KB
vb高教版龚沛曾主编课后实验题答案.docx
《vb高教版龚沛曾主编课后实验题答案.docx》由会员分享,可在线阅读,更多相关《vb高教版龚沛曾主编课后实验题答案.docx(59页珍藏版)》请在冰豆网上搜索。
vb高教版龚沛曾主编课后实验题答案
A.1
PrivateSubCommand1_Click()
Label3=Text1
EndSub
A.2
PrivateSubForm_Load()
Timer1.Interval=0
EndSub
PrivateSubCommand1_Click() '自动
Timer1.Interval=200
EndSub
PrivateSubCommand2_Click() '手动
Timer1.Interval=0
CallMyMove
EndSub
PrivateSubTimer1_Timer()
CallMyMove
EndSub
SubMyMove()
Label1.MoveLabel1.Left-50
IfLabel1.Left<0ThenLabel1.Left=Form1.Width
EndSub
A.3
PrivateSubForm_Click()
Text1=Val(Text1)+1
EndSub
PrivateSubForm_Load()
Text1=0
EndSub
A.4
PrivateSubForm_Click()
Caption="单击窗体,改变图片"
Picture=LoadPicture(App.Path+"\n_015.bmp")
Print"欢迎使用VB"
EndSub
PrivateSubForm_DblClick()
Cls
Caption="双击窗体,卸去图片"
Picture=LoadPicture("") '
EndSub
PrivateSubForm_Load()
Caption="装入窗体"
Picture=LoadPicture(App.Path+"\n_016.bmp")
Print"装入图"
EndSub
PrivateSubForm_Resize() '该事件的作用窗体始终与图一样大
'Caption="窗体大小不变"
'Form1.Width=260*16 '260是Tongji-2.bmp图的宽度,象素单位
'Form1.Height=260*16+200 '260是图的高度,象素单位,200是窗体的标题栏高度
EndSub
A.5
SubCommand1_Click()
Text1.FontName="隶书"
Text1.FontSize=25
EndSub
SubCommand2_Click()
Text2.Text=Text1.SelText
Text2.FontName=Text1.FontName
Text2.FontSize=Text1.FontSize
EndSub
B.1
PrivateSubCommand1_Click()
Text2=Format(5/9*(Val(Text1)-32),"0.00")
EndSub
PrivateSubCommand2_Click()
Text1=Format(9/5*Val(Text2)+32,"0.00")
EndSub
或
PrivateSubCommand1_Click()
Dimf!
c!
'声明两个变量
f=Val(Text1)
c=5/9*(f-32)
Text2=Format(c,"0.00") '保留两位小数
EndSub
PrivateSubCommand2_Click()
Dimff!
cc!
'声明两个变量
cc=Val(Text2)
ff=9/5*cc+32
Text1=Format(ff,"0.00") '保留两位小数
EndSub
B.2
PrivateSubCommand1_Click()
Label2=Format(Val(Text1)*Val(Text1)*3.14,"0.00")
EndSub
PrivateSubCommand2_Click()
Label3=Format(Val(Text1)*3.14*2,"0.00")
EndSub
PrivateSubText1_LostFocus()
IfNotIsNumeric(Text1.Text)Then
MsgBox"输入有非数字字符,请重新输入",,"警告"
Text1.Text=""
Text1.SetFocus
EndIf
EndSub
或
PrivateSubCommand1_Click()
Label2=Format(Val(Text1)*Val(Text1)*3.14,"0.00")
EndSub
PrivateSubCommand2_Click()
Label3=Format(Val(Text1)*3.14*2,"0.00")
EndSub
PrivateSubText1_KeyPress(KeyAsciiAsInteger)
IfKeyAscii=13Then
IfNotIsNumeric(Text1.Text)Then
Text1.Text=""
EndIf
EndIf
EndSub
B.3
PrivateSubCommand1_Click()
n=Int(Log
(2)/Log(1.008)+1)
Label1=n&"年后人数超过26亿"
EndSub
B.4
PrivateSubCommand1_Click()
Dimx,dx,cd
x=Text1.Text
dx=UCase(x)
cd=Len(x)
Print"大写字母为:
";dx
Print"字符串长度为:
";cd
EndSub
B.5
PrivateSubCommand1_Click()
Text1=Int(Rnd*900+100)
EndSub
PrivateSubCommand2_Click()
Dimx%,x1%,x2%,x3%
x=Val(Text1)
x1=xMod10 '分离出的个位数
x2=(xMod100)\10 '分离出的十位数
x3=x\100 '分离出的百位数
Label1=x1*100+x2*10+x3
EndSub
B.6
PrivateSubForm_Click()
Label1=Left(Text1,11)
Label2=Mid(Text1,12,6)
Label3=Right(Text1,5)
EndSub
B.7
PrivateSubCommand1_Click()
Fori=1To5
PrintTab(15-i*2);String(2*i-1,"★");Spc(18-4*(i-1));String(2*i-1,"★")
Nexti
EndSub
PrivateSubCommand2_Click()
Cls
EndSub
进一步要求:
PrivateSubCommand1_Click()
Fori=1To5
PrintTab(15-i*2);String(2*i-1,"★");String(10-(2*i-1),"☆");String(2*i-1,"★")
Nexti
EndSub
PrivateSubCommand2_Click()
Cls
EndSub
B.8
PrivateSubForm_Click()
x=Val(InputBox("输入一正实数","计算",0))
pf=Format(x*x,"0.000")
pfg=Format(Sqr(x),"0.000")
lf=Format(x*x*x,"0.000")
lfg=Format(x^(1/3),"0.000")
Print"平方为:
";pf;Space(5);"平方根为:
";pfg;Space(5);"立方为:
";lf;Space(5);"立方根为:
";lfg
EndSub
C.1
PrivateSubForm_Click()
Dimx!
y!
x=Val(InputBox("输入x的值"))
Ifx<1000Then
y=x
ElseIfx<2000Then
y=0.9*x
ElseIfx<3000Then
y=0.8*x
Else
y=0.7*x
EndIf
Printy
EndSub
C.2
PrivateSubForm_Click()
Dimx!
y!
x=Val(InputBox("输入上网时间"))
Ifx<10Then
y=30
ElseIfx<50Then
y=30+2.5*(x-10)
Else
y=30+2.5*40+2*(x-50)
EndIf
Ify>150Then
y=150
EndIf
Printy
EndSub
C.3
PrivateSubCommand1_Click()
Dimx!
y!
z!
x=InputBox("inputx")
y=InputBox("inputy")
z=InputBox("inputz")
Print" x y z"
Print"排序前";x;" ";y;" ";z
Ifx x=y: y=t Ifx x=z: z=t Ify y=z: z=t Print"排序后"&x&" "&y&" "&z EndSub PrivateSubCommand2_Click() Dimx! y! z! x=InputBox("inputx") y=InputBox("inputy") z=InputBox("inputz") Print" x y z" Print"排序前";x;" ";y;" ";z Ifx x=y: y=t Ify t=y: y=z: z=t Ifx t=x: x=y: y=t EndIf EndIf Print"排序后"&x&" "&y&" "&z EndSub C.4 Dima(3)AsInteger PrivateSubCommand1_Click() Picture1.Cls Fori=0To2 a(i)=Int(Rnd*100+200) Picture1.Printa(i) Nexti EndSub PrivateSubCommand2_Click() Picture2.Cls DimzAsInteger Fori=0To1 Ifa(i)>a(i+1)Then z=a(i+1) a(i+1)=a(i) a(i)=z EndIf Nexti Picture2.Printa(0) Picture2.Printa (1) Picture2.Printa (2) EndSub C.5 PrivateSubText2_LostFocus() Dimm%,n%,y% m=Val(Text1) n=Val(Text2) IfnMod2<>0Then MsgBox("脚数必定为偶数") Text2="" Text2.SetFocus Else y=n/2-m Ify<0Then MsgBox("脚数必须≥2倍的头数,请重新输入") Text2="" Text2.SetFocus Else x=n/2-m Label2=y Label3=m-y EndIf EndIf EndSub C.6 PrivateSubCommand1_Click() Dima! b! c! x1! x2! de! a=Text1 b=Text2 c=Text3 de=b*b-4*a*c t=2*a Ifde=0Then Text4=Format(-b/t,"0.00") Text5=Format(-b/t,"0.00") ElseIfde>0Then Text4=Format((-b+Sqr(de))/t,"0.00") Text5=Format((-b-Sqr(de))/t,"0.00") Else Text4=Format(-b/t,"0.00")&"+"&Format(Sqr(Abs(de))/t,"0.00")&"i" Text5=Format(-b/t,"0.00")&"-"&Format(Sqr(Abs(de))/t,"0.00")&"i" EndIf EndSub PrivateSubCommand2_Click() Text1="" Text2="" Text3="" Text4="" Text5="" EndSub C.7 PrivateSubText3_LostFocus() SelectCaseTrim(Text3) Case"+" Text4=Val(Text1)+Val(Text2) Case"-" Text4=Val(Text1)-Val(Text2) Case"*" Text4=Val(Text1)*Val(Text2) Case"/" IfVal(Text2)=0Then MsgBox"分母为零,重新输入" Text2="" Text2.SetFocus Else Text4=Val(Text1)/Val(Text2) EndIf EndSelect EndSub C.8 PrivateSubText1_LostFocus() SelectCaseTrim(Text1) Case1 Text2="Monday" Case2 Text2="Tuesday" Case3 Text2="Wednesday" Case4 Text2="Thursday" Case5 Text2="Friday" Case6 Text2="Saturday" Case7 Text2="Sunday" CaseIs>7,Is<1 MsgBox"数字为1~7,重新输入" Text1="" Text1.SetFocus EndSelect EndSub 或者 PrivateSubText1_LostFocus() IfText1>7OrText1<1Then MsgBox"数字为1~7,重新输入" Text1="" Text1.SetFocus Else Text2=Choose(Text1,"Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday") EndIf EndSub D.1 PrivateSubForm_Click() Fori=1To9 PrintTab(10-i);String(2*i-1,Trim(Str(i))) Nexti EndSub D.2 PrivateSubForm_Click() Fori=1To10Step1 PrintTab(i);String((20-2*i),Chr(64+i)) Nexti EndSub D.3 PrivateSubCommand1_Click() Dims! t! i& s=1 t=1 Fori=1To100000 t=t+i s=s+1/t If1/t<0.00001ThenExitFor Nexti Print"For结构";s,i;"项" EndSub D.4 PrivateSubCommand1_Click() Dimn&,pi#,i& n=InputBox("输入n值") pi=2 Fori=1Ton pi=pi*(2*i)/(2*i-1)*(2*i)/(2*i+1) Nexti Print"当n="&n&"时,pi=";pi EndSub D.5 PrivateSubForm_Click() Dims! t! i! a%,n% a=Int(Rnd*9+1) n=Int(Rnd*6+5) t=0: s=0 Print"a=";a,"n=";n Fori=1Ton t=t*10+a s=s+t Printt; Nexti Print Print"s=";s EndSub D.6 PrivateSubCommand1_Click() DimsAsInteger s=0 Fori=1To9 Forj=0To9 Fork=0To9 s=i*100+j*10+k Ifs=i^3+j^3+k^3Then Prints EndIf Nextk Nextj Nexti EndSub PrivateSubCommand3_Click() formd6.Hide main.Show EndSub D.7 PrivateSubCommand1_Click() Dima! x0! x1! a=27 x0=2 i=0 Do i=i+1 x1=2*x0/3+a/(3*x0*x0) IfAbs(x1-x0)<0.00001ThenExitDo x0=x1 Loop Printx1,i EndSub D.8 PrivateSubCommand1_Click() s=0 x0=0.01 Fori=1To30 s=s+x0 x0=x0*2 Nexti Prints EndSub D.9 PrivateSubCommand4_Click() Picture1.Cls Picture1.Print"x课安排在 ";"y课安排在 ";"z课安排在" Picture1.Print"" Forz=5To6 Forx=1Toz-2 ForY=x+1Toz-1 X1=Choose(Weekday(x),"周一","周二","周三","周四","周五","周六","周日") Y1=Choose(Weekday(Y),"周一","周二","周三","周四","周五","周六","周日") z1=Choose(Weekday(z),"周一","周二","周三","周四","周五","周六","周日") Picture1.Print"";X1;" ";Y1;" ";z1 NextY Nextx Nextz EndSub E.1 PrivateSubForm_Click() Dima(1To10)AsInteger Fori=1To10 a(i)=Int(Rnd*71+3
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- vb 高教 版龚沛曾 主编 课后 实验 答案
![提示](https://static.bdocx.com/images/bang_tan.gif)