public SoPhuc Tong(SoPhuc t2) { SoPhuc tmp = new SoPhuc(); tmp.thuc = this.thuc + t2.thuc; tmp.ao = this.ao + t2.ao; return(tmp); }
public SoPhuc Hieu(SoPhuc t2) { SoPhuc tmp = new SoPhuc(); tmp.thuc = this.thuc - t2.thuc; tmp.ao = this.ao - t2.ao; return(tmp); }
public static SoPhuc operator +(SoPhuc t1, SoPhuc t2) { SoPhuc tmp = new SoPhuc(); tmp.thuc = t1.thuc + t2.thuc; tmp.ao = t1.ao + t2.ao; return(tmp); }
static void Main() { SoPhuc t1 = new SoPhuc(5, 8); SoPhuc t2 = new SoPhuc(t1); Console.WriteLine("So phuc thu nhat"); t1.Hien(); Console.WriteLine("So phuc thu hai"); t2.Hien(); SoPhuc t3 = t1 + t2;//t1.Tong(t2); Console.WriteLine("So phuc tong"); t3.Hien(); Console.ReadLine(); }
static void Main(string[] args) { SoPhuc a = new SoPhuc(); a.nhap(); a.xuat(); SoPhuc b = new SoPhuc(); b.nhap(); b.xuat(); Console.WriteLine("\n===================================================="); SoPhuc c = a + b; Console.WriteLine("\nKet qua phep cong 2 so phuc vua nhap: " + c.ToString()); SoPhuc d = a - b; Console.WriteLine("Ket qua phep tru 2 so phuc vua nhap: " + d.ToString()); SoPhuc e = a * b; Console.WriteLine("Ket qua phep nhan 2 so phuc vua nhap: " + e.ToString()); SoPhuc f = a / b; Console.WriteLine("Ket qua phep chia 2 so phuc vua nhap: " + f.ToString()); Console.WriteLine("\n===================================================="); Console.WriteLine("Kiem tra so phuc la so thuc hay so thuan ao!!!"); SoPhuc g = new SoPhuc(); g.nhap(); g.xuat(); if (!(bool)g) { Console.WriteLine("So phuc nay la so thuc!!!"); } else { Console.WriteLine("So phuc nay la so thuan ao!!!"); } Console.WriteLine("\n===================================================="); Console.WriteLine("So sanh 2 so phuc!!!"); SoPhuc h = new SoPhuc(); h.nhap(); h.xuat(); SoPhuc k = new SoPhuc(); k.nhap(); k.xuat(); Console.WriteLine("Hai so phuc bang nhau: {0}", h == k); Console.WriteLine("Hai so phuc khac nhau: {0}", h != k); Console.ReadLine(); }
public void PhepTinh_Cong2SoPhuc_TraVeTong() { // --Arrange var sp1 = new SoPhuc(1, 2); var sp2 = new SoPhuc(3, 4); var expected = new SoPhuc(4, 6); // --Act var actual = sp1 + sp2; // --Assert Assert.True(expected == actual); }
public void PhepTinh_Nhan2SoPhuc_TraVeTich() { // --Arrange var sp1 = new SoPhuc(1, 2); var sp2 = new SoPhuc(3, 4); var expected = new SoPhuc(-5, 10); // --Act var actual = sp1 * sp2; // --Assert Assert.True(expected == actual); }
public void PhepTinh_Tru2SoPhuc_TraVeHieu() { // --Arrange var sp1 = new SoPhuc(1, 2); var sp2 = new SoPhuc(3, 4); var expected = new SoPhuc(-2, -2); // --Act var actual = sp1 - sp2; // --Assert Assert.True(expected == actual); }
static void Main(string[] args) { SoPhuc a = new SoPhuc(); SoPhuc b = new SoPhuc(3, 4); SoPhuc c = new SoPhuc(); a.NhapSoPhuc(); Console.Write("So phuc a "); a.XuatSoPhuc(); Console.Write("So phuc b "); b.XuatSoPhuc(); c = a + b; Console.WriteLine("-----------------------------------------------------------------"); Console.WriteLine("Cong 2 so phuc"); c.XuatSoPhuc(); c = a - b; Console.WriteLine("-----------------------------------------------------------------"); Console.WriteLine("Tru 2 so phuc"); c.XuatSoPhuc(); c = a * b; Console.WriteLine("-----------------------------------------------------------------"); Console.WriteLine("Nhan 2 so phuc"); c.XuatSoPhuc(); c = a / b; Console.WriteLine("-----------------------------------------------------------------"); Console.WriteLine("Chia 2 so phuc"); c.XuatSoPhuc(); Console.WriteLine("-----------------------------------------------------------------"); if (a == b) { Console.WriteLine("Hai so phuc a va b bang nhau"); } else { Console.WriteLine("Hai so phuc ava b khac nhau"); } Console.WriteLine("-----------------------------------------------------------------"); a.Kiemtra(); Console.WriteLine("-----------------------------------------------------------------"); b.Kiemtra(); }
static void Main(string[] args) { SoPhuc sp1 = new SoPhuc(); SoPhuc sp2 = new SoPhuc(); SoPhuc sp3 = new SoPhuc(); Console.WriteLine("=======VUI LONG NHAP VAO CAC SO PHUC======="); Console.WriteLine(""); Console.WriteLine("-So phuc thu nhat"); Console.WriteLine(""); sp1.nhap(); sp1.xuat(); Console.WriteLine(""); Console.WriteLine("=================="); Console.WriteLine(""); Console.WriteLine("-So phuc thu hai"); Console.WriteLine(""); sp2.nhap(); sp2.xuat(); Console.WriteLine("=================="); Console.WriteLine("Tong cua 2 so phuc la : "); sp3 = sp1 + sp2; sp3.xuat(); Console.WriteLine("=================="); Console.WriteLine("Hieu cua 2 so phuc la : "); sp3 = sp1 - sp2; sp3.xuat(); Console.WriteLine("=================="); Console.WriteLine("Tich cua 2 so phuc la : "); sp3 = sp1 * sp2; sp3.xuat(); Console.WriteLine("=================="); Console.WriteLine("Thuong cua 2 so phuc la : "); sp3 = sp1 / sp2; sp3.xuat(); Console.ReadLine(); }
public SoPhuc(SoPhuc t2) { this.thuc = t2.thuc; this.ao = t2.ao; }