public void TestMethod1() { PhanSo.PhanSo p1 = new PhanSo.PhanSo(2, 3); PhanSo.PhanSo p2 = new PhanSo.PhanSo(4, -6); bool actual = PhanSo.PhanSo.soSanh(p1, p2); bool expected = false; Assert.AreEqual(expected, actual); }
public void TestEquals() { PhanSo.PhanSo p1 = new PhanSo.PhanSo(2, 3); PhanSo.PhanSo p2 = new PhanSo.PhanSo(-4, -6); bool actual = PhanSo.PhanSo.soSanh(p1, p2); bool expected = true; Assert.AreEqual(expected, actual); }
public void TestFile() { int t1 = int.Parse(TestContext.DataRow[0].ToString()); int m1 = int.Parse(TestContext.DataRow[1].ToString()); int t2 = int.Parse(TestContext.DataRow[2].ToString()); int m2 = int.Parse(TestContext.DataRow[3].ToString()); bool expected = bool.Parse(TestContext.DataRow[4].ToString()); PhanSo.PhanSo p1 = new PhanSo.PhanSo(t1, m1); PhanSo.PhanSo p2 = new PhanSo.PhanSo(t2, m2); bool actual = PhanSo.PhanSo.soSanh(p1, p2); Assert.AreEqual(expected, actual); }
static void Main(string[] args) { Console.OutputEncoding = System.Text.Encoding.UTF8; var a = new PhanSo(3, 4); var b = new PhanSo(); b.Nhap(); // Lợi ích của việc override hàm ToString() Console.WriteLine($"{a} + {b} = {a + b}"); Console.WriteLine($"{a} - {b} = {a - b}"); Console.WriteLine($"{a} * {b} = {a * b}"); Console.WriteLine($"{a} / {b} = {a / b}"); }
public PhanSo Tru(PhanSo S1) { if (this.Tu != 0) { PhanSo ps1 = new PhanSo(); ps1.Tu = Tu * S1.Mau - Mau * S1.Tu; ps1.Mau = Mau * S1.Mau; return(ps1); } else { PhanSo ps = new PhanSo(); ps.Tu = -S1.Tu; ps.Mau = S1.Mau; return(ps); } }
static void Main(string[] args) { int a = 0, b = 0; PhanSo ps = new PhanSo(); tag: ps.Nhap(); ps.rutGon(); ps.Xuat(); Console.WriteLine("\nXin moi xhon chuc nang: "); Console.WriteLine("Bam 1 de cong phan so[a/b]"); Console.WriteLine("Bam 2 de tru phan so[a/b]"); Console.WriteLine("Bam 3 Exit."); Console.WriteLine("Hello World"); int choose = int.Parse(Console.ReadLine()); switch (choose) { case 1: Console.Write("\nNhap vao phan so: "); ps.NhapThem(ref a, ref b); ps.Cong(a, b); ps.rutGon(); ps.Xuat(); goto tag; break; case 2: Console.Write("\nNhap vao phan so: "); PhanSo ps1 = new PhanSo(); ps1.Nhap(); ps = ps.Tru(ps1); ps.rutGon(); ps.Xuat(); goto tag; break; case 3: break; } }
private void btnSoSanh_Click(object sender, EventArgs e) { int tu01 = int.Parse(txtTuSo01.Text); int mau01 = int.Parse(txtMauSo01.Text); int tu02 = int.Parse(txtTuSo02.Text); int mau02 = int.Parse(txtMauSo02.Text); PhanSo ps01 = new PhanSo(tu01, mau01); PhanSo ps02 = new PhanSo(tu02, mau02); if (PhanSo.sosanh(ps01, ps02) == true) { MessageBox.Show("Hai phân số bằng nhau!", "Thông báo"); } else { MessageBox.Show("Hai phân số không bằng nhau!", "Thông báo"); } }
private void button1_Click(object sender, EventArgs e) { int t1 = int.Parse(textBox1.Text); int m1 = int.Parse(textBox2.Text); int t2 = int.Parse(textBox3.Text); int m2 = int.Parse(textBox4.Text); PhanSo p1 = new PhanSo(t1, m1); PhanSo p2 = new PhanSo(t2, m2); if (PhanSo.soSanh(p1, p2) == true) { MessageBox.Show("Hai phan so bang nhau"); } else { MessageBox.Show("Hai phan so KHONG bang nhau"); } }