Xây dựng chương trình xử lý Số phức (complex) với các chức năng sau (dùng menu chọn): Menu complex

0 thích 0 không thích
21 lượt xem
đã hỏi 13 Tháng 12, 2017 bởi Nguyên Trần (120 điểm)
Đến đây là tịt có ai giúp e với ạ

class complex
        {
            private int realPart;
            private int imaginaryPart;
            public complex()
            {
                realPart = 0 ;
                imaginaryPart = 0;
            }
            public complex(int valreal, int valimaginary)
            {
                realPart = valreal;
                imaginaryPart = valimaginary;
            }
            public void Readcomplex()
            {
                Console.WriteLine("Enter realPart: ");
                realPart = int.Parse(Console.ReadLine());

                Console.Write("Enter imaginaryPart: ");
                imaginaryPart = int.Parse(Console.ReadLine());
            }
            public void PrintComplex()
            {
                Console.WriteLine(realPart + "+" + imaginaryPart + "i");
            }
            public void SetReal(int realVal)
            {
                realPart = realVal;
            }
            public void Setimaginary(int imaginaryVal)
            {
                imaginaryPart = imaginaryVal;
            }
            public void SetComplex(int realVal, int imaginaryVal)
            {
                realPart = realVal;
                imaginaryPart = imaginaryVal;
            }
            public int GetReal()
            {
                return realPart;
            }
            public int GetImaginary()
            {
                return imaginaryPart;
            }
            public complex GetComplex()
            {
                complex a = new complex();
                return a;
            }
            public void AddComplex(complex a, complex b)
            {
                realPart = a.realPart + b.realPart;
                imaginaryPart = a.imaginaryPart + b.imaginaryPart;
            }
            public static complex operator  +(complex a, complex b)
            {
                complex c = new complex();
                c.realPart = a.realPart + b.realPart;
                c.imaginaryPart = a.imaginaryPart + b.imaginaryPart;
                return c;
            }

            public void subComplex(complex a, complex b)
            {
                realPart = a.realPart - b.realPart;
                imaginaryPart = a.imaginaryPart - b.imaginaryPart;
            }

            public static complex operator -(complex a, complex b)
            {
                complex c = new complex();
                c.realPart = a.realPart - b.realPart;
                c.imaginaryPart = a.imaginaryPart - b.imaginaryPart;
                return c;
            }

            public void MultiplyComplex(complex a, complex b)
            {
                realPart = a.realPart * b.realPart;
                imaginaryPart = a.imaginaryPart * b.imaginaryPart;
            }

            public static complex operator *(complex a, complex b)
            {
                complex c = new complex();
                c.realPart = a.realPart * b.realPart;
                c.imaginaryPart = a.imaginaryPart * b.imaginaryPart;
                return c;
            }

          
            public static complex operator /(complex a, complex b)
            {
                complex c = new complex();
                c.realPart = (a.realPart * b.realPart + a.realPart * (-b.imaginaryPart)) + (a.imaginaryPart * b.realPart + a.imaginaryPart * (-b.imaginaryPart));
                c.imaginaryPart = (b.realPart * b.realPart + b.realPart * (-b.imaginaryPart)) + (b.imaginaryPart * b.realPart + b.imaginaryPart * (-b.imaginaryPart));
                return c;
            }
            public static bool operator ==(complex a, complex b)
            {
                if (a.realPart == b.realPart&& a.imaginaryPart == b.imaginaryPart)
                    return true;
                else
                    return false;
            }

            public static bool operator !=(complex a, complex b)
            {
                if (a.realPart != b.realPart && a.imaginaryPart != b.imaginaryPart)
                    return true;
                else
                    return false;
            }
        }
    

1 câu trả lời

0 thích 0 không thích
đã trả lời 21 Tháng 12, 2017 bởi TONA DINH (1,570 điểm)
Nhìn code hoa cả mắt.. Vấn đề của bạn là gì ? Bạn có thế trình bày rõ hơn không ?
...