二、选择题
题号 答案 1 D 2 C 3 A 4 D 5 B
三、程序填空题 1.(1) nsp=true (2) m mod i=0 (3) p1 and p2 (4) p1=nsp(i) 2.(1) number(i,7)
(2) (int n, int m)
(3) number=number*10+m
四、程序阅读 1. a=9 b=4 2.(1) 36
25 16 9 4 1
(2)
1 4 9 9 4 1
3. 6 4. 1 4 6
五、编写程序
1.
Public Function fact(x As Integer) As Single Dim f As Single, i As Integer f = 1
For i = 1 To x
f = f * i '累积 Next i fact = f End Function
Private Sub Form_Click() Dim n%, m%, y! Do
'求x! m% = Val(InputBox(\ n% = Val(InputBox(\ Loop Until m >= n And n >= 0 y = fact(m) / (fact(n) * fact(m - n)) Print y End Sub
2 private sub Insertfun(a%(), y%) Dim i as integer,n as integer n=ubound(a)
Redim preserve a(n+1) For i=ubound(a)-1 to 0 step -1 If y
If i=0 then a(i)=y Else
a(i+1)=y exit for end if next i
3. '判断是否为回文函数
Private Function Judge(str As String) As Boolean
Dim i As Integer
Judge = True '假设为回文
For i = 1 To Len(str) \\ 2 '依次判断对应位置的两个字符,只要有一组不等即不是回文 If Mid(str, i, 1) <> Mid(str, Len(str) + 1 - i, 1) Then Judge = False Exit Function End If Next i End Function 4.
Private Sub Form_Click() Dim n%,x!
n = Val(InputBox(\ x = Val(InputBox(\
Print fe(n, x) '调用求值函数过程 End Sub
'求值函数过程
Public Function fe(n%, x!) As Single
Dim i As Integer, t As Single
fe = 1: t = 1 For i = 1 To n
t = t * x / i 't为通项
fe = fe + t Next i End Function 5.。。。。
第7章 习题参考答案 一、判断题
题号 1 答案 × 2 × 3 √ 4 √ 5 × 6 × 7 × 8 √ 9 √ 10 √ 11 × 12 × 13 √ 14 √ 15 × 16 √ 二、填空题
1.___Multiline_______ 2.____Value______ 3.___Selected______、____List______、____0______、___List1.ListCount-1____ 4. 下拉式列表框
5.___LargeChange_______、____Value______ 6. Shift+Ctrl 7.KeyAscii=0
if KeyAscii>57 OR KeyAscii<48 then KeyAscii=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.RemoveItem List1.ListIndex
List1.AddItem List2.List(List2.ListIndex) List2.RemoveItem
四、选择题
题号 答案 1 A 2 D 3 D 4 B 5 D 6 D 7 C 8 D 五、编程题
1.'添加功能
Private Sub cmdAdd_Click()
Dim i%
If Combo1.Text = \
For i = 0 To Combo1.ListCount - 1 '逐个判断是否有与输入内容相同的项目 If Combo1.Text = Combo1.List(i) Then Exit Sub '找到相同项目则退出 Next i
Combo1.AddItem Combo1.Text '未找到则添加 End Sub '删除功能
Private Sub cmdDelete_Click()
If Combo1.ListIndex >= 0 Then '是否选中某一项目
Combo1.RemoveItem Combo1.ListIndex '删除选中项目 Else '删除与输入内容相同的项目 For i = 0 To Combo1.ListCount - 1 If Combo1.List(i) = Combo1.Text Then Combo1.RemoveItem i End If Next i End If End Sub '清除
Private Sub Command3_Click() Combo1.Clear End Sub 2.
Private Sub Command1_Click() ‘ 产生随机数 Dim i%
Randomize
For i = 1 To 10
List1.AddItem Str(Int(Rnd * 90) + 10) Next i
List2.Clear End Sub
Private Sub Command2_Click() ‘ 迁移偶数 Dim i%
i = 0
Do While i <= List1.ListCount - 1
If Val(List1.List(i)) Mod 2 = 0 Then List2.AddItem List1.List(i) List1.RemoveItem i
Else
i = i + 1 End If
Loop End Sub 3.
Private Sub List1_DblClick() Dim i As Integer
For i = 0 To List2.ListCount - 1 '防止重复点歌 If List2.List(i) = List1.Text Then Exit Sub End If Next i
List2.AddItem List1.Text End Sub
Private Sub List2_DblClick()
List2.RemoveItem List2.ListIndex End Sub
第10章 习题参考答案 一、判断题
题号 1 答案 √ 2 √ 3 √ 4 × 5 × 6 × 7 √ 8 √ 9 √ 10 √ 二、选择题
题号 答案 1 D 2 A 3 C 4 C 5 B 6 D 7 A 8 B 9 D 10 B 三、填空题
1. 2. 3. 4. 5.
窗体控件菜单、下拉菜单、快捷菜单
___ShowFont___ ___打开/另存为、颜色、字体、帮助、打印
工程/部件、选中Microsoft Common Dialog Control 6.0 ___ CommonDialog1.Action =3、CommonDialog1.ShowColor ______