大学VB程序设计课后习题参考答案编码Word文档下载推荐.docx
《大学VB程序设计课后习题参考答案编码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《大学VB程序设计课后习题参考答案编码Word文档下载推荐.docx(20页珍藏版)》请在冰豆网上搜索。
FontBold=True
欢迎来到"
河南大学"
PrivateSubCommand3_Click()
End
2-10
r=Text1.Text
Text2.Text=3.14*2*r
Text1.Text="
"
Text2.Text="
Text1.SetFocus
2-11
PrivateSubForm_Load()
河南大学欢迎您!
"
Text1.FontName="
Text1.FontSize=50
Text1.BackColor=vbYellow
Text1.ForeColor=vbBlue
2-12
DimsAsString
s=Text1.SelText
Text2.SelText=s
2-13
IfLabel1.Top>
-Label1.HeightThen
Label1.Top=Label1.Top-100
Label1.Top=Form1.Height
3-2
DimnAsInteger
Randomize
n=Int((90*Rnd)+10)
Printn
3-3
河南大学环境与规划学院"
FontSize=Int(71*Rnd+10)
3-4
n=Text1.Text
Text2.Text=Hex(Asc(Right(Text1.Text,1)))
3-5
DimmAsDate
m=Text1.Text
n=Date
Text2.Text=n-m
3-6
DimbAsString
DimnAsString
DimmAsString
m=Left(Text1,1)
n=Right(Text1,1)
b=Mid(Text1,2,1)
Text2.Text=n&
b&
m
3-7
PrivateSubForm_click()
r=InputBox("
请输入字符"
)
PrintLeft(r,1)&
Mid(r,3,1)&
Right(r,1)
3-8
Label1.FontSize=Rnd*40+10
Label1.BackColor=RGB(Rnd*256,Rnd*256,Rnd*256)
Label1.ForeColor=QBColor(Int(16*Rnd))
3-9
x=Shell("
notepad.exe"
1)
Shell"
mspaint.exe"
1
3-10
r!
=InputBox("
请输入您的工资:
a=r\100
b=(r-100*a)\50
c=(r-100*a-b*50)\10
d=(r-100*a-b*50-c*10)\5
e=(r-100*a-b*50-c*10-d*5)\2
f=r-100*a-b*50-c*10-d*5-e*2
您的工资是:
&
r
100元张数:
a
50元张数:
b
10元张数:
c
5元张数:
d
2元张数:
e
1元张数:
f
4-1
DimpAsSingle,rAsSingle,nAsSingle
p=Text1
r=Text2
n=Text3
s=p*(1+r)^n
MsgBox"
您的本息是:
Round(s,2)
4-2
DimmaxAsSingle,minAsSingle
a!
请输入第一个实数"
b!
请输入第二个实数"
Ifa>
bThen
Printa,b
Printb,a
EndIf
4-3
请输入年份"
IfaMod4=0AndaMod100<
>
0&
aMod400=0Then
您刚刚输入的年份为闰年!
您刚刚输入的年份不是闰年!
4-4
a="
b="
c!
c="
d!
=b*b-4*a*c
Ifd>
=0Then
m!
=(-b+Sqr(d))/(2*a)
n!
=(-b-Sqr(d))/(2*a)
X1="
;
m,"
"
"
X2="
n
r=(-b)/(2*a)
i=Sqr(Abs(-d))/(2*a)
X1="
r&
+"
Abs(i)&
i"
X2="
-"
4-5
Dimx!
x=Text1
Ifx<
60Then
Text2="
重考!
ElseIfx<
70Then
及格!
80Then
中等!
90Then
良好!
优秀!
Text1="
4-6
SelectCasex
CaseIs<
60
70
80
90
CaseElse
EndSelect
4-7
s=InputBox("
请输入年龄"
Ifs<
30Then
您的年龄为"
s,"
请参加长跑运动"
ElseIfs<
40Then
请参加跳绳运动"
50Then
请参加竞走运动"
请参加慢跑运动"
4-8
Forn=2To100Step2
Printn;
IfnMod20=0ThenPrint
Nextn
4-9
Forn=100To1000
IfnMod3=2AndnMod5=3AndnMod7=2ThenPrintn;
Print
4-10
m=0:
n=0
Do
r%=InputBox("
请输入学生成绩"
m=m+r
n=n+1
LoopUntilr=-1
学生平均成绩="
(m+1)/(n-1)
4-11
DimaAsInteger
DimsAsInteger
a=1
s=s+(-1)^(a+1)*a
a=a+1
LoopUntila>
100
1-2+3-4+5-6+…+99-100="
s
4-12
DimmAsInteger
m%=InputBox("
请输入正整数m(m>
=1)"
阶乘"
n%=InputBox("
请输入正整数n(n>
=m)"
Form=mTon
t=1
Fori=1Tom
t=t*i
Nexti
s=s+t
Nextm
m!
+(m+1)!
+…+n!
="
4-13
Dima%
Dimb%
Dimc%
Fora=1To20
Forb=1To20
Forc=1To20
Ifa*a+b*b=c*cThen
Printa,b,c
Nextc
Nextb
Nexta
4-14
Forn=1To500
Fori=1Ton-1
IfnModi=0Thens=s+i
Ifs=nThenPrinti;
s=0
4-15
DimiAsInteger
DimnAsLong
n=1
DoWhilet>
0.00001
e=e+t
i=i+1
n=n*i
t=1/n
Loop
e的近似值是"
5-2
Dimi%,s
s=Array(1,2,3,4,5,6,7,8,9,10)
Fori=0To9
Ifs(i)Mod3=0Then
Prints(i);
i
5-3
OptionBase1
Dimx()
x=Array(1,2,3,4,5,6,7,8,9,10)
t=x
(1)
Fori=1To9
x(i)=x(i+1)
Printx(i);
Next
x(10)=t
Printx(i)
t=x(10)
Fori=9To1Step-1
x(i+1)=x(i)
x
(1)=t
Fori=1To10
5-4
Dima(5,5)
Fori=1To5
Sum=0
Forj=1To5
a(i,j)=Int(Rnd*51+10)
Sum=Sum+a(i,j)
Printa(i,j);
Nextj
PrintSum
Ifi=jThenPrinta(i,j);
5-5
Dima()AsInteger
DimMaxAsInteger,iMaxAsInteger,jMaxAsInteger
DimMinAsInteger,iMinAsInteger,jMinAsInteger
M=InputBox("
输入M"
N=InputBox("
输入N"
ReDima(M,N)
Fori=1ToM
Forj=1ToN
a(i,j)=Int(Rnd*900)+100
Max=a(1,1):
Min=a(1,1)
Ifa(i,j)>
MaxThenMax=a(i,j):
iMax=i:
jMax=j
fa(i,j)<
MinThenMin=a(i,j):
iMin=i:
jMin=j
Max="
Max,"
iMax="
iMax,"
jMax="
jMax
Min="
Min,"
iMin="
iMin,"
jMin="
jMin
Erasea
5-6
n=InputBox("
n"
ReDima(n,n)
Fori=1Ton
Forj=1Ton
Ifi=jThen
a(i,j)=1
a(i,j)=0
Erasea
5-7
DimxAsVariant
Fori=1To7
x(i)=x(i+3)
ReDimPreservex(i)
x=Array(1,2,3,4,5,6,7)
ori=1To7
5-8
PrivateSubCommand1_Click(IndexAsInteger)
SelectCaseIndex
Case1
Text3=Val(Text1)+Val(Text2)
Case2
Text3=Text1-Text2
Case3
Text3=Text1*Text2
Case4
Text3=Text1/Text2
6-1
DimxAsSingle
DimyAsSingle
DimzAsSingle
x=InputBox("
请输入圆柱体的半径"
y=InputBox("
请输入圆柱体的高度"
volumex,y,z
圆柱体的体积为"
z
6-2
窗体模块
Dima!
b!
c!
a=InputBox("
b=InputBox("
c=volume(a,b)
标准模块
Functionvolume(rAsSingle,hAsSingle)AsSingle
volume=3.14*r*r*h
EndFunction
6-3
Dimy%
请输入一个整数"
Callweek(y)
6-4
DimaAsInteger,bAsString
b=week(a)
Printb
Functionweek(sAsInteger)AsString
SelectCases
Case0
week="
星期日"
星期一"
星期二"
星期三"
星期四"
Case5
星期五"
Case6
星期六"
数据无效"
6-5
PrivateSubForm_cl