当前位置: 高中信息技术 / 综合题
  • 1. (2021高二下·德清开学考) 要求编写一个“统计直角三角形的个数”的程序,功能如下:在文本框Text1中依次输入3*N个数表示三角形的边长(用逗号分隔并以逗号结尾),单击“计算”按钮Command1后,程序统计直角三角形个数,并在标签Label1中显示。程序运行界面如图所示。

    Private Sub Command1_Click()

        Dim i As Integer, j As Integer, k As Integer

        Dim x1 As Single, x2 As Single, x3 As Single, t As Single Dim Totald As Integer, v As Single, s As String

        s = Text1.Text

        k = 0: j = 1: Totald = 0

        For i = 1 To Len(s)

            If Mid(s, i, 1) = "," Then

                v = Val(Mid(s, j, i - j))       '提取三角形边长,保存在变量v中

                   ①    

                If k Mod 3 = 1 Then

                    x1 = v

                ElseIf k Mod 3 = 2 Then x2 = v

                If x1 < x2 Then t = x1: x1 = x2: x2 = t

                Else

                    x3 = v

                    If x1 < x3 Then t = x1: x1 = x3: x3 = t

                    If   ②    Then Totald = Totald + 1

                End If

               

            End If

        Next i

        Label1.Caption = "一共构成" + Str(Totald) + " 个直角三角形"

    End Sub

    1. (1) 请在划线处补充合适的代码。

       ② 

    2. (2) 加框处代码有误,请改正。
    3. (3) 观察程序代码,若正确完成(1)、(2)后,调试过程中出现如下错误提示,可能是程序代码执行到第行报错。

微信扫码预览、分享更方便