Lập trinh C++ code máy tính bỏ túi - Pdf 28

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//lyvantuan//mangmaytinh
namespace MayTinh2
{
public partial class Form1 : Form
{
public bool clickBang = false;
public string ketQua="";
public double x, y,z, x1, x2,min;

public double a1 = 0, b1 = 0, c1 = 0,d1=0, a2 = 0, b2 = 0, c2 =
0,d2=0,a3=0,b3=0,c3=0,d3=0;
public double a = 0, b = 0, c = 0;
public int mode = 1;
public int ngoacTrai = 0;
public int ngoacPhai = 0;
public const double PI = 3.141592654;
public const double E = 2.718281828;
public Form1()
{
InitializeComponent();
}
public double tinhTich(string str)
{
double tich = 0;

}
if (dau == "/")
{
tich = tich / double.Parse(s3);
continue;
}
}
return tich;
}
public double tinhKetQua(string str)
{
int l = str.Length;
double result = 0;
while (l > 0)
{
string s1 = "";
string dau = "";
string s = str.Substring(l - 1, 1);
while (s != "+" && s != "-" && s != "*" && s != "/" && l > 0)
{
s1 = str.Substring(l - 1, 1) + s1;
l ;
if (l == 0) break;
s = str.Substring(l - 1, 1);
}
if (l == 0)
dau = "";
else
dau = str.Substring(l - 1, 1);
if (dau == "")

d = str.Substring(l - 1, 1);
if (d == "+")
{
result += tinhTich(str_s2);
l ;
}
if (d == "-")
{
result -= tinhTich(str_s2);
l ;
}
}
}
return result;
}
public string DaoDau(string str)
{
string result = "";
int i = str.Length - 1;
while (i >= 0)
{
result += str.Substring(i, 1);
i ;
}
return result;
}
public string chuoiCongVoiNgoacCoDauTru(string str)
{
string result = "";
int i = 0;

}
public string chuoiNhanVoiNgoacCoDauTru(string str)
{
if (str.Substring(0, 1) != "+" && str.Substring(0, 1) != "-")
str = "+" + str;
string result = "";
int i = str.Length - 1;
while (i >= 0)
{
if (str.Substring(i, 1) == "-" && i > 0 && (str.Substring(i -
1, 1) == "*" || str.Substring(i - 1, 1) == "/"))
{
string chuoitam = str.Substring(i - 1, 1);//Lay dau nhan
hoac chia
int vitridaunhan = i - 1;
i = i - 2;//Vuot qua dau tru,nhan
//Tim vi tri dau + or -gan nhat
//
while ((str.Substring(i, 1) != "+" && str.Substring(i,
1) != "-") && i > 0)
{
chuoitam += str.Substring(i, 1);
i ;
}
//MessageBox.Show("Vi tri do la " + i);
//Khi gap dau +/-
string dau;
if (str.Substring(i, 1) == "-")
dau = "+";
else

s = XuLyNgoac(str, l);
str = s + ketQua;
l = str.Length;
ketQua = "";
}
else
{
if (str.Substring(l - 1, 1) == "(")
{
return (str.Substring(0, l - 1) +
tinhKetQua(chinhLaiDau(ketQua)).ToString());
}
ketQua = str.Substring(l - 1, 1) + ketQua;
l ;
}
}
return chinhLaiDau(ketQua);
}
public string XuLyChuoiCoSin(string str)
{
string result = "";
int i = 0;
while (i < str.Length)
{
//Xu ly Sin(9+3)
string chuoitam = "";
double sin, s;
if (str.Substring(i, 1) == "s" && str.Substring(i + 3, 1) ==
"(")
{

i++;
}
}
return result;
}
public string XuLyChuoiCoCos(string str)
{
string result = "";
int i = 0;
while (i < str.Length)
{
//Xu ly Sin(9+3)
string chuoitam = "";
double sin, s;
if (str.Substring(i, 1) == "c" && str.Substring(i + 3, 1) ==
"(")
{
//vuot qua sin(
i = i + 4;
int daumongoac = 1;
int daudongngoac = 0;
while (daumongoac != daudongngoac)
{
chuoitam += str.Substring(i, 1);
if (str.Substring(i, 1) == "(")
daumongoac++;
if (str.Substring(i, 1) == ")")
daudongngoac++;
i++;
}

double sin, s;
if (str.Substring(i, 1) == "t" && str.Substring(i + 3, 1) ==
"(")
{
//vuot qua sin(
i = i + 4;
int daumongoac = 1;
int daudongngoac = 0;
while (daumongoac != daudongngoac)
{
chuoitam += str.Substring(i, 1);
if (str.Substring(i, 1) == "(")
daumongoac++;
if (str.Substring(i, 1) == ")")
daudongngoac++;
i++;
}
//Lui lai sau
i ;
string u, v;
u = XuLyNgoac(chuoitam, chuoitam.Length);
v = chinhLaiDau(u);
s = tinhKetQua(v);
//Doi qua do
s = s * Math.PI / 180;
//u = double.Parse(s);
sin = Math.Tan(s);
result += sin.ToString();
//vuot qua )
i++;

s2 = chuoi.Substring(i + 1, 1);
if(s1=="1"||s1=="2"||s1=="3"||s1=="4"||s1=="5"||s1=="6"||
s1=="7"||s1=="8"||s1=="9"||s1=="0")
if (s2 == "s" || s2 == "c" || s2 == "t") return true;
if (s1 == ")")
if (s2 == "s" || s2 == "c" || s2 == "t") return true;
if(s1=="(")
if(s2==")") return true;
if (s1 == "/" || s1 == "*" || s1 == "+" || s1 == "-" || s1 ==
".")
if (s2 == "/" || s2 == "*" || s2 == "+" || s2 == "-" || s2
== ".") return true;
}
return false;
}
public string XuLyChuoi(string str)
{
string u, v, k;
k = XuLyChuoiCoSinCosTan(str);
u = XuLyNgoac(k, k.Length);
v = chinhLaiDau(u);
return v;
}
public double giaiHePhuongTrinhBacNhat2An(double a1, double b1, double
c1, double a2, double b2, double c2)
{
double d, d1, d2;
d = a1 * b2 - a2 * b1;
d1 = c1 * b2 - c2 * b1;
d2 = a1 * c2 - a2 * c1;

z = dz / d;
}
return 2;
}
public double giaiPhuongTrinhBacHai(double a, double b, double c)
{
double denta;
denta = b * b - 4 * a * c;
if (denta == 0)
{
x1 = -b / (2 * a);
return 1;
}
if (denta < 0)
return 0;
if (denta > 0)
{
x1 = -b + Math.Sqrt(denta) / (2 * a);
x2 = -b - Math.Sqrt(denta) / (2 * a);
}
return 2;
}
private void bt_0_Click(object sender, EventArgs e)
{
txt_pheptinh.Text = txt_pheptinh.Text + "0";
clickBang = false;
}
private void bt_1_Click(object sender, EventArgs e)
{
txt_pheptinh.Text = txt_pheptinh.Text + "1";

clickBang = false;
}
private void bt_8_Click(object sender, EventArgs e)
{
txt_pheptinh.Text = txt_pheptinh.Text + "8";
clickBang = false;
}
private void bt_9_Click(object sender, EventArgs e)
{
txt_pheptinh.Text = txt_pheptinh.Text + "9";
clickBang = false;
}
private void bt_cong_Click(object sender, EventArgs e)
{
if (clickBang == true)
{
txt_pheptinh.Text = ketQua;
clickBang = false;
}
txt_pheptinh.Text += "+";
}
private void bt_nhan_Click(object sender, EventArgs e)
{
if (clickBang == true)
{
txt_pheptinh.Text = ketQua;
clickBang = false;
}
txt_pheptinh.Text += "*";
}

{
txt_pheptinh.Text += ".";
clickBang = false;
}
private void bt_bang_Click(object sender, EventArgs e)
{
//Tinh toan cong tru nhan chia
if (mode == 1)
{
if (KiemTraLoiChuoi(txt_pheptinh.Text) == true)
{
txt_ketqua.Text = "Error";
return;
}
else
{
txt_ketqua.Text =
tinhKetQua(XuLyChuoi(txt_pheptinh.Text)).ToString();
ketQua = txt_ketqua.Text;
clickBang = true;
}
}
//giai he phuong trinh 2 an
if(mode==2)
{
if (txt_ketqua.Text == "nhap a1")
{
if (txt_pheptinh.Text == "")
{
a1 = 0;

}
if (txt_ketqua.Text == "nhap a2")
{
if (txt_pheptinh.Text == "")
{
a2 = 0;
return;
}
a2 = double.Parse(txt_pheptinh.Text);
txt_ketqua.Text = "nhap b2";
txt_pheptinh.Text = "";
return;
}
if (txt_ketqua.Text == "nhap b2")
{
if (txt_pheptinh.Text == "")
{
b2 = 0;
return;
}
b2 = double.Parse(txt_pheptinh.Text);
txt_ketqua.Text = "nhap c2";
txt_pheptinh.Text = "";
return;
}
if (txt_ketqua.Text == "nhap c2")
{
if (txt_pheptinh.Text == "")
{
c2 = 0;

if (txt_ketqua.Text == "nhap b")
{
b = double.Parse(txt_pheptinh.Text);
txt_ketqua.Text = "nhap c";
txt_pheptinh.Text = "";
return;
}
if (txt_ketqua.Text == "nhap c")
{
c = double.Parse(txt_pheptinh.Text);
txt_pheptinh.Text = "";
}
if (giaiPhuongTrinhBacHai(a, b, c) == 1)
{
txt_pheptinh.Text = "PT co 1 nghiem X1";
txt_ketqua.Text = x1.ToString();
}
if (giaiPhuongTrinhBacHai(a, b, c) == 0)
{
txt_pheptinh.Text = "PT vo nghiem";
}
if (giaiPhuongTrinhBacHai(a, b, c) == 2)
{
txt_pheptinh.Text = "PT Co 2 Nghiem x1,x2:";
txt_ketqua.Text = x1.ToString() + " " +
x2.ToString();
}
}
//Giai he phuong trinh bac nhat 3 an
if (mode == 4)

{
a2 = double.Parse(txt_pheptinh.Text);
txt_ketqua.Text = "nhap b2";
txt_pheptinh.Text = "";
return;
}
if (txt_ketqua.Text == "nhap b2")
{
b2 = double.Parse(txt_pheptinh.Text);
txt_ketqua.Text = "nhap c2";
txt_pheptinh.Text = "";
return;
}
if (txt_ketqua.Text == "nhap c2")
{
c2 = double.Parse(txt_pheptinh.Text);
txt_ketqua.Text = "nhap d2";
txt_pheptinh.Text = "";
return;
}
if (txt_ketqua.Text == "nhap d2")
{
d2 = double.Parse(txt_pheptinh.Text);
txt_ketqua.Text = "nhap a3";
txt_pheptinh.Text = "";
return;
}
if (txt_ketqua.Text == "nhap a3")
{
a3 = double.Parse(txt_pheptinh.Text);

{
txt_pheptinh.Text = "Nghiem cua HPT X,Y,Z:";
txt_ketqua.Text = "X=" + x.ToString() + " " + "Y=" +
y.ToString() + " " + "Z=" + z.ToString();
}
}
}
private void bt_sin_Click(object sender, EventArgs e)
{
txt_pheptinh.Text += "sin";
}
private void bt_cos_Click(object sender, EventArgs e)
{
txt_pheptinh.Text += "cos";
}
private void bt_tan_Click(object sender, EventArgs e)
{
txt_pheptinh.Text += "tan";
}
private void bt_mode_Click(object sender, EventArgs e)
{
if (mode == 5) mode = 0;
if (mode <= 4)
{
mode++;
textBox2.Text = mode.ToString();
}

}
private void bt_doiDau_Click(object sender, EventArgs e)
{
txt_pheptinh.Text += "-";
}
private void bt_ac_Click(object sender, EventArgs e)
{
clickBang = false;
if (mode == 1)
{
txt_pheptinh.Text = "";
txt_ketqua.Text = "";
}
if (mode == 2)
{
txt_pheptinh.Text = "";
txt_ketqua.Text = "nhap a1";
}
if (mode == 3)
{
txt_ketqua.Text = "nhap a";
txt_pheptinh.Text = "";
}
if (mode == 4)
{
txt_ketqua.Text = "nhap a1";
txt_pheptinh.Text = "";
}
}
private void bt_DEL_Click(object sender, EventArgs e)

}
private void bt_back_Click(object sender, EventArgs e)
{
txt_pheptinh.Select();
SendKeys.Send("{LEFT}");
}
private void bt_next_Click(object sender, EventArgs e)
{
txt_pheptinh.Select();
SendKeys.Send("{RIGHT}");
}
private void bt_off_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void panel5_Paint(object sender, PaintEventArgs e)
{
}
private void txt_pheptinh_MaskInputRejected(object sender,
MaskInputRejectedEventArgs e)
{
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{


Nhờ tải bản gốc
Music ♫

Copyright: Tài liệu đại học © DMCA.com Protection Status