-
Triangle Property (class)
I have a program that takes user input from a textbox. Based on those 3 numbers it will tell them whether it is a right triangle, equilateral triangle or not a triangle. I've written 3 properties (get/set) to take the lengths. Now I need two readonly (get only) properties s to determine whether something is right or equilateral. I'm really not sure how I would write the formula in vb. I understand a right triangle is a2 + b2 = c2 but i'm not sure how I could process a math formula inside a property. I guess I am also trying to learn how these two new properties would interact with the 3 already written? Here is what I have so far. I do not yet have anything for the right triangle. Does this make sense and anybody know how to easily calculate a right triangle. The formulas online haven't really made sense to me in order to write it out in vb.
Code:
Public Class Triangle
'declare integers for 3 triangle sides
Dim m_intSide1 As Integer
Dim m_intSide2 As Integer
Dim m_intSide3 As Integer
'declare integers for triangle type
Dim m_intRight As Integer
Dim m_intEquilateral As Integer
'Triangle constructor, sides supplied
Public Sub New(ByVal side1Value As Integer, ByVal side2Value As Integer, _
ByVal side3Value As Integer, ByVal RightTriangleValue As Integer, _
ByVal EquilateralValue As Integer)
m_intSide1 = side1Value
m_intSide2 = side2Value
m_intSide3 = side3Value
m_intRight = RightTriangleValue
m_intEquilateral = EquilateralValue
End Sub 'New
'property side1
Public Property Side1() As Integer
'return m_intSide1 value
Get
Return m_intSide1
End Get 'end of Get accessor
'set m_intside1 value
Set(ByVal Value As Integer)
'if side 1 value entered is valid
If (Value > 0) Then
m_intSide1 = Value
Else
m_intSide1 = 0 'set invalid input to 0
End If
End Set 'end of set accessor
End Property
'property side2
Public Property Side2() As Integer
'return m_intSide2 value
Get
Return m_intSide2
End Get 'end of Get accessor
'set m_intside2 value
Set(ByVal Value As Integer)
'if side 2 value entered is valid
If (Value > 0) Then
m_intSide2 = Value
Else
m_intSide2 = 0 'set invalid input to 0
End If
End Set 'end of set accessor
End Property
'property side3
Public Property Side3() As Integer
'return m_intSide3 value
Get
Return m_intSide3
End Get 'end of Get accessor
'set m_intside3 value
Set(ByVal Value As Integer)
'if side 3 value entered is valid
If (Value > 0) Then
m_intSide3 = Value
Else
m_intSide3 = 0 'set invalid input to 0
End If
End Set 'end of set accessor
End Property
'property IsRight (copied from below, work in progress)
Public ReadOnly Property IsRight() As Integer
'return m_intRightTriangle value
Get
If (Side1 = Side2 AndAlso Side2 = Side3) Then
Return m_intRight
End If
End Get 'end of Get accessor
End Property
'property IsEquilateral
Public ReadOnly Property IsEquilateral() As Integer
'return m_intEquilateral value
Get
If (Side1 = Side2 AndAlso Side2 = Side3) Then
Return m_intEquilateral
End If
End Get 'end of Get accessor
End Property
End Class 'Triangle
-
geo039,
I would consider making IsRight and IsEquilateral methods (public functions) that return boolean values.
Kerry Moorman
-
That's also how I approached it and since this is a hw assignment there are requirements and it has to be in a property but due to the timeframe I have normally at this point I just try to get it to work and take whatever credit I can get, so I may end up just putting it in a boolean function.
Similar Threads
-
Replies: 5
Last Post: 01-15-2006, 07:10 PM
-
By thegios in forum VB Classic
Replies: 1
Last Post: 09-19-2005, 02:08 PM
-
By Patrick Ireland in forum .NET
Replies: 3
Last Post: 05-07-2001, 03:04 PM
-
By Patrick Ireland in forum .NET
Replies: 0
Last Post: 04-26-2001, 10:01 PM
-
By Jerry Bumgarner in forum VB Classic
Replies: 4
Last Post: 07-14-2000, 10:48 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Development Centers
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center
|