Chào các bạn! Vì nhiều lý do từ nay Truyen2U chính thức đổi tên là Truyen247.Pro. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

ClassXe-ClassHinh

using System;

using System.Text;

namespace ClassXe

{

    public class Xe

    {

        public Xe(string MyName)    { this.MyName = MyName;}

        public virtual void Who() 

        { 

            Console.WriteLine("

Toi la xe {0}", MyName);

        }

        protected string MyName;

    }

    public class Xe_Dulich : Xe

    {

        public Xe_Dulich(string MyName) : base(MyName) { }

        public override void Who()

        {

            Console.WriteLine("

Toi la xe du lich {0}.", MyName);

        }

    }

    public class Xe_May : Xe

    {

        public Xe_May(string MyName) : base(MyName) { }

        public override void Who()

        {

            Console.WriteLine("

Toi la xe may {0}.", MyName);

        }

    }

    public class Tester

    {

        static void Main()

        {

            Xe xe = new Xe("Toyota");

            xe.Who();

            Xe[] mangxe = new Xe[5];

            mangxe[0] = new Xe_Dulich("Toyota");

            mangxe[1] = new Xe_May("Dream");

            mangxe[2] = new Xe_May("Spacy");

            mangxe[3] = new Xe_Dulich("BMW");

            mangxe[4] = new Xe_Dulich("Fiat");

            for (int i = 0; i < 5; i++)

            {

                mangxe[i].Who();

            }

        }

    }

}

------

------

------

using System;

using System.Text;

namespace Class_HinhHoc

{

    public class Diem

    {

        public Diem(int x1, int y1)

        {

            this.x1 = x1;

            this.y1 = y1;

        }

        public virtual void Draw()

        {

            Console.Write("

Ve diem tai toa do( {0};{1} )", x1, y1);

        }

        protected int x1;

        protected int y1;

    }

    public class DuongThang : Diem

    {

        public DuongThang(int x1,int y1,int x2, int y2) 

            : base(x1,y1)

        {

            this.x2 = x2;

            this.y2 = y2;

        }

        public override void Draw()

        {

            Console.Write("

Ve doan thang voi diem dau ( {0};{1} ) va diem cuoi ( {2};{3} ) ",x1,y1,x2,y2);

        }

        private int x2;

        private int y2;

    }

    public class DuongTron : Diem

    {

        public DuongTron(int x1, int y1, int r)

            : base(x1, y1)

        {

            this.r = r;

        }

        public override void Draw()

        {

            Console.Write("

Ve duong tron tam ( {0};{1} ) ban kinh {2} ",x1,y1,r);

        }

        private int r;

    }

    public class HinhChuNhat : Diem

    {

        public HinhChuNhat(int x1, int y1, int x2, int y2)

            : base(x1, y1)

        {

            this.x2 = x2;

            this.y2 = y2;

        }

        public override void Draw()

        {

            Console.Write("

Ve hinh chu nhat diem tren ( {0};{1} ) va diem duoi ( {2};{3} ) ", x1, y1, x2, y2);

        }

        private int x2;

        private int y2;

    }

    public class HinhVuong : Diem

    {

        public HinhVuong(int x1, int y1, int a)

            : base(x1, y1)

        {

            this.a = a;

        }

        public override void Draw()

        {

            Console.Write("

Hinh vuong voi mot dinh tai ( {0};{1} ) chieu dai canh la {2} ", x1, y1, a);

        }

        private int a;

    }

    public class TamGiac : Diem

    { 

        public TamGiac(int x1,int y1,int x2, int y2, int x3, int y3) 

            : base(x1,y1)

        {

            this.x2 = x2;

            this.y2 = y2;

            this.x3 = x3;

            this.y3 = y3;

        }

        public override void Draw()

        {

            Console.Write("

Ve tam giac voi ba diem ( {0};{1} ) , ( {2};{3} ) va ( {4};{5} )",x1,y1,x2,y2,x3,y3);

        }

        private int x2;

        private int y2;

        private int x3;

        private int y3;

    }

    public class Tester

    {

        public static void Main()

        {

            Diem[] mang = new Diem[6];

            mang[0] = new Diem(1 , 2);

            mang[1] = new DuongThang(1, 2, 2, 4);

            mang[2] = new DuongTron(1, 3, 10);

            mang[3] = new HinhChuNhat(3, 4, 5, 6);

            mang[4] = new HinhVuong(5, 6, 12);

            mang[5] = new TamGiac(1, 2, 3, 4, 5, 6);

            for (int i = 0; i < mang.Length; i++)

            {

                mang[i].Draw();

            }

            Console.WriteLine();

        }

    }

}

Bạn đang đọc truyện trên: Truyen247.Pro

Tags: #nguyen