第七章
一、選擇題:
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.統(tǒng)計按鈕名為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
子函數(shù)
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能實現(xiàn)數(shù)據(jù)交換。因為地址傳遞方式形參和實參有共同的地址,那么形參的變化,會引起實參的變化(即形參將值回傳給實參),故可實現(xiàn)兩數(shù)交換。
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=”偶數(shù)”
Else
isQO=”奇數(shù)”
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