Nulpunten (discriminant)
Auteur: Wim - 06 december 2007 - 18:58 - Gekeurd door: Abbas - Hits: 4572 - Aantal punten: 4.67 (3 stemmen)
Een simpele classe die nulpunten van een 2degraads functie berekent.
Voorbeeld voor gebruik:
Public Class frmInput
Dim d As New discriminant
Private Sub btnBereken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBereken.Click
d.A = CType(txtA.Text, Double)
d.B = CType(txtB.Text, Double)
d.C = CType(txtC.Text, Double)
d.bereken()
MessageBox.Show("Discriminant: " + d.D.ToString + vbCrLf + "X1: " + d.X1.ToString + vbCrLf + "X2: " + d.X2.ToString)
End Sub
End Class
Public Class frmInput Dim d As New discriminant Private Sub btnBereken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBereken.Click d.A = CType(txtA.Text, Double) d.B = CType(txtB.Text, Double) d.C = CType(txtC.Text, Double) d.bereken() MessageBox.Show("Discriminant: " + d.D.ToString + vbCrLf + "X1: " + d.X1.ToString + vbCrLf + "X2: " + d.X2.ToString) End Sub End Class
|
Code: |
Classe:
Public Class discriminant
'door Wim Mariën
'http://www.gdx.be/
Private dblA, dblB, dblC As Double
Private dblD As Double
Private dblX, dblY As Double
Public WriteOnly Property A() As Double
Set(ByVal value As Double)
dblA = value
End Set
End Property
Public WriteOnly Property B() As Double
Set(ByVal value As Double)
dblB = value
End Set
End Property
Public WriteOnly Property C() As Double
Set(ByVal value As Double)
dblC = value
End Set
End Property
Public ReadOnly Property D() As Double
Get
Return dblD
End Get
End Property
Public ReadOnly Property X1() As Double
Get
Return dblX
End Get
End Property
Public ReadOnly Property X2() As Double
Get
Return dblY
End Get
End Property
Public Sub bereken()
dblD = dblB ^ 2 - (4 * dblA * dblC)
If (dblD > 0) Then
dblX = (-dblB - Math.Sqrt(dblD)) / (2 * dblA)
dblY = (-dblB + Math.Sqrt(dblD)) / (2 * dblA)
ElseIf dblD = 0 Then
dblX = (-dblB) / (2 * dblA)
dblY = dblX
Else
dblX = CDbl(False)
dblY = CDbl(False)
End If
End Sub
End Class
Public Class discriminant 'door Wim Mariën 'http://www.gdx.be/ Private dblA, dblB, dblC As Double Private dblD As Double Private dblX, dblY As Double Public WriteOnly Property A() As Double Set(ByVal value As Double) dblA = value End Set End Property Public WriteOnly Property B() As Double Set(ByVal value As Double) dblB = value End Set End Property Public WriteOnly Property C() As Double Set(ByVal value As Double) dblC = value End Set End Property Public ReadOnly Property D() As Double Get Return dblD End Get End Property Public ReadOnly Property X1() As Double Get Return dblX End Get End Property Public ReadOnly Property X2() As Double Get Return dblY End Get End Property Public Sub bereken() dblD = dblB ^ 2 - (4 * dblA * dblC) If (dblD > 0) Then dblX = (-dblB - Math.Sqrt(dblD)) / (2 * dblA) dblY = (-dblB + Math.Sqrt(dblD)) / (2 * dblA) ElseIf dblD = 0 Then dblX = (-dblB) / (2 * dblA) dblY = dblX Else dblX = CDbl(False) dblY = CDbl(False) End If End Sub End Class
Download code (.txt)
|
|
Stemmen |
Niet ingelogd. |
|