pawelkl

pierwkwad

Mar 23rd, 2011
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 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 lab2_gr2
  11. {
  12.     public partial class Okno : Form
  13.     {
  14.         public Okno()
  15.         {
  16.             InitializeComponent();
  17.         }
  18.         /// <summary>
  19.         /// Metoda zamykająca program.
  20.         /// </summary>
  21.         /// <param name="sender"></param>
  22.         /// <param name="e"></param>
  23.         private void Zamknij_Click(object sender, EventArgs e)
  24.         {
  25.             Close();
  26.         }
  27.  
  28.         private void Oblicz_Click(object sender, EventArgs e)
  29.         {
  30.            
  31.            
  32.             string [] wynik = string
  33.  
  34.             float delta = Licz.LiczDelte(float.Parse(A.Text),float.Parse(B.Text),float.Parse(C.Text));
  35.  
  36.             if (delta==0)
  37.             {
  38.                 wynik.Text = "Równanie kwadratowe ma wyniki:";
  39.                 wynikx1.Text=" x1 = "+Licz.LiczX(true, a, b, delta);
  40.             }
  41.             if (delta > 0)
  42.             {
  43.                 wynik.Text = "Równanie kwadratowe ma wyniki:";
  44.                 wynikx1.Text=" x1 = "+Licz.LiczX(true, a, b, delta);
  45.                 wynikx2.Text=" x2 = "+Licz.LiczX(false, a, b, delta);
  46.             }
  47.             else
  48.             {
  49.                 wynik.Text = "Równanie kwadratowe nie ma rozwiązań rzeczywistych.";
  50.             }
  51.  
  52.             group_wyniki.Visible = true;
  53.         }
  54.  
  55.         private void A_TextChanged(object sender, EventArgs e)
  56.         {
  57.             TextBox kon = (TextBox)sender;
  58.             //if (kon.Text.Length == 1 && ((kon.Text. < '0') || (kon.Text > '9')))
  59.             //{
  60.             //    kon.Text = "";
  61.             //}
  62.             //else
  63.             {
  64.                 if ((kon.Text[kon.Text.Length - 1] < '0') || (kon.Text[kon.Text.Length - 1] > '9'))
  65.                 {
  66.                     kon.Text = kon.Text.Remove(kon.Text.Length - 1);
  67.                     kon.SelectionStart = kon.Text.Length;
  68.                     Oblicz.Enabled = false;
  69.                     group_wyniki.Visible = false;
  70.                 }
  71.                 else
  72.                 {
  73.                     Oblicz.Enabled = true;
  74.                 }
  75.             }
  76.         }
  77.         class Licz
  78.         {
  79.             public static float LiczDelte(float a, float b, float c)
  80.             {
  81.                 return (b * b) - 4 * a * c;
  82.             }
  83.             /// <summary>
  84.             /// Metoda oblicza X1 lub X2 w zaleznosci od podanego pierwszego argumentu
  85.             /// true => x1
  86.             /// false => x2
  87.             /// </summary>
  88.             /// <param name="jeden"></param>
  89.             /// <param name="a"></param>
  90.             /// <param name="b"></param>
  91.             /// <param name="c"></param>
  92.             /// <param name="delta"></param>
  93.             /// <returns></returns>
  94.             public static float LiczX(bool jeden, float a, float b, float delta)
  95.             {
  96.                 if (jeden == true)
  97.                 {
  98.                     return (float)((-b - Math.Sqrt(delta)) / (2 * a));
  99.                 }
  100.                 else
  101.                 {
  102.                     return (float)((-b + Math.Sqrt(delta)) / (2 * a));
  103.                 }
  104.             }
  105.         }
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment