Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- namespace lab2_gr2
- {
- public partial class Okno : Form
- {
- public Okno()
- {
- InitializeComponent();
- }
- /// <summary>
- /// Metoda zamykająca program.
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void Zamknij_Click(object sender, EventArgs e)
- {
- Close();
- }
- private void Oblicz_Click(object sender, EventArgs e)
- {
- string [] wynik = string
- float delta = Licz.LiczDelte(float.Parse(A.Text),float.Parse(B.Text),float.Parse(C.Text));
- if (delta==0)
- {
- wynik.Text = "Równanie kwadratowe ma wyniki:";
- wynikx1.Text=" x1 = "+Licz.LiczX(true, a, b, delta);
- }
- if (delta > 0)
- {
- wynik.Text = "Równanie kwadratowe ma wyniki:";
- wynikx1.Text=" x1 = "+Licz.LiczX(true, a, b, delta);
- wynikx2.Text=" x2 = "+Licz.LiczX(false, a, b, delta);
- }
- else
- {
- wynik.Text = "Równanie kwadratowe nie ma rozwiązań rzeczywistych.";
- }
- group_wyniki.Visible = true;
- }
- private void A_TextChanged(object sender, EventArgs e)
- {
- TextBox kon = (TextBox)sender;
- //if (kon.Text.Length == 1 && ((kon.Text. < '0') || (kon.Text > '9')))
- //{
- // kon.Text = "";
- //}
- //else
- {
- if ((kon.Text[kon.Text.Length - 1] < '0') || (kon.Text[kon.Text.Length - 1] > '9'))
- {
- kon.Text = kon.Text.Remove(kon.Text.Length - 1);
- kon.SelectionStart = kon.Text.Length;
- Oblicz.Enabled = false;
- group_wyniki.Visible = false;
- }
- else
- {
- Oblicz.Enabled = true;
- }
- }
- }
- class Licz
- {
- public static float LiczDelte(float a, float b, float c)
- {
- return (b * b) - 4 * a * c;
- }
- /// <summary>
- /// Metoda oblicza X1 lub X2 w zaleznosci od podanego pierwszego argumentu
- /// true => x1
- /// false => x2
- /// </summary>
- /// <param name="jeden"></param>
- /// <param name="a"></param>
- /// <param name="b"></param>
- /// <param name="c"></param>
- /// <param name="delta"></param>
- /// <returns></returns>
- public static float LiczX(bool jeden, float a, float b, float delta)
- {
- if (jeden == true)
- {
- return (float)((-b - Math.Sqrt(delta)) / (2 * a));
- }
- else
- {
- return (float)((-b + Math.Sqrt(delta)) / (2 * a));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment