2011年2月13日 星期日

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

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

輸入範例:80

輸出範例:270

5 則留言:

  1. Private Sub Form_Load()
    Me.Hide

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

    Input #1, x

    Select Case x
    Case Is < 40: Print #2, x * 2.2 + 30
    Case 40 To 100: Print #2, x * 3 + 30
    Case Is > 100: Print #2, x * 3.5 + 30
    End Select

    Close #1
    Close #2
    End
    End Sub

    回覆刪除
  2. Private Sub Form_Activate()
    me.hide
    Open App.Path & "\in.txt" For Input As #1
    Input #1, x
    Close #1

    Select Case x
    Case Is < 40
    ans = 30 + x * 2.2
    Case 40 To 100
    ans = 30 + x * 3
    Case Is > 100
    ans = 30 + x * 3.5
    End Select

    Open App.Path & "\out.txt" For Output As #2
    Print #2, ans
    Close #2
    end
    End Sub


    //--------------


    這題...未免太簡單了吧...

    回覆刪除
  3. Dim N As Integer
    Private Sub Form_Activate()
    me.hide

    Open App.Path & "\in.txt" For Input As #1
    Input #1, N
    Close #1

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

    Select Case N
    Case Is < 40
    Print #2, 30 + N * 2.2
    Case 40 To 100
    Print #2, 30 + N * 3
    Case Is > 100
    Print #2, 30 + N * 3.5
    End Select

    Close #2

    end
    End Sub

    回覆刪除
  4. 三位好,
    是簡單了些,但是,以往的比賽,還真有機會出這樣的送分題的。
    三位的程式都正確。 還是要多練手,比賽的時候才不會緊張而出錯。

    回覆刪除
  5. 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, n
    Select Case n
    Case Is < 40: n = n * 2.2 + 30
    Case 40 To 100: n = n * 3 + 30
    Case Is > 100: n = n * 3.5 + 30
    End Select
    Print #2, n
    Close
    Close
    End
    End Sub



    1:48

    回覆刪除