VB物件導向 問題
請問虛線部分的(註解)主程式該如何推算 如果沒有電腦執行的話 m(_ _)m 感激不盡Module Module1
Class Vector
Private x As Integer = 0
Private y As Integer = 0
Public Overloads Sub setvalue(ByVal tx As Integer)
x = more(tx)
y = more(tx)
End Sub
Public Overloads Sub setvalue(ByVal tx As Integer, ByVal ty As Integer)
x = more(tx)
y = more(ty)
End Sub
Public Overloads Sub setvalue(ByVal t As Vector)
x = t.x
y = t.y
End Sub
Public Sub display()
If length() <= 16 Then
Console.WriteLine("x = {0}, y = {1}", x, y)
Else
Console.WriteLine("x = {0}, y = {1}, length= {2}", x, y, length())
End If
End Sub
Public Function length() As Single
Return (x + y)
End Function
Private Function more(ByVal t As Integer) As Integer
Return IIf(t > 12, 12, t)
End Function
Public Overloads Sub add(ByVal t As Vector)
x = more(x + t.x)
y = more(y + t.y)
End Sub
Public Overloads Sub addvalue(ByVal tx As Integer, ByVal ty As Integer)
x = more(x + tx)
y = more(y + ty)
End Sub
Public Overloads Sub addvalue(ByVal tx As Integer)
x = more(x + tx)
y = more(y + tx)
End Sub
Public Overloads Sub subtvalue(ByVal t As Vector)
x = more(x - t.x)
y = more(y - t.y)
End Sub
Public Overloads Sub subtvalue(ByVal tx As Integer, ByVal ty As Integer)
x = more(x - tx)
y = more(y - ty)
End Sub
Public Overloads Sub mulvalue(ByVal tx As Integer)
x = more(x * tx)
y = more(y * tx)
End Sub
Public Overloads Sub mulvalue(ByVal t As Vector)
x = more(x * t.x)
y = more(y * t.y)
End Sub
End Class
Sub Main()
'Dim i As New Vector()
'i.setvalue(15)
'i.display()
'---------------------------------
'Dim i As New Vector()
'Dim k As New Vector()
'i.setvalue(6, 4)
'k.setvalue(i)
'k.addvalue(2)
'k.display()
'---------------------------------
' Dim i As New Vector()
'i.setvalue(2, 3)
'i.mulvalue(i)
'i.display()
'------------------------------------------
Dim i As New Vector()
i.setvalue(18, 4)
i.subtvalue(2, 1)
Dim k As Vector
k = i
i.display()
'-----------------------------------------
Console.Read()
End Sub
End Module
[[i] 本帖最後由 odin0912 於 2009-4-15 21:03 編輯 [/i]] Sub Main()
'Dim i As New Vector()
'i.setvalue(15) ==> i.x =12, i.y=12
'i.display() ==> x =12, y = 12, length= 24
'---------------------------------
'Dim i As New Vector() ==> 這裡應該會有Error, 因為 i 重複定義, 假設不考慮重複定義的狀況下:
'Dim k As New Vector()
'i.setvalue(6, 4) ==> i.x=6 , i.y=4
'k.setvalue(i) ==> k.x=6,k.y=4
'k.addvalue(2) ==> k.x=8,k.y=6
'k.display() ==> 後面的自己推吧..........
'---------------------------------
' Dim i As New Vector()
'i.setvalue(2, 3)
'i.mulvalue(i)
'i.display()
'------------------------------------------
Dim i As New Vector()
i.setvalue(18, 4)
i.subtvalue(2, 1)
Dim k As Vector
k = i
i.display()
'-----------------------------------------
Console.Read()
End Sub
頁:
[1]