English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請問有誰會用Microsoft Visual Basic寫以下兩題程式設計題(越詳細越好)

第一題:
假設轎車出租租金計費方式為:第一天1000元,第2天起打8折優待
請寫一程式輸入出租天數後,印出應付租金費用

第二題:
寫一程式,輸入一西元年份,輸出該年為閏年還是平年,
有關閏年的算法如下:
(1)該年為400的倍數,則該年為閏年
(2)該年不是100的倍數,而是4的倍數,則該年為閏年

2005-06-16 16:17:12 · 2 個解答 · 發問者 Anonymous in 電腦與網際網路 程式設計

2 個解答

第一題:
首先在表單上放一個text和一個command
然後在command的click輸入以下程式,就行了。
Private Sub Command1_Click()
Dim n As Integer
n = Val(Text1.Text)
If n = 1 Then
MsgBox "應付租金為1000元"
ElseIf n > 1 Then
MsgBox "應付租金為" & (n - 1) * 800 + 1000
Else
MsgBox "請輸入大於零的數字。"
End If
End Sub

第二題:
依然在表單上放一個text和command
依然在command的click放下面的程式碼,就可以了
Private Sub Command1_Click()
Dim d As Integer
d = Val(Text1.Text)
If d > 0 Then
If d Mod 4 = 0 And (d Mod 100 <> 0 or d Mod 400 = 0) Then
MsgBox "西元" & Text1.Text & "年是潤年"
Else
MsgBox "西元" & Text1.Text & "年是平年"
End If
Else
MsgBox "請輸入大於○的西元年"
End If
End Sub

另外提醒你,下次可以試著寫寫看,不會再上來問,才會進步喔

2005-06-16 18:10:05 · answer #1 · answered by 上官 5 · 0 0

Option Explicit

Private Sub Command1_Click()
Dim Rent As Single
Dim Day As Integer

Rent = 1000
Day = Val(InputBox("輸入天數"))

If Day < 2 Then

MsgBox "租金" & Rent & "元"

Else
Rent = 1000 + ((1000 * 0.8) * (Day - 1))

MsgBox "租金" & Rent & "元"
End If

End Sub

Private Sub Command2_Click()

Dim Y As Integer

Y = Val(InputBox("請輸入年份"))

If Y Mod 4 = 0 Or (Y Mod 100 <> 0 Or Y Mod 400 = 0) Then

MsgBox "閏年"
Else
MsgBox "平年"
End If
End Sub

2005-06-16 18:48:32 · answer #2 · answered by ? 1 · 0 0

fedest.com, questions and answers