第七章
一、选择题:
1—12: DCADD BBDAC CB
二、填空题
1.42 2.Index 3.41
4.A(i)=a(11-i) a(11-i)=Tmp
5.1 6.X Mod 7=0 7.210
8.0 To 8 i+1 To 9
9.3 K 1
10. 1001 Max MaxMax)
三、编程题
1.Private Sub C1_click()
If OP1(0).Value=True Then P1.Print “选择了椭圆形”
If OP1(1).Value=True Then P1.Print “选择了圆形”
If OP1(2).Value=True Then P1.Print “选择了正方形”
End Sub
2.统计按钮名为Command1,输入框名为text1,输出框为text2(MultLine设为True)
Private Sub Command1_click()
Dim X(1 to 26) AS Integer,I As Integer
Dim S As String,L As Integer
L=Len(Text1.text)
For i=1 To L
S=Mid(Text1,I,1)
S=Ucase(S)
If S >= "A" And S <= "Z" Then
x(Asc(S) - 65 + 1) = x(Asc(S) - 65 + 1) + 1
End If
Next i
For i=1 To L
Text2=text2 & Chr(64+i) & “=” & x(i) & “ “
If I Mod 7=0 then Text2=text2 & chr(13)+chr(10)
Next i
End Sub
3.设学生成绩的平均分已在Mark(1)至Mark(10)中,学生姓名在name(1)至name(10)中。
Private Sub Command1_click()
Dim I%,J%,T%,S$
For i=1 To 9
For j=i+1 To 10
If Mark(i)<MARK(J) Then T=Mark(i):Mark(i)=Mark(j):Mark(j)=T
S=name(i):name(i)=name(j):name(j)=S
Next J
Next i
For i=1 To 10
Print Name(i),Mark(i)
Next i
End Sub
第八章
一、选择题:
1—10: DCBBDDDBCB
二、填空题
1.a Ubound(b) n=n-1
2.Key=a(i) Index=-1
三、编程题
1.子过程
Sub P1(x As Single, esp As Single)
Dim p!,S!,F!,i%
P=1:S=1:i=1:F=x
Do
P=P*i
S=S+F/p
Loop Until Abs(F/p)<ESP Print s
End Sub
子函数
Function P2(x As Single, esp As Single) As single
Dim p!,S!,F!,i%
P=1:S=1:i=1:F=x
Do
P=P*i
S=S+F/p
Loop Until Abs(F/p)<ESP P2=s
End Function
2.Swap2能实现数据交换。因为地址传递方式形参和实参有共同的地址,那么形参的变化,会引起实参的变化(即形参将值回传给实参),故可实现两数交换。
3.Function LF( ByVal x As Single) As Single
LF=X*X*X
End Function
Sub Command1_Click()
Dim I%
For i=1 To 20
Print I, LF(i)
Next i
End Sub
4.Function WeekDay(ByVal x As Integer) As String
Select Case x
Case 0
WeekDay=”星期日”
Case 1
WeekDay=”星期一”
Case 2
WeekDay=”星期二”
Case 3
WeekDay=”星期三”
Case 4
WeekDay=”星期四”
Case 5
WeekDay=”星期五”
Case 6
WeekDay=”星期六”
End Select
End Function
5.Function Rand30(ByVal X As`Integer) As Integer
Randomize
Rand30=Int(Rnd*X+1)
End Function
Sub Command1_Click()
For i=1 To 30
Print Rand30(100)
Next i
End Sub
6.Function F1(ByVal X As`Single, ByVal Y As`Single) As Integer
If X>Y Then
F1=X
Else
F1=Y
End If
End Function
7.
Function GDBH(ByVal x%) As String
Dim i%
For i = 3 To x - 3 Step 2
If isp(i) And isp(x - i) Then
GDBH = i & "+" & (x - i) & "=" & x
Exit Function
End If
Next
End Function
Function isp(y%) As Boolean
i = 2: k = Int(y / 2)
Do While i <= k
If y Mod i = 0 Then Exit Do
i = i + 1
Loop
If i > k Then
isp = True
Else
isp = False
End If
End Function
Private Sub Form_Click()
For i = 6 To 40 Step 2
Print GDBH(i)
Next i
End Sub
8.Function isQO(ByVal x As Integer) As String
If x Mod 2 =0 Then
isQO=”偶数”
Else
isQO=”奇数”
End If
End Function
9.Function F1(ByVal x As Integer) As Boolean
If x Mod 17 =0 and x Mod 37 =0Then
F1=True
Else
F1=False
End If
End Function
Private Sub Form_Click()
For i = 1000 To 2000
If F1(i) Then
Print i
End if
Next i
End Sub
10.Sub F1(a() As Integer, ByVal L1 As Integer, ByVal L2 As
Integer)
Dim L%, U%, x%, i%
L = LBound(a): U = UBound(a)
If L1 > U Or L2 > U Then
Print "位置输入错误!"
Exit Sub
End If
If L1 > L2 Then
x = a(L1)
For i = L1 To L2 + 1 Step -1
a(i) = a(i - 1)
Next i
a(L2) = x
ElseIf L2 > L1 Then
x = a(L1)
For i = L1 To L2 - 1
a(i) = a(i + 1)
Next i
a(L2) = x
End If
End Sub