Exemplo n.º 1
0
        public DaThuc truDaThuc(DaThuc a)
        {
            DaThuc b;
            int    i, j;

            if (bac > a.bac)
            {
                b = new DaThuc(bac);
                for (i = 0; i <= a.bac; i++)
                {
                    b.heso[i] = heso[i] - b.heso[i];
                }
                for (j = i; j <= bac; i++)
                {
                    b.heso[j] = heso[j];
                }
            }
            else
            {
                b = new DaThuc(a.bac);
                for (i = 0; i <= bac; i++)
                {
                    b.heso[i] = heso[i] - a.heso[i];
                }
                for (j = i; j <= a.bac; j++)
                {
                    b.heso[j] = a.heso[j];
                }
            }

            return(b);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            DaThuc dt = new DaThuc();

            Console.WriteLine("\tNhap vao da thuc thu nhat!!! ");
            dt.Nhap();
            Console.Write("Da thuc vua nhap: ");
            dt.Xuat();
            DaThuc dt1 = new DaThuc();

            Console.WriteLine("\t\nNhap vap da thuc thu hai!!! ");
            dt1.Nhap();
            Console.Write("Da thuc vua nhap: ");
            dt1.Xuat();
            Console.Write("\nTong 2 da thuc: ");
            DaThuc tong = new DaThuc();

            tong = dt.congDaThuc(dt1);
            tong.XuatKQ();
            Console.Write("\nOperator tong 2 da thuc: ");
            tong = dt + dt1;
            tong.XuatKQ();
            Console.Write("\nHieu 2 da thuc: ");
            DaThuc hieu = new DaThuc();

            hieu = dt.truDaThuc(dt1);
            hieu.Xuat();
            Console.Write("\nOperator hieu 2 da thuc: ");
            hieu = dt - dt1;
            hieu.Xuat();
            Console.ReadLine();
        }
Exemplo n.º 3
0
        public static DaThuc operator +(DaThuc a, DaThuc b)
        {
            DaThuc c = new DaThuc();

            for (int i = 0; i <= c.bac; i++)
            {
                c.heso[i] = a.heso[i] + b.heso[i];
            }
            return(c);
        }
Exemplo n.º 4
0
        public static DaThuc operator -(DaThuc a, DaThuc b)
        {
            DaThuc c      = new DaThuc();
            int    maxbac = Math.Max(a.bac, b.bac);

            for (int i = 0; i <= c.bac; i++)
            {
                c.heso[i] = a.heso[i] - b.heso[i];
            }
            return(c);
        }