Page 149 -
P. 149

附錄四:11900 電腦軟體設計丙級學科題庫(105 年新版)

4.程式碼
 Public Class Form1

       Private Sub Form1_Load(sender As System.Object, e ……………………………
             Dim a, b, x, y, c, d, c1, d1, r, t As Integer
             Dim op, ans As String
             FileOpen(1, "c:\丙設磁片\940308.sm", OpenMode.Input)
             Dim i As Integer = 0
             Do While Not EOF(1)
                   Input(1, b) : Input(1, a) : Input(1, op) : Input(1, y) : Input(1, x)
                   Select Case op
                         Case "+"
                               c=b*x+a*y:d=a*x
                         Case "-"
                               c=b*x-a*y:d=a*x
                         Case "*"
                               c=b*y:d=a*x
                         Case "/"
                               c=b*x:d=a*y
                   End Select
                   If (c Mod d) = 0 Then
                         ans = Str(c / d)
                   Else
                         c1 = c : d1 = d
                         If d1 > c1 Then t = c1 : c1 = d1 : d1 = t
                         Do
                               r = c1 Mod d1
                               c1 = d1
                               d1 = r
                         Loop While (r > 0)
                         ans = Str(c / c1) & "/" & Str(d / c1)
                   End If
                   With dv
                         .Rows.Add(1)
                         .Item(0, i).Value = b & "/" & a
                         .Item(1, i).Value = op
                         .Item(2, i).Value = y & "/" & x
                         .Item(3, i).Value = ans
                         .Height = i * 35
                   End With
                   i=i+1
             Loop
             FileClose(1)

       End Sub
 End Class

5.完成程式(以 940308.sm 為答案)

                                                          145
   144   145   146   147   148   149   150   151   152   153   154