2011年12月26日 星期一

第一次儲備選手選拔試卷第四題

電費計算:從指定目錄"in.txt"讀取一數字作為用電度數計算出電費,輸出至指定目錄"out.txt"。
電費算法為:電錶每月租金30元,用電在40度之內,每度2.2元,40度至100度,每度3元,超過100度,每度3.5元。

輸入範例:80

輸出範例:270

9 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Dim n As Integer
    Open App.Path & "/in.txt" For Input As #1
    Open App.Path & "/out.txt" For Output As #2
    Input #1, x
    n = 30
    If x < 40 Then n = n + x * 2.2
    If 40 < x < 100 Then n = n + x * 3
    If x > 100 Then n = n + x * 3.5

    Print #2, n
    Close
    Close
    End
    End Sub

    回覆刪除
  2. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, M
    If M < 40 Then X = M * 2.2 + 30
    If (M >= 40) And (M < 100) Then X = M * 3 + 30
    If M >= 100 Then X = M * 3.5 + 30
    Print #2, X
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. 晟晟程式正確。

    小冰,你的 40 < x < 100 是錯誤語法
    要像晟晟那樣才是正確的

    回覆刪除
  4. Private Sub Form_Load()
    Me.Hide
    Dim n As Integer
    Open App.Path & "/in.txt" For Input As #1
    Open App.Path & "/out.txt" For Output As #2
    Input #1, x
    n = 30
    If x < 40 Then n = n + x * 2.2
    If (40 <= x) And (x < 100) Then n = n + x * 3
    If x >= 100 Then n = n + x * 3.5

    Print #2, n
    Close
    Close
    End
    End Sub

    回覆刪除
  5. Private Sub Form_Load()
    Dim y As Integer
    Open App.Path & "\in.txt" For Input As 1
    Open App.Path & "\out.txt" For Output As 2
    Input #1, x
    If 40 < x <= 100 Then
    y = x * 3 + 30
    End If
    If 40 >= x Then
    y = x * 2.2 + 30
    End If
    If x > 100 Then
    y = x * 3.5 + 30
    End If

    Print #2, y
    Close
    Close
    End
    End Sub

    回覆刪除
  6. 小冰程式對了。

    哲哲跟小冰一開始一樣
    40 < x <= 100
    這樣不算是很正確的語法
    要改成像晟晟那樣
    然後題目要看清楚
    ※用電在40度之內,40度至100度,超過100度

    回覆刪除
  7. 作者已經移除這則留言。

    回覆刪除
  8. Dim a As Integer
    Dim x As Integer
    Private Sub Form_Load()
    Me.Hide


    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2

    Input #1, a


    x = 30

    If a < 40 Then
    x = x + a * 2.2
    End If

    If (a > 40 And a < 100) Then
    x = x + a * 3
    End If

    If a > 100 Then
    x = x + a * 3.5
    End If

    Print #2, x

    End
    End Sub

    回覆刪除
  9. Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, x
    If x < 40 Then m = 30 + x * 2.2
    If (x >= 40) And (x < 100) Then m = 30 + x * 3
    If (x >= 100) Then m = 30 + x * 3.5
    Print #2, m
    Close
    Close
    End

    回覆刪除