Advertisement
marongiuchristian93

[VB.NET] Calcolo del Delta

Jan 20th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Module Module1
  2.  
  3.     Sub Main()
  4.  
  5.         'Calcolo Delta
  6.  
  7.         'Variabili
  8.  
  9.         Dim a As Single
  10.         Dim b As Single
  11.         Dim c As Single
  12.         Dim d As Single
  13.         Dim text00 As String
  14.         Dim text0 As String
  15.         Dim text1 As String
  16.         Dim text2 As String
  17.         Dim text3 As String
  18.         Dim text4 As String
  19.         Dim text5 As String
  20.         Dim text6not As String
  21.         Dim textfin As String
  22.  
  23.         'VARIABILI RADICE
  24.  
  25.         Dim i As Double 'Variabile i
  26.        Dim f As Double ' Variabile f
  27.        Dim pm As Double 'Variabile pm
  28.        Dim RisRad As String
  29.  
  30.         'SOLUZIONI x1 e x2
  31.  
  32.         Dim RP As Double
  33.         Dim RN As Double
  34.         Dim textSolUno
  35.         Dim textSolDue
  36.  
  37.         '-----------------------------
  38.  
  39.         'Spiegazione variabili
  40.        text00 = "Ricorda che: se Delta > 0 e si ricerca x > 0, la soluzione avrà valori esterni. Se Delta > 0 e si ricerca x < 0, la soluzione avrà valori interni. Se Delta < 0 e x > 0  la soluzione è Per ogni x. Se Delta < 0 e x < 0 la soluzione è Impossibile"
  41.         text0 = "Inserisci B, invio; Inserisci A, invio; Inserisci C, invio; Visualizzerai il delta quanto vale"
  42.         text1 = "Il Delta vale:" & d
  43.         text3 = "Il Delta è maggiore di zero quindi l'equazione ha due soluzioni distinte. "
  44.         text4 = "Il Delta è uguale a zero quindi l'equazione ha due soluzioni coincidenti."
  45.         text5 = "Il Delta è minore di zero quindi l'equazione non ha soluzioni, o ha soluzione come OGNI X"
  46.         text6not = ""
  47.         textfin = "Approssima la radice non contare tutti i numeri dopo la virgola ;)"
  48.         textSolUno = RP & " <- La soluzione x1 positiva"
  49.         textSolDue = RN & " <- La soluzione x2 negativa"
  50.         'Inserire variabili e letture
  51.        System.Console.Write(text00)
  52.         '/* Come premere Invio
  53.        System.Console.WriteLine(text6not)
  54.         System.Console.WriteLine(text6not)
  55.         '*/
  56.  
  57.         '/* Invio
  58.        System.Console.WriteLine(text6not)
  59.         'Inserisci variabili
  60.        System.Console.Write(text0)
  61.         'Invio */
  62.        System.Console.WriteLine(text6not)
  63.  
  64.         b = System.Console.ReadLine() 'valore A
  65.        a = System.Console.ReadLine() 'valore B
  66.        c = System.Console.ReadLine() 'valore C
  67.        d = (b * b) - (4 * a * c) 'Delta
  68.  
  69.         'Scrivi quanto vale Delta
  70.  
  71.         text2 = d & " <- Valore Delta "
  72.         MsgBox(text2)
  73.  
  74.         'Condizioni con il Delta
  75.  
  76.         'Delta > 0
  77.        If d > 0 Then
  78.             MsgBox(text3)
  79.             'Delta = 0
  80.        ElseIf d = 0 Then
  81.             MsgBox(text4)
  82.             'Delta < 0
  83.        ElseIf d < 0 Then
  84.             MsgBox(text5)
  85.         End If
  86.  
  87.         'Per fare una prova:
  88.        'assegniamo a B il valore 12, ad A 11 e a C 1
  89.        'B = 12, A = 11, C = 1
  90.        ' (12*12) - (4*11*1)
  91.        ' 144 - 44
  92.        ' 100 <- Valore Delta
  93.        ' Delta > 0 (vedi messaggio)
  94.  
  95.         'B = 12, A = 36, C = 1
  96.        ' (12*12) - (4*36*1)
  97.        ' 144 - 144
  98.        ' 0 <- Valore Delta
  99.        ' Delta = 0 (vedi messaggio)
  100.  
  101.         'B = 12, A = 30, C = 10
  102.        ' (12*12) - (4*30*10)
  103.        ' 144 - 1200
  104.        ' -1056 <- Valore Delta
  105.        ' Delta < 0 (vedi messaggio)
  106.        ' ---------------------------------------------
  107.        'RADICE
  108.  
  109.         If (d > 1) Then 'qui se A1 è > 0 allora
  110.            i = 1 'Intervallo iniziale diventa 1
  111.            f = d 'Int finale diventa A1 (delta)
  112.        Else 'Altrimenti
  113.            i = d 'Int iniz diventa A1 (delta)
  114.            f = 1 'Int finale diventa 1
  115.        End If
  116.  
  117.         Do 'Inizio CICLO DO UNTIL
  118.            pm = (i + f) / 2 'calcolo punto medio
  119.  
  120.             If (pm * pm > d) Then 'se pm al quadrato maggiore di A1 (delta)
  121.                f = pm 'Allora int finale diventa pm
  122.            Else 'altrimenti
  123.                i = pm 'int finale diventa pm
  124.            End If
  125.  
  126.         Loop Until Math.Abs((pm * pm) - d) < 0.1 'continuazione del calcolo finche pm al quadrato - a sia minore di 0,0001
  127.        System.Console.WriteLine(pm)
  128.  
  129.         RisRad = Math.Truncate(pm) & " <- La radice di Delta" 'Messaggio che riporta il valore della radice del delta.
  130.  
  131.         System.Console.WriteLine(text6not) 'Invio
  132.        System.Console.WriteLine(text6not) 'Invio
  133.        System.Console.WriteLine(textfin) 'Approssimare la radice
  134.  
  135.         System.Console.WriteLine(RisRad)
  136.         MsgBox(RisRad) 'Risultato radice
  137.        MsgBox(textfin)
  138.        
  139.         'Con questo programma si può quindi calcolare il delta e la sua radice
  140.  
  141.     End Sub
  142.  
  143. End Module
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement