Advertisement
Guest User

adolf

a guest
May 30th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace WindowsFormsApplication5
  11. {
  12. public partial class Form1 : Form
  13. {
  14. Form2 f2 = new Form2();
  15. public Form1()
  16. {
  17. InitializeComponent();
  18. }
  19. public double a, b, c, d, x1, x2, p, q, x, i;
  20.  
  21.  
  22.  
  23.  
  24. internal void button1_Click(object sender, EventArgs e)
  25. {
  26. try
  27. {
  28.  
  29. a = double.Parse(textBox1.Text);
  30. if (a == 0)
  31. {
  32. textBox4.Text = "A musi byc rozne od 0";
  33. }
  34. else
  35. {
  36. b = double.Parse(textBox2.Text);
  37. c = double.Parse(textBox3.Text);
  38. d = Math.Pow(b, 2) - 4 * a * c;
  39. p = -b / 2 * a;
  40. q = -d / 4 * a;
  41.  
  42. if (d >= 0)
  43. {
  44.  
  45. x1 = -b - Math.Sqrt(d) / (2 * a);
  46. x2 = -b + Math.Sqrt(d) / (2 * a);
  47. textBox4.Text = "Delta =" + d.ToString()+ Environment.NewLine;
  48. textBox4.Text += "x1=" + x1.ToString() + " x2=" + x2.ToString() + Environment.NewLine;
  49. textBox4.Text += "p=" + p.ToString() + " q=" + q.ToString() + Environment.NewLine;
  50. textBox4.Text += "Postac ogolna f(x)=" + a.ToString() + "x^2+" + b.ToString() + "x+" + c.ToString() + Environment.NewLine;
  51. textBox4.Text += "Postac iloczynowa: f(x)=" + a.ToString() + "(x-(" + x1.ToString() + "))(x-(" + x2.ToString() + "))" + Environment.NewLine;
  52. textBox4.Text += "Postac kanoniczna: f(x)=" + a.ToString() + "(x-(" + p.ToString() + "))^2+" + q.ToString() + Environment.NewLine;
  53.  
  54. }
  55.  
  56.  
  57. else
  58. {
  59. if (f2.getOption1())
  60. {
  61. x = -b / 2 * a;
  62. i = Math.Sqrt(Math.Abs(d)) / (2 * a);
  63. textBox4.Text = "Delta =" + d.ToString() + Environment.NewLine;
  64. textBox4.Text += "x1=" + x.ToString() + "+j" + i.ToString() + Environment.NewLine;
  65. textBox4.Text += "x2=" + x.ToString() + "-j" + i.ToString() + Environment.NewLine;
  66. textBox4.Text += "Postac ogolna f(x)=" + a.ToString() + "x^2+" + b.ToString() + "x+" + c.ToString() + Environment.NewLine;
  67. textBox4.Text += "Postac iloczynowa: f(x)=" + a.ToString() + "(x-(" + x.ToString() + ")+j" + i.ToString() + ")(x-(" + x.ToString() + ")-j" + i.ToString() + ")" + Environment.NewLine;
  68. textBox4.Text += "Postac kanoniczna: f(x)=" + a.ToString() + "(x-(" + p.ToString() + "))^2+" + q.ToString() + Environment.NewLine;
  69. }
  70. else
  71. {
  72. textBox4.Text = "Delta =" + d.ToString() + Environment.NewLine;
  73. textBox4.Text +="Delta jest ujemna, brak rozwiazan";
  74.  
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81. }
  82.  
  83.  
  84.  
  85.  
  86. }
  87. }
  88. catch
  89. {
  90.  
  91. textBox4.Text = "Wprowadz poprawne dane";
  92.  
  93. }
  94.  
  95.  
  96. }
  97.  
  98.  
  99.  
  100. internal void button2_Click(object sender, EventArgs e)
  101. {
  102.  
  103. f2.ShowDialog();
  104.  
  105.  
  106.  
  107. }
  108.  
  109. private void Form1_Load(object sender, EventArgs e)
  110. {
  111.  
  112. }
  113.  
  114. private void label2_Click(object sender, EventArgs e)
  115. {
  116.  
  117. }
  118.  
  119. private void label3_Click(object sender, EventArgs e)
  120. {
  121.  
  122. }
  123.  
  124.  
  125.  
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement