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


Reply With Quote


Bookmarks