第610章 VB课后参考答案Word文档格式.docx
《第610章 VB课后参考答案Word文档格式.docx》由会员分享,可在线阅读,更多相关《第610章 VB课后参考答案Word文档格式.docx(13页珍藏版)》请在冰豆网上搜索。
(3)number=number*10+m
四、程序阅读
1.a=9b=4
2.
(1)36
25
16
9
(2)
3.6
4.146
五、编写程序
1.
PublicFunctionfact(xAsInteger)AsSingle'
求x!
DimfAsSingle,iAsInteger
f=1
Fori=1Tox
f=f*i'
累积
Nexti
fact=f
EndFunction
PrivateSubForm_Click()
Dimn%,m%,y!
Do
m%=Val(InputBox("
m="
))
n%=Val(InputBox("
n="
LoopUntilm>
=nAndn>
=0
y=fact(m)/(fact(n)*fact(m-n))
Printy
EndSub
2privatesubInsertfun(a%(),y%)
Dimiasinteger,nasinteger
n=ubound(a)
Redimpreservea(n+1)
Fori=ubound(a)-1to0step-1
Ify<
a(i)then
a(i+1)=a(i)
Ifi=0thena(i)=y
Else
a(i+1)=y
exitfor
endif
nexti
3.'
判断是否为回文函数
PrivateFunctionJudge(strAsString)AsBoolean
DimiAsInteger
Judge=True'
假设为回文
Fori=1ToLen(str)\2'
依次判断对应位置的两个字符,只要有一组不等即不是回文
IfMid(str,i,1)<
>
Mid(str,Len(str)+1-i,1)Then
Judge=False
ExitFunction
EndIf
4.
Dimn%,x!
n=Val(InputBox("
x=Val(InputBox("
x="
Printfe(n,x)'
调用求值函数过程
'
求值函数过程
PublicFunctionfe(n%,x!
)AsSingle
DimiAsInteger,tAsSingle
fe=1:
t=1
Fori=1Ton
t=t*x/i'
t为通项
fe=fe+t
5.。
。
第7章习题参考答案
7
8
10
11
12
13
14
15
二、填空题
1.___Multiline_______
2.____Value______
3.___Selected______、____List______、____0______、___List1.ListCount-1____
4.下拉式列表框
5.___LargeChange_______、____Value______
6.Shift+Ctrl
7.KeyAscii=0
ifKeyAscii>
57ORKeyAscii<
48thenKeyAscii=0
三、程序填空
1.Label1.Font=Combo1.Text
Combo2.Text
Label1.FontBold=True
Label1.FontItalic=True
Label1.FontSize=Val(Combo3.Text)
2.List1.List(list1.ListIndex)
list1.RemoveItemList1.ListIndex
List1.AddItemList2.List(List2.ListIndex)
List2.RemoveItem
四、选择题
五、编程题
1.'
添加功能
PrivateSubcmdAdd_Click()
Dimi%
IfCombo1.Text="
"
ThenExitSub
Fori=0ToCombo1.ListCount-1'
逐个判断是否有与输入内容相同的项目
IfCombo1.Text=Combo1.List(i)ThenExitSub'
找到相同项目则退出
Combo1.AddItemCombo1.Text'
未找到则添加
删除功能
PrivateSubcmdDelete_Click()
IfCombo1.ListIndex>
=0Then'
是否选中某一项目
Combo1.RemoveItemCombo1.ListIndex'
删除选中项目
Else'
删除与输入内容相同的项目
Fori=0ToCombo1.ListCount-1
IfCombo1.List(i)=Combo1.TextThen
Combo1.RemoveItemi
清除
PrivateSubCommand3_Click()
Combo1.Clear
2.
PrivateSubCommand1_Click()‘产生随机数
Randomize
Fori=1To10
List1.AddItemStr(Int(Rnd*90)+10)
List2.Clear
PrivateSubCommand2_Click()‘迁移偶数
i=0
DoWhilei<
=List1.ListCount-1
IfVal(List1.List(i))Mod2=0Then
List2.AddItemList1.List(i)
List1.RemoveItemi
Else
i=i+1
Loop
3.
PrivateSubList1_DblClick()
DimiAsInteger
Fori=0ToList2.ListCount-1'
防止重复点歌
IfList2.List(i)=List1.TextThen
ExitSub
List2.AddItemList1.Text
PrivateSubList2_DblClick()
List2.RemoveItemList2.ListIndex
第8章习题参考答案
1.Open“c:
\stud1.txt”ForOutputAs#1
UCase(Text1)=”END”
Print#1,Text1
2.ForInput
ForOutputAs#2
NotEof
(1)
LineInput#1,str1
Close#1,#2
KILL"
c:
\old.dat"
3.ForAppendAs#1
ForInputAs#2
四、程序设计
1.
DimstrInAsString*1,CountAsInteger
'
打开文件进行统计
Open"
D:
\data.txt"
ForInputAs#1
Count=0'
计数器清零
DoWhileNotEOF
(1)
strIn=Input(1,#1)'
一次读出一个字符
IfstrIn="
$"
ThenCount=Count+1
Loop
Close#1
将结果写入到文本文件C:
\Mydir\res.txt中
\Mydir\res.txt"
ForOutputAs#1
Print#1,Count
2.
Dimk%,n%
Dimnum()AsSingle,sumAsSingle,aveAsSingle
\abc.txt"
n=n+1
ReDimPreservenum(n)
Input#1,num(n)
sum=sum+num(n)
ave=sum/n
Fork=1Ton
Ifnum(k)>
aveThenPrintnum(k);
Nextk
DimstrInAsString*1,k%,n%
DimNm(1To26)AsInteger
\Lcs.txt"
\Res.dat"
ForOutputAs#2
strIn=UCase(strIn)'
转换为大写字母
IfstrIn>
="
A"
AndstrIn