一.选择结构
'题目:在下面的程序段中过程pd可以判断任意三个数能否构成三角形的三边,利用该过程的判定结果, ' 对能构成三角形的计算其面积,构不成的显示\不能构成三角形\'------------------------------------------------ Option Explicit
Private Sub Form_Click()
'**********FOUND**********
Dim x%, y%, z%, s%, b As Boolean, h As Single x = InputBox(\请输入三角形的边长\y = InputBox(\请输入三角形的边长\z = InputBox(\请输入三角形的边长\b = pd(x, y, z) h = (x + y + z) / 2 '**********FOUND********** If Not b Then
s = Sqr(h * (h - x) * (h - y) * (h - z)) Print \三角形面积是\Else
Print \不能构成三角形\End If End Sub
'**********FOUND********** Public Function pd() As Boolean
If x > 0 And y > 0 And z > 0 And x + y > z And x + z > y And y + z > x Then pd = True Else
pd = False End If End Function
(答案1) Dim x% , y% , z% , s! , b As Boolean , h As Single (答案2) If b=true Then
(答案3) Public Function pd(x%, y%, z%) As Boolean
'------------------------------------------------
'题目:请根据下列描述编写购物优惠程序。某商场为了加速促成商品流通,采用购物打折的优惠办法,
每位顾客一次购物(1)在100元以上者,按九五折优惠;
' (2)在200元以上者,按九折优惠;
(3)在300元以上者,按八折优惠; (4)在500元以上者, 按七折优惠。
'------------------------------------------------ Option Explicit
Private Sub Command1_Click() Dim x As Single, y As Single x = Val(Text1.Text) If x < 100 Then
'**********FOUND********** x = y
Else
If x < 200 Then y = 0.95 * x Else
If x < 300 Then y = 0.9 * x Else
If x < 500 Then y = 0.8 * x Else
y = 0.7 * x
'**********FOUND********** Else If End If End If End If
'**********FOUND********** Text2.Text = x End Sub
(答案1) y = x (答案2) End If
(答案3) Text2.Text = y
'------------------------------------------------ '题目:程序功能根据输入的学习成绩,分别显示
优秀 (90分以上), 良好(75分以上),及格(60分以上), 不及格四个等级.
'------------------------------------------------ Option Explicit
Private Sub Form_Click()
Cls
Dim i As Integer
i = InputBox(\请输入学习成绩\Select Case i
'**********FOUND********** Case 0 < i < 100
MsgBox \成绩应该在0--100之间\
'**********FOUND**********
Case 90
Print \优秀\ Case 75 To 89 Print \良好\ Case 60 To 74 Print \及格\
'**********FOUND********** Case
MsgBox \不及格\End Select End Sub
(答案1) Case is>100 ,is<0 (答案2) Case 90 to 100 (答案3) Case else
二.一般
'------------------------------------------------
'题目:程序功能为求解一元二次方程的实根,请修正程序中错误。 '------------------------------------------------ Option Explicit
Private Sub Form_Load()
Dim a!, b!, c!, root1#, root2#, work As Double a = Val(InputBox(\请输入系数a的值\ b = Val(InputBox(\请输入系数b的值\ c = Val(InputBox(\请输入系数c的值\ '**********FOUND********** work = b * 2 - 4 * a * c If work >= 0 And a <> 0 Then '**********FOUND********** root1 = (Sqr(work)) / (2 * a) '**********FOUND********** root2 = (Sqr(work)) / (2 * a)
Print \有二个实根\ Else
Print \无实根!\ End If End Sub
(答案1) work = b ^ 2 - 4 * a * c
(答案2) root1 = (-b + Sqr(work)) / (2 * a) (答案3) root2 = (-b - Sqr(work)) / (2 * a)
'------------------------------------------------ '题目:求s=72+102+132+……832的值。
'------------------------------------------------ Option Explicit
Private Sub Form_Click()
Cls
Dim s As Long Dim i As Integer
'**********FOUND********** s = 1
'**********FOUND********** For i = 72 To 832
s = s + i
'**********FOUND********** loop 30 Print s End Sub
===(答案1)=== ===(答案2)==== ===(答案3)===
s =0 For i = 72 To 832 step 30 Next i
'------------------------------------------------ '题目:该程序的功能是求出100到200之间的全部素数, ' 并且按每行4个、每个数据之间有10个空格的格式输出。 '------------------------------------------------ Option Explicit
Private Sub Form_Click()
Dim k As Integer, i As Integer, j As Integer k = 0
For i = 100 To 200 '**********FOUND********** For j = 1 To i - 1
If i Mod j = 0 Then Exit For Next j If j = i Then
'**********FOUND********** Print i; Tab(10); k = k + 1
'**********FOUND**********
If k Mod 5 = 0 Then Print ; End If Next i End Sub
(答案1) For j = 2 To i - 1 (答案2) Print i; Space(10); (答案3) If k Mod 4 = 0 Then Print
'------------------------------------------------ '题目: 输入一个字符串,将所有的小写字母都转换为大写字母。 '------------------------------------------------ Option Explicit
Private Sub Form_Click()
Dim s1 As String, s2 As String, i As Integer, t As String s1 = InputBox(\输入字符串,#号结束\ i = 1
'**********FOUND********** s1 = Mid(s1, i, 1) Do While t <> \
'**********FOUND**********
If t >= \ s2 = s2 + t i = i + 1
t = Mid(s1, i, 1) Loop
'**********FOUND********** Print \新字符串为:\
End Sub
(答案1) t = Mid(s1, i, 1)
(答案2) If t >= \(答案3) Print \新字符串为:\
三.级数
'------------------------------------------------
'题目:程序功能:求1+2+3……,直到其和超出3000为止,并输入结果。 '------------------------------------------------ Option Explicit
Private Sub Form_Click()
Cls
Dim i As Integer Dim s As Single i = 0
'**********FOUND********** s = 1 Do
'**********FOUND********** i = i + 2 s = s + i
'**********FOUND********** Loop s > 3000
Print \从1 到:\的和是\End Sub (答案1) s =0
(答案2) i = i + 1
(答案3) Loop until s > 3000
'------------------------------------------------ '题目:用自定义函数的方法求sum(x),求当-1≤x≤1时, ' sum(x)=x/2!+x^2/3!+x^3/4!+……+x^n/(n+1)!,
' 当x〉1或x〈-1时,函数值为0。当n〈=0时,输入数据错误。X、N都是由用户输入。 '------------------------------------------------ Option Explicit
Private Sub Command1_Click() Dim s As Single
Dim n As Integer, x As Single, k As Integer n = Val(InputBox(\ x = Val(InputBox(\ If n <= 0 Then
k = MsgBox(\数据输入错误!\数据输入\ Exit Sub End If s = Sum(x, n) Print s End Sub
百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说教育文库VB - 改错练习答案在线全文阅读。
相关推荐: