kvadratické rovnice v3
java
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 kvdratickerovnice
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
tbhelp.Visible = false;
}
double a;
double b;
double c;
double d;
double x1;
double x2;
double d1;
double odmocninad;
private void atb_TextChanged(object sender, EventArgs e)
{
resenitb.Text = "";
dtb.Text = "";
odmocninadtb.Text = "";
x1tb.Text = "";
x2tb.Text = "";
if (atb.Text == "-")
{
}
//uložení proměnné a
else if (atb.Text != "")
if (!double.TryParse(atb.Text, out a))
{
MessageBox.Show("Neplatné číslo!");
atb.Text = "";
}
if (a != 0 & b != 0 & c != 0)
{
vypocitatbutton.Enabled = true;
}
else
{
vypocitatbutton.Enabled = false;
}
}
private void btb_TextChanged(object sender, EventArgs e)
{
resenitb.Text = "";
dtb.Text = "";
odmocninadtb.Text = "";
x1tb.Text = "";
x2tb.Text = "";
if (btb.Text == "-")
{
} //uložení proměnné b
else if (btb.Text != "")
try
{
b = double.Parse(btb.Text);
}
catch
{
MessageBox.Show("Neplatné číslo!");
btb.Text = "";
}
if (a != 0 & b != 0 & c != 0)
{
vypocitatbutton.Enabled = true;
}
else
{
vypocitatbutton.Enabled = false;
}
}
private void ctb_TextChanged(object sender, EventArgs e)
{
resenitb.Text = "";
dtb.Text = "";
odmocninadtb.Text = "";
x1tb.Text = "";
x2tb.Text = "";
if (ctb.Text == "-") //uložení proměnné c
{
}
else if (ctb.Text != "")
try
{
c = double.Parse(ctb.Text);
}
catch
{
MessageBox.Show("Neplatné číslo!");
ctb.Text = "";
}
if (a != 0 & b != 0 & c != 0)
{
vypocitatbutton.Enabled = true;
}
else
{
vypocitatbutton.Enabled = false;
}
}
private void nulovanibutton_Click(object sender, EventArgs e)
{
atb.Text = ""; //tlačítko vynulovat
btb.Text = "";
ctb.Text = "";
resenitb.Text = "";
dtb.Text = "";
x1tb.Text = "";
x2tb.Text = "";
odmocninadtb.Text = "";
a = 0;
b = 0;
c = 0;
d = 0;
d1 = 0;
x1 = 0;
x2 = 0;
vypocitatbutton.Enabled = false;
}
private void vypocitatbutton_Click(object sender, EventArgs e)
{
d1 = Math.Pow(b, 2.0);
d = d1 - (4 * (a) * (c));
dtb.Text = d.ToString();
odmocninad = Math.Sqrt(d);
odmocninadtb.Text = odmocninad.ToString();
if (d < 0)
{
resenitb.Text = "0";
x1tb.Text = "NENÍ";
x2tb.Text = "NENÍ";
odmocninadtb.Text = "NENÍ";
}
else if (d == 0)
{
resenitb.Text = "1";
x1 = (-(b) + odmocninad) / (2 * a);
x2tb.Text = "NENÍ";
x1tb.Text = x1.ToString();
}
else if (d > 0)
{
resenitb.Text = "2";
x1 = (-b + odmocninad) / (2 * a);
x2 = (-b - odmocninad) / (2 * a);
x1tb.Text = x1.ToString();
x2tb.Text = x2.ToString();
}
}
private void button1_Click(object sender, EventArgs e)
{
tbhelp.Visible = true;
hidebtn.Visible = true;
}
private void hidebtn_Click(object sender, EventArgs e)
{
tbhelp.Visible = false;
hidebtn.Visible = false;
}
}
}
Neformátovaný
Přidáno: 13.11.2013
Expirace: Neuvedeno