login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > .NET > VB.NET > Nulpunten (discriminant)

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:
  1. Public Class frmInput
  2.  
  3. Dim d As New discriminant
  4.  
  5. Private Sub btnBereken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBereken.Click
  6. d.A = CType(txtA.Text, Double)
  7. d.B = CType(txtB.Text, Double)
  8. d.C = CType(txtC.Text, Double)
  9. d.bereken()
  10. MessageBox.Show("Discriminant: " + d.D.ToString + vbCrLf + "X1: " + d.X1.ToString + vbCrLf + "X2: " + d.X2.ToString)
  11. End Sub
  12. End Class

Code:
Classe:
  1. Public Class discriminant
  2. 'door Wim Mariën
  3. 'http://www.gdx.be/
  4.  
  5. Private dblA, dblB, dblC As Double
  6. Private dblD As Double
  7. Private dblX, dblY As Double
  8.  
  9. Public WriteOnly Property A() As Double
  10. Set(ByVal value As Double)
  11. dblA = value
  12. End Set
  13. End Property
  14.  
  15. Public WriteOnly Property B() As Double
  16. Set(ByVal value As Double)
  17. dblB = value
  18. End Set
  19. End Property
  20.  
  21. Public WriteOnly Property C() As Double
  22. Set(ByVal value As Double)
  23. dblC = value
  24. End Set
  25. End Property
  26.  
  27. Public ReadOnly Property D() As Double
  28. Get
  29. Return dblD
  30. End Get
  31. End Property
  32.  
  33. Public ReadOnly Property X1() As Double
  34. Get
  35. Return dblX
  36. End Get
  37. End Property
  38.  
  39. Public ReadOnly Property X2() As Double
  40. Get
  41. Return dblY
  42. End Get
  43. End Property
  44.  
  45. Public Sub bereken()
  46. dblD = dblB ^ 2 - (4 * dblA * dblC)
  47. If (dblD > 0) Then
  48. dblX = (-dblB - Math.Sqrt(dblD)) / (2 * dblA)
  49. dblY = (-dblB + Math.Sqrt(dblD)) / (2 * dblA)
  50. ElseIf dblD = 0 Then
  51. dblX = (-dblB) / (2 * dblA)
  52. dblY = dblX
  53. Else
  54. dblX = CDbl(False)
  55. dblY = CDbl(False)
  56. End If
  57.  
  58. End Sub
  59. End Class
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (6)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.026s