예제 #1
0
        public static TamThucBacHai operator +(TamThucBacHai tamThucBacHai1, TamThucBacHai tamThucBacHai2)
        {
            TamThucBacHai d = new TamThucBacHai
            {
                a = tamThucBacHai1.a + tamThucBacHai2.a,
                b = tamThucBacHai1.b + tamThucBacHai2.b,
                c = tamThucBacHai1.c + tamThucBacHai2.c
            };

            return(d);
        }
예제 #2
0
        public static TamThucBacHai operator-(TamThucBacHai tamThucBacHai)
        {
            TamThucBacHai d = new TamThucBacHai
            {
                a = -tamThucBacHai.a,
                b = -tamThucBacHai.b,
                c = -tamThucBacHai.c
            };

            return(d);
        }
예제 #3
0
        static void Main(string[] args)
        {
            TamThucBacHai tamThucBacHai1 = new TamThucBacHai(3, 0, 5);
            TamThucBacHai tamThucBacHai2 = new TamThucBacHai(123, 456, 789);

            tamThucBacHai1 = -tamThucBacHai1;
            tamThucBacHai2 = -tamThucBacHai2;
            Console.WriteLine("Tam thuc bac hai 1: " + tamThucBacHai1);
            Console.WriteLine("Tam thuc bac hai 2: " + tamThucBacHai2);
            TamThucBacHai tong = tamThucBacHai1 + tamThucBacHai2;
            TamThucBacHai hieu = tamThucBacHai1 - tamThucBacHai2;

            Console.WriteLine(tamThucBacHai1 + " + " + tamThucBacHai2 + " = " + tong);
            Console.WriteLine(tamThucBacHai1 + " - " + tamThucBacHai2 + " = " + hieu);
        }