MohammadZaidan فريق هندسة الحواسب
الجنس : عدد المساهمات : 829
| موضوع: كلاس للتابع العقدي 1/6/2011, 20:53 | |
| - الكود:
-
using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication36 { class comp { double real; double image; public double Real { set { real = value; } get { return real; } } public double Image { set { image = value; } get { return image; } } public comp() { } public comp(double r, double i) { real = r; image = i; } public comp(comp c) { comp f = new comp(); real = c.real; image = c.image; } static public comp operator +(comp c1, comp c2) { comp temp = new comp(); temp.image = c1.image + c2.image; temp.real = c1.real + c2.real; return temp; } static public comp operator -(comp c1, comp c2) { comp temp = new comp(); temp.image = c1.image - c2.image; temp.real = c1.real - c2.real; return temp; } static public comp operator *(comp c1, comp c2) { comp temp = new comp(); temp.real = c1.real * c2.real + c1.image * c2.image; temp.image = c1.image * c2.real - c1.real * c2.image; return temp; } static public comp operator /(comp c1, comp c2) { comp temp = new comp(); temp.real = c1.real / c2.real + c1.image / c2.image; temp.image = c1.image / c2.real - c1.real / c2.image; return temp; } static public bool operator ==(comp c1, comp c2) { return ((c1.real == c2.real) == (c1.image == c2.image));
} static public bool operator !=(comp c1, comp c2) { return ((c1.real == c2.real) != (c1.image == c2.image));
} static public explicit operator double (comp c) { return c.real;
}
} class Program { static void Main(string[] args) { comp c1 = new comp(); Console.WriteLine(c1); comp c2 = new comp(2, 3); c1.Real = 5; c1.Image = 5; c2.Image = 4; c2.Real = 4; comp c3 = new comp(c1); Console.WriteLine(c3); c3 += c1; if (c1 == c2) Console.WriteLine("Equal"); else Console.WriteLine("non equal");
} } }
| |
|