/// <summary> /// Cộng 2 số phức /// </summary> /// <param name="soPhuc">Số phức cần cộng</param> /// <returns>Kết quả tổng của số phức hiện tại và số phức truyền vào.</returns> public SoPhuc Cong(SoPhuc soPhuc) { SoPhuc ketQua = new SoPhuc(); ketQua.A = this.A + soPhuc.A; ketQua.B = this.B + soPhuc.B; return(ketQua); }
static void Main(string[] args) { SoPhuc sp = new SoPhuc(3, -2); SoPhuc sp2 = new SoPhuc(2, -3); Console.Write("cong: " + (sp + sp2).ToString() + "\n"); Console.Write("Tru: " + (sp - sp2).ToString() + "\n"); Console.Write("Nhan: " + (sp * sp2).ToString() + "\n"); Console.Write("Chia: " + (sp / sp2).ToString() + "\n"); Console.ReadKey(); }
public void sort() { for (int i = 0; i < this.n - 1; i++) { for (int j = i + 1; j < this.n; j++) { if (this.arrSP[i] < this.arrSP[j]) { SoPhuc temp = this.arrSP[i]; this.arrSP[i] = this.arrSP[j]; this.arrSP[j] = temp; } } } }
private void bntTinh_Click(object sender, EventArgs e) { int thuc1= int.Parse(this.textBox1.Text); int ao1= int.Parse(this.textBox2.Text); int thuc2= int.Parse(this.textBox3.Text); int ao2= int.Parse(this.textBox4.Text); SoPhuc a =new SoPhuc(thuc1,ao1); SoPhuc b=new SoPhuc(thuc2,ao2); SoPhuc p; if(radioButton1.Checked) p = a + b; else if(radioButton1.Checked) p = a - b; else if(radioButton1.Checked) p = a * b; else p = a / b; textBox5.Text = p.Thuc.ToString(); textBox6.Text = p.Ao.ToString(); }
static void Main(string[] args) { Console.WriteLine("Nhap vao so phuc thu nhat: "); Console.Write("Phan thuc = "); Double r1 = Double.Parse(Console.ReadLine()); Console.Write("Phan ao = "); Double i1 = Double.Parse(Console.ReadLine()); SoPhuc sp1 = new SoPhuc(r1, i1); Console.WriteLine("Nhap vao so phuc thu hai: "); Console.Write("Phan thuc = "); Double r2 = Double.Parse(Console.ReadLine()); Console.Write("Phan ao = "); Double i2 = Double.Parse(Console.ReadLine()); SoPhuc sp2 = new SoPhuc(r2, i2); Console.WriteLine("Tong 2 so phuc da nhap la: "); sp1.Print(); Console.Write(" + "); sp2.Print(); Console.Write(" = "); sp1.Add(sp2).Print(); Console.WriteLine("\nHieu 2 so phuc da nhap la: "); sp1.Print(); Console.Write(" - "); sp2.Print(); Console.Write(" = "); sp1.Sub(sp2).Print(); Console.ReadLine(); }
public void In(SoPhuc p) { Console.WriteLine("Phan thuc: " + p.thuc); Console.WriteLine("Phan ao: " + p.ao); }
public static SoPhuc operator /(SoPhuc a, SoPhuc b) { SoPhuc p = new SoPhuc((a.thuc * b.thuc + a.ao * b.ao) / (b.thuc * b.thuc + b.ao * b.ao), (a.ao * b.thuc - a.thuc * b.ao) / (b.thuc * b.thuc + b.ao * b.ao)); return p; }
public static SoPhuc operator -(SoPhuc a, SoPhuc b) { SoPhuc p = new SoPhuc(a.thuc - b.thuc, a.ao - b.ao); return p; }
public static SoPhuc operator *(SoPhuc a, SoPhuc b) { SoPhuc p = new SoPhuc(a.thuc * b.thuc - a.ao * b.ao, a.thuc * b.ao + b.thuc * a.ao); return p; }