Kvadratické rovnice
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)
{
if (atb.Text != "") //uložení proměnné a
{
try
{
a = double.Parse(atb.Text);
}
catch
{
MessageBox.Show("Neplatné číslo!");
atb.Text = "";
}
}
}
private void btb_TextChanged(object sender, EventArgs e)
{
if (btb.Text != "") //uložení proměnné b
{
try
{
b = double.Parse(btb.Text);
}
catch
{
MessageBox.Show("Neplatné číslo!");
btb.Text = "";
}
}
}
private void ctb_TextChanged(object sender, EventArgs e)
{
if (ctb.Text != "") //uložení proměnné c
{
try
{
c = double.Parse(ctb.Text);
}
catch
{
MessageBox.Show("Neplatné číslo!");
ctb.Text = "";
}
}
}
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;
azapor.Checked = false;
bzapor.Checked = false;
czapor.Checked = false;
vypocitatbutton.Enabled = true;
}
private void vypocitatbutton_Click(object sender, EventArgs e)
{
if (azapor.Checked)
{
a = 0 - a;
}
if (bzapor.Checked)
{
b = 0 - b;
}
if (czapor.Checked)
{
c = 0 - c;
}
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();
}
a = 0; //vynuluje všechny proměnné po vypočítání
b = 0;
c = 0;
d = 0;
d1 = 0;
x1 = 0;
x2 = 0;
vypocitatbutton.Enabled = false;
}
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: 9.11.2013
Expirace: Neuvedeno