Advertisement
Guest User

PT2

a guest
Jul 31st, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 2.43 KB | None | 0 0
  1. #include <ButtonConstants.au3>
  2. #include <EditConstants.au3>
  3. #include <GUIConstantsEx.au3>
  4. #include <StaticConstants.au3>
  5. #include <WindowsConstants.au3>
  6. #include <ListViewConstants.au3>
  7.  
  8. #Region ### START Koda GUI section ### Form=
  9. $Form1 = GUICreate("Giải phương trình bậc 2", 300, 246)
  10. GuiSetIcon (@SystemDir & "\mspaint.exe" , 0)
  11. $Label1 = GUICtrlCreateLabel("Nhập a:", 20, 35, 40, 17)
  12. $Label2 = GUICtrlCreateLabel("Nhập b:", 20, 62, 40, 17)
  13. $Label3 = GUICtrlCreateLabel("Nhập c:", 20, 93, 40, 17)
  14. $Label4 = GUICtrlCreateLabel("Phương trình có dạng: ax^2 + bx + c = 0", 16, 8, 194, 17)
  15. $Input1 = GUICtrlCreateInput("", 63, 34, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
  16. $Input2 = GUICtrlCreateInput("", 64, 62, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
  17. $Input3 = GUICtrlCreateInput("", 63, 90, 73, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER))
  18. $Button1 = GUICtrlCreateButton("Let's go", 163, 62, 113, 25, $BS_DEFPUSHBUTTON)
  19. $Label5 = GUICtrlCreateLabel("Phương trình có nghiệm:", 24, 128,200, 17)
  20. $ListView1 = GUICtrlCreateListView("a|b|c|x1|x2", 24, 144, 255, 81)
  21. GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 0, 50)
  22. GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 1, 50)
  23. GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 2, 50)
  24. GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 3, 50)
  25. GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 4, 50)
  26. $Label7 = GUICtrlCreateLabel("", 144, 35, 200, 17)
  27. GUISetState(@SW_SHOW)
  28. #EndRegion ### END Koda GUI section ###
  29. While 1
  30.     $nMsg = GUIGetMsg()
  31.     Switch $nMsg
  32.     Case $GUI_EVENT_CLOSE
  33.             Exit
  34.          Case $Button1
  35.             b()
  36.     EndSwitch
  37. WEnd
  38. Func pt()
  39.     $a = GUICtrlRead($Input1)
  40.     $b = GUICtrlRead($Input2)
  41.     $c = GUICtrlRead($Input3)
  42.     $denta = ($b^2) - 4*$a*$c
  43.     $x1 = ((-$b) + Sqrt($denta)) / (2*$a)
  44.     $x2 = ((-$b) - Sqrt($denta)) / (2*$a)
  45.     GUICtrlSetData($label7,"")
  46.     If $denta < 0 Then
  47.         MsgBox (0, "Phương trình","Vô nghiệm!")
  48.         $x1 = ""
  49.         $x2 = ""
  50.     ElseIf $denta = 0 Then
  51.         MsgBox(0, "Phương trình","Có nghiệm kép x1 = x2 = " & $x1)
  52.     Else
  53.         MsgBox(0,"Phương trình","Có 2 nghiệm" & @CRLF & "x1 = " & $x1 & @CRLF & "x2 = " & $x2)
  54.     EndIf
  55.     GUICtrlCreateListViewItem($a & "|" & $b & "|" & $c & "|" & $x1 & "|" & $x2,$ListView1)
  56. EndFunc
  57. func b()
  58.     If GUICtrlRead($Input1) <> 0 And StringIsInt(GUICtrlRead($Input2)) And StringIsInt(GUICtrlRead($Input3)) Then
  59.         pt()
  60.     Else
  61.         GUICtrlSetData($label7,"a,b,c phải là số, a khác 0")
  62.     EndIf
  63. EndFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement