大学计算机VB程序设计教程课后答案Word下载.docx
《大学计算机VB程序设计教程课后答案Word下载.docx》由会员分享,可在线阅读,更多相关《大学计算机VB程序设计教程课后答案Word下载.docx(24页珍藏版)》请在冰豆网上搜索。
\picture\flower.wmf"
)
Command1.Visible=False
Command2.Visible=False
End
PrivateSubForm_DblClick()
"
Command1.Visible=True
Command2.Visible=True
第3章常用标准控件
1.C2.B3.C.4.D5.B
6.B7.A8.C9.B10.C
11.C12.A13.C14.B15.D
16.D17.C18.A19.D20.A21.B
三.编程及上机调试:
1.
PrivateSubCheck1_Click()
IfCheck1.Value=1Then
Text1.FontBold=True
Else
Text1.FontBold=False
EndIf
PrivateSubCheck2_Click()
IfCheck2.Value=1Then
Text1.FontItalic=True
Text1.FontItalic=False
PrivateSubCheck3_Click()
Text1.FontUnderline=True
Text1.FontUnderline=False
PrivateSubCommand1_Click()
Text1.Text="
"
2.
Text2.Text=List1.ListCount
List1.AddItemText1.Text
DimiAsInteger
i=List1.ListIndex
List1.RemoveItemi
Command3.Enabled=False
Text1.SetFocus
PrivateSubForm_Load()
PrivateSubList1_Click()
Command3.Enabled=True
第4章VB语言基础
1.A2.D3.D.4.A5.A
6.A7.C8.D9.C10.B
11.A12.D13.C14.A15.A
16.C17.D18.A19.B20.D
21.C22.A23.B24.C25.C
1.PrivateSubForm_Load()
DimxAsInteger,sAsString,dAsInteger
Randomize
x=Int(Rnd*9000+1000)
s=Trim(CStr(x))
d=Val(Right(s,1)+Mid(s,3,1)+Mid(s,2,1)+Left(s,1))
Show
Print"
产生的数;
;
x;
倒序数"
d
2.PrivateSubForm_KeyPress(KeyAsciiAsInteger)
输入字符:
Chr(KeyAscii),"
ASCII码为:
KeyAscii
Cls
3.PrivateSubForm_Click()
MsgBox"
在这里显示提示"
&
vbCrLf&
提示信息"
2+16,"
请确认"
或
PrivateSubForm_Click()
MsgBox"
+Chr(13)+"
vbAbortRetryIgnore_
+vbCritical,"
第5章程序控制结构
二.单选题
1.D2.C3.C.4.D.5.B
6.C7.A8.A9.D10.C
11.C12.C13.B14.B
四.编程及上机调试
1.PrivateSubForm_Click()
DimxAsInteger,yAsInteger
x=InputBox("
请输入一个数值"
Ifx>
20Then
y=x^2+3*x+2
ElseIfx>
=10Then
y=Sqr(3*x)-2
0Then
y=1/x+Abs(x)
EndIf
x="
x,"
y="
y
(2)SelectCase实现:
DimxAsInteger,yAsInteger
x=InputBox("
SelectCasex
CaseIs>
20
y=x^2+3*x+2
=10
y=Sqr(3*x)-2
0
y=1/x+Abs(x)
EndSelect
Print"
2.
DimaAsInteger,bAsInteger,cAsInteger
Fori=100To999
a=i\100
b=(i-a*100)\10
c=iMod10
Ifa^3+b^3+c^3=iThen
Printi;
k=k+1
IfkMod2=0ThenPrint
Nexti
3.
p=60:
r=0.014
Do
p=p*(1+r)
n=n+1
LoopUntilp>
=70
Printn;
年后世界人口达到"
p;
亿"
4.
DimsAsSingle,xAsInteger,tAsSingle,nAsInteger
x=Val(InputBox("
请输入x的值"
,2))
s=1
n=1
m=1
m=-m
t=m*n/x^(n-1)
IfAbs(t)<
0.00001ThenExitDo
s=s+t
Loop
Prints
第6章数组
二.单选题:
1.A2.A.3.A4.C5.D
6.D7.A8.D9.B10.B
四.编程及上机调试:
OptionBase1
Dima(10)AsInteger
DimiAsInteger,tAsInteger
数组的原始数据为:
Fori=1To10
a(i)=Int(11*Rnd)+10
Printa(i);
Print
变化后数组数据为:
Fori=1To5
t=a(i)
a(i)=a(10-i+1)
a(10-i+1)=t
OptionBase1
Dima(3,4)AsInteger,iAsInteger,jAsInteger,kAsInteger,pAsInteger
Randomize
Fori=1To3
Forj=1To4
a(i,j)=Int(90*Rnd+10)
Printa(i,j);
Nextj
Nexti
Max=a(1,1):
k=1:
p=1
Ifa(i,j)>
MaxThen
Max=a(i,j)
k=i
p=j
最大的数为第"
k&
行,第"
p&
列的数:
Max
3.
Dima(4,5)AsInteger'
在窗体声明段声明数组
DimiAsInteger,jAsInteger
PrivateSubcmdmatrix_Click()'
生成数组"
按钮
Fori=1To4
Forj=1To5
a(i,j)=Int(Rnd*10)'
一位的随机数
Picture1.Printa(i,j);
'
输出元素
Picture1.Print
PrivateSubcmdcol_Click()'
求列和"
DimcolsumAsInteger
txtcol.Text="
Forj=1To5'
列变量先循环
colsum=0
colsum=colsum+a(i,j)
txtcol.Text=txtcol.Text&
Str(colsum)
PrivateSubcmdrow_Click()'
求行和"
DimrowsumAsInteger
txtrow.Text="
Fori=1To4'
行变量先循环
rowsum=0
rowsum=rowsum+a(i,j)
txtrow.Text=txtrow.Text&
CStr(rowsum)&
vbCrLf
PrivateSubcmdclear_Click()'
清除"
Picture1.Cls
PrivateSubcmdexit_Click()'
结束"
4.OptionBase1
Dima()AsInteger,b()AsInteger,iAsInteger,jAsInteger,xAsInteger,yAsInteger
第一维上界"
DoWhileNotIsNumeric(x)
x=Int(InputBox("
))
y=InputBox("
第二维上界"
y=Int(InputBox("
ReDima(x,y)
原数组元素为:
Fori=1Tox
Forj=1Toy
a(i,j)=Int(90*Rnd)+10
转置后数组元素为:
Fori=1Toy
Forj=1Tox
Printa(j,i);
5.OptionBase1
Dima(10,10)AsInteger,iAsInteger,jAsInteger
Fori=1To10
Forj=1To10
Ifi=jOri+j=11Then
a(i,j)=0
Else
a(i,j)=1
6.OptionExplicit
DimiAsInteger,jAsInteger,nAsInteger,kAsInteger,a(11)AsInteger
j=1
Fori=3To21Step2
a(j)=i
Printa(j);
j=j+1
n=InputBox("
请输入一个数"
Ifn=a(i)Then
Forj=iTo10
a(j)=a(j+1)
Fori=1To9
7.OptionBase1
DimaAsVariant,kAsInteger,iAsInteger,jAsInteger
DimbAsVariant
b=Array(17,35,128,235,89,121,143,189,231,94)
a=Array(11.3,12.3,12#,11.8,12.6,11.6,12.8,11.8,12.4,12.1)
Fori=1To9'
对数组a的元素排序
Forj=i+1To10
Ifa(k)>
a(j)Thenk=j
Ifk<
>
iThen'
数组b的元素随数组a的元素一起变动
a(i)=a(k)
a(k)=t
t=b(i)
b(i)=b(k)
b(k)=t
按名字的排列顺序为:
IfLen(b(i))=2Thenb(i)="
0"
b(i)'
补上数组b中长度为2的编号前的"
第"
i&
名的号码为:
b(i)&
,成绩为:
a(i)
第7章过程
二、单选题
1.C2.D3.C4.D5.B
6.A7.B8.B9.C10.D
11.C12.D13.B14.B15.C
16.A17.B18.B
三、填空题
1.5251
2.411
835
3.135
1.PrivateSubCommand1_Click()
DimnAsInteger
Forn=100To1600Step500
n="
n;
时π的近似值是:
pi(n)
Nextn
PrivateFunctionpi(xAsInteger)AsSingle
DimsAsSingle,kAsInteger,mAsInteger
s=0
k=1
s=s+m/k
k=k+2
LoopWhilek<
=x
pi=4*s
EndFunction
2.PrivateSubCommand1_Click()
DimxAsInteger,iAsInteger
x=Val(Text1)
Ifprime(i)Andprime(x-i)Then
Label2=Str(x)&
是"
Str(i)&
和"
Str(x-i)&
两个素数之和"
ExitSub
PrivateFunctionprime(xAsInteger)AsBoolean
Fori=2ToInt(Sqr(x))
IfxModi=0Then
prime=False
ExitFunction
prime=True
3.OptionExplicit
DimiAsInteger
a(i)=Int(Rnd*90)+10
Text1=Text1+Str(a(i))
Callsort(a)
Text2=Text2+Str(a(i))
PrivateSubsort(a()AsInteger)
DimkAsInteger,iAsInteger,jAsInteger,tAsInteger
k=UBound(a)
Fori=1Tok-1
Forj=i+1Tok
Ifa(i)<
a(j)Then
a(i)=a(j)
a(j)=t
4.OptionExplicit
DimiAsInteger,jAsInteger,sAsInteger
Fori=2To1000
S=0
Forj=1Toi-1
IfImodj=0Thens=s+j
Ifs=iThenPrintI,
5.Publica(10)AsInteger
PublicSubsort(a()AsInteger)
DimiAsInteger,jAsInteger,tAsInteger
Fori=1ToUBound(a)-1
Forj=i+1ToUBound(a)
Ifa(i)>