Advertisement
Guest User

Regola di Ruffini

a guest
Mar 9th, 2012
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.79 KB | None | 0 0
  1. #Region Includes
  2. #include <GUIConstantsEx.au3>
  3. #include <StaticConstants.au3>
  4. #EndRegion Includes
  5.  
  6. #Region GUI
  7. Local $ValCoefficient[7]
  8. $Form1 = GUICreate("Regola di Ruffini")
  9. $Label1 = GUICtrlCreateLabel("Numero di Coefficienti:"&@CRLF&@CRLF&@CRLF&"                                       Valore dei Coefficienti:", 32, 8)
  10. $List1 = GUICtrlCreateCombo ("3", 150, 5)
  11. GUICtrlSetData(-1, "4|5|6")
  12. For $i = 1 To 6
  13.     $ValCoefficient[$i] = GUICtrlCreateInput("", 45*$i, 70, 40, 20)
  14. Next
  15. $Label2 = GUICtrlCreateLabel ("Divisore: x-", 32, 110)
  16. $Input7 = GUICtrlCreateInput("", 90, 107, 41, 21)
  17. $Button1 = GUICtrlCreateButton("Costruisci tabella", 160, 100, 120, 35)
  18. $Button2 = GUICtrlCreateButton("Calcola!", 300, 100, 70, 35)
  19. GUICtrlSetState ($Button2, $GUI_DISABLE)
  20. GUISetState(@SW_SHOW)
  21. #EndRegion GUI
  22.  
  23. #Region Global Vars
  24. Global $Cicle
  25. Global $InputFirstLine
  26. Global $InputScndLine
  27. Global $InputThrdLine
  28. Global $Graphic
  29. Global $PoltResLabel
  30. #EndRegion Global Vars
  31.  
  32. #Region Program Cicle
  33. While 1
  34.     $nMsg = GUIGetMsg()
  35.     Switch $nMsg
  36.         Case $GUI_EVENT_CLOSE
  37.             Exit
  38.         Case $Button1
  39.             If Not $Cicle = 0 Then
  40.                 For $i = 1 To UBound ($InputFirstLine)-1
  41.                     GUICtrlDelete ($InputFirstLine[$i])
  42.                 Next
  43.                 For $i = 1 To UBound ($InputScndLine)-1
  44.                     GUICtrlDelete ($InputScndLine[$i])
  45.                 Next
  46.                 For $i = 1 To UBound ($InputThrdLine)-1
  47.                     GUICtrlDelete ($InputThrdLine[$i])
  48.                 Next
  49.                 For $i = 1 To UBound ($Graphic)-1
  50.                     GUICtrlDelete ($Graphic[$i])
  51.                 Next
  52.                 GUICtrlDelete ($PoltResLabel)
  53.             EndIf
  54.             Dim $DividLab
  55.             GUICtrlDelete ($DividLab)
  56.             $Read = _ReadInput ()
  57.             For $i = 1 To GUICtrlRead ($List1)
  58.                 If $Read[$i] = "" Then
  59.                     $Complete = False
  60.                     ExitLoop
  61.                 Else
  62.                     $Complete = True
  63.                 EndIf
  64.             Next
  65.             If $Complete = False Then
  66.                 MsgBox (48, "Errore", "Inserire i Coefficienti!")
  67.                 GUICtrlSetState ($Button2, $GUI_DISABLE)
  68.             ElseIf GUICtrlRead ($Input7) = "" Then
  69.                 MsgBox (48, "Errore", "Inserire il Divisore!")
  70.             Else
  71.                 $DividLab = GUICtrlCreateLabel ("Dividendo = " & _Dividendo(GUICtrlRead ($List1)) & @CRLF& "Divisore = x-" & GUICtrlRead ($Input7), 20, 150)
  72.                 _CreateGraph ()
  73.                 _CreateInLineInput ()
  74.                 GUICtrlSetState ($Button2, $GUI_ENABLE)
  75.             EndIf
  76.             $Cicle = $Cicle + 1
  77.         Case $Button2
  78.             _Calc ()
  79.             $PoltResLabel = GUICtrlCreateLabel ("Risultato: " & _GetResultPoly (), 10, 375)
  80.     EndSwitch
  81. WEnd
  82. #EndRegion Program Cicle
  83.  
  84. #Region Funcs
  85. Func _Dividendo ($NumFact)
  86.     $Read = _ReadInput ()
  87.     Local $Dividendo
  88.     For $i = 1 To $NumFact-1
  89.         $Dividendo = $Dividendo & $Read[$i] & "x^" & $NumFact-$i & "+"
  90.     Next
  91.     $Dividendo = $Dividendo & $Read[$NumFact]
  92.     Return $Dividendo
  93. EndFunc
  94.  
  95. Func _ReadInput ()
  96.     Local $Ret[8]
  97.     For $i = 1 To 6
  98.         $Ret[$i] = GUICtrlRead ($ValCoefficient[$i])
  99.     Next
  100.     Return $Ret
  101. EndFunc
  102.  
  103. Func _CreateGraph ()
  104.     Local $Read = GUICtrlRead ($List1) -1
  105.     Global $Graphic[5]
  106.     $Graphic[1] = GUICtrlCreateGraphic (60, 250, 1, 110)
  107.     GUICtrlSetColor (-1, 0x000000)
  108.     $Graphic[2] = GUICtrlCreateGraphic (100+16*$Read+24*($Read-1)-4, 250, 1, 110)
  109.     GUICtrlSetColor (-1, 0x000000)
  110.     $Graphic[3] = GUICtrlCreateGraphic (25, 322, 35, 1)
  111.     GUICtrlSetColor (-1, 0x000000)
  112.     $Graphic[4] = GUICtrlCreateGraphic (60, 322, 65+30*$Read+12*($Read-1), 1)
  113.     GUICtrlSetColor (-1, 0x000000)
  114. EndFunc
  115.  
  116. Func _CreateInLineInput ()
  117.     $NumCoeff = GUICtrlRead ($List1)+1
  118.     Global $InputFirstLine[$NumCoeff]
  119.     Global $InputScndLine[$NumCoeff]
  120.     Global $InputThrdLine[$NumCoeff]
  121.     For $i = 1 To $NumCoeff-2
  122.         $InputFirstLine[$i] = GUICtrlCreateInput ($Read[$i], 30+$i*40, 250, 30, 20)
  123.     Next
  124.     $InputFirstLine[$NumCoeff-1] = GUICtrlCreateInput ($Read[$i], 42+$i*40, 250, 30, 20)
  125.     $InputScndLine[1] = GUICtrlCreateInput (GUICtrlRead ($Input7), 25, 290, 30, 20)
  126.     For $i = 2 To $NumCoeff-2
  127.         $InputScndLine[$i] = GUICtrlCreateInput ("", 30+$i*40, 290, 30, 20)
  128.     Next
  129.     $InputScndLine[$NumCoeff-1] = GUICtrlCreateInput ("", 42+$i*40, 290, 30, 20)
  130.     For $i = 1 To $NumCoeff-2
  131.         $InputThrdLine[$i] = GUICtrlCreateInput ("", 30+$i*40, 330, 30, 20)
  132.     Next
  133.     $InputThrdLine[$NumCoeff-1] = GUICtrlCreateInput ("", 42+$i*40, 330, 30, 20)
  134. EndFunc
  135.  
  136. Func _Calc ()
  137.     GUICtrlSetData ($InputThrdLine[1], $Read[1])
  138.     $NumCoeff = GUICtrlRead ($List1)
  139.     For $i = 1 To $NumCoeff-1
  140.         GUICtrlSetData ($InputScndLine[$i+1], GUICtrlRead ($Input7)*GUICtrlRead ($InputThrdLine[$i]))
  141.         GUICtrlSetData ($InputThrdLine[$i+1], GUICtrlRead ($InputFirstLine[$i+1])+GUICtrlRead ($InputScndLine[$i+1]))
  142.     Next
  143. EndFunc
  144.  
  145. Func _GetResultPoly ()
  146.     $NumCoeff = GUICtrlRead ($List1)
  147.     Local $Ret
  148.     Local $Array[$NumCoeff+1]
  149.     For $i = 1 To $NumCoeff
  150.         $Array[$i] = GUICtrlRead ($InputThrdLine[$i])
  151.     Next
  152.     For $i = 1 To $NumCoeff-1
  153.         $Ret = $Ret & $Array[$i] & "x^" & $NumCoeff-$i & "+"
  154.     Next
  155.     $Ret = $Ret & $Array[$NumCoeff-1] & " Resto:" & $Array[$NumCoeff]
  156. Return $Ret
  157. EndFunc
  158. #EndRegion Funcs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement