コード例 #1
0
ファイル: Program.cs プロジェクト: hieudan26/DoAn_10Diem_Bai1
        //sua ngu
        static void Main(string[] args)
        {
            int flag = 1;

            while (flag == 1)
            {
                Console.WriteLine("\t\t\t\t*****************************MENU*****************************");
                Console.WriteLine("\t\t\t\t***           1. Thao Tac Voi Hinh Chu Nhat                ***");
                Console.WriteLine("\t\t\t\t***           2. Thao Tac Voi Doan Thang                   ***");
                Console.WriteLine("\t\t\t\t***           3. Thao Tac Voi Hinh Tron                    ***");
                Console.WriteLine("\t\t\t\t***           4. Thao Tac Voi Hinh Tam Giac                ***");
                Console.WriteLine("\t\t\t\t***           5. Thao Tac Voi Hinh Vuong                   ***");
                Console.WriteLine("\t\t\t\t***           6. Thao Tac Voi Hinh Thoi                    ***");
                Console.WriteLine("\t\t\t\t***           7. Thao Tac Voi Hinh Ngu Giac Deu            ***");
                Console.WriteLine("\t\t\t\t***           8. Thao Tac Voi Tat Ca Ca Hinh               ***");
                Console.WriteLine("\t\t\t\t***           9. Thoat                                     ***");
                Console.WriteLine("\t\t\t\t**************************************************************");
                Console.Write("Moi nhap lua chon cua ban => Your choice: ");
                int choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                {
                    Console.Beep();
                    Rectangle HCN = new Rectangle();
                    HCN.Nhap();
                    HCN.Menu();
                    break;
                }

                case 2:
                {
                    Console.Beep();
                    Line DT = new Line();
                    DT.Nhap();
                    DT.Menu();
                    break;
                }

                case 3:
                {
                    Console.Beep();
                    Circle HTron = new Circle();
                    HTron.Nhap();
                    HTron.Menu();
                    break;
                }

                case 4:
                {
                    Console.Beep();
                    Triangle HTG = new Triangle();
                    HTG.Nhap();
                    HTG.Menu();
                    break;
                }

                case 5:
                {
                    Console.Beep();
                    Square HV = new Square();
                    HV.Nhap();
                    HV.Menu();
                    break;
                }

                case 6:
                {
                    Console.Beep();
                    Rhombus HT = new Rhombus();
                    HT.Nhap();
                    HT.Menu();
                    break;
                }

                case 7:
                {
                    Console.Beep();
                    Pentagon HNGD = new Pentagon();
                    HNGD.Nhap();
                    HNGD.Menu();
                    break;
                }

                case 8:
                {
                    Console.Beep();
                    int           floor = 0;
                    ComplexObject cpO   = new ComplexObject(floor);
                    cpO.Menu();
                    break;
                }

                case 9:
                {
                    Console.Beep();
                    flag = 0;
                    Console.Clear();
                    break;
                }

                default:
                {
                    Console.Beep();
                    Console.Clear();
                    Console.WriteLine("Ban Nhap Sai!!! Vui long nhap lai ~~ ");
                    break;
                }
                }
            }
        }
コード例 #2
0
        public override void Nhap()
        {
            Console.Write("Vui long nhap so luong Doan Thang: ");
            int DT = int.Parse(Console.ReadLine());

            for (int i = 0; i < DT; i++)
            {
                try
                {
                    Line a = new Line();
                    a.Nhap();
                    if (a.P1.x != a.P2.x || a.P2.y != a.P1.y)
                    {
                        this.lShape.Add(a);
                    }
                    else
                    {
                        throw new Exception("Khong the nhap 2 diem trung nhau!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.Write("Vui long nhap so luong Hinh Tron: ");
            int HT = int.Parse(Console.ReadLine());

            for (int i = 0; i < HT; i++)
            {
                Circle a = new Circle();
                a.Nhap();
                try
                {
                    if (Math.Abs(a.P1.x - a.P2.x) == Math.Abs(a.P1.y - a.P2.y) && (a.P1.x != a.P2.x && a.P2.y != a.P1.y))
                    {
                        this.lShape.Add(a);
                    }
                    else
                    {
                        throw new Exception("Khong the ve hinh vuong voi khung hinh chu nhat!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.Write("Vui long nhap so luong Hinh Chu Nhat: ");
            int HCN = int.Parse(Console.ReadLine());

            for (int i = 0; i < HCN; i++)
            {
                try
                {
                    Rectangle a = new Rectangle();
                    a.Nhap();
                    if (a.P1.x != a.P2.x && a.P2.y != a.P1.y)
                    {
                        this.lShape.Add(a);
                    }
                    else
                    {
                        throw new Exception("Khong the nhap 2 diem trung nhau!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.Write("Vui long nhap so luong Hinh Tam Giac: ");
            int TG = int.Parse(Console.ReadLine());

            for (int i = 0; i < TG; i++)
            {
                try
                {
                    Triangle a = new Triangle();
                    a.Nhap();
                    if (a.P1.x != a.P2.x && a.P2.y != a.P1.y)
                    {
                        this.lShape.Add(a);
                    }
                    else
                    {
                        throw new Exception("Khong the nhap 2 diem trung nhau!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.Write("Vui long nhap so luong Hinh Vuong: ");
            int HV = int.Parse(Console.ReadLine());

            for (int i = 0; i < HV; i++)
            {
                Square a = new Square();
                a.Nhap();
                try
                {
                    if (Math.Abs(a.P1.x - a.P2.x) == Math.Abs(a.P1.y - a.P2.y) && (a.P1.x != a.P2.x && a.P2.y != a.P1.y))
                    {
                        this.lShape.Add(a);
                    }
                    else
                    {
                        throw new Exception("Khong the ve hinh vuong voi khung hinh chu nhat! Hoac ban nhap 2 diem trung nhau!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.Write("Vui long nhap so luong Hinh Thoi: ");
            int HTh = int.Parse(Console.ReadLine());

            for (int i = 0; i < HTh; i++)
            {
                try
                {
                    Rhombus a = new Rhombus();
                    a.Nhap();
                    if (a.P1.x != a.P2.x && a.P2.y != a.P1.y)
                    {
                        this.lShape.Add(a);
                    }
                    else
                    {
                        throw new Exception("Khong the nhap 2 diem trung nhau!");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            Console.Write("Vui long nhap so luong Hinh Ngu Giac Deu: ");
            int HNGD = int.Parse(Console.ReadLine());

            for (int i = 0; i < HNGD; i++)
            {
                Pentagon a = new Pentagon();
                a.Nhap();
                try
                {
                    if (Math.Abs(a.P1.x - a.P2.x) == Math.Abs(a.P1.y - a.P2.y) && (a.P1.x != a.P2.x && a.P2.y != a.P1.y))
                    {
                        this.lShape.Add(a);
                    }
                    else
                    {
                        throw new Exception("Khong the ve hinh Ngu Giac Deu voi khung hinh chu nhat! Hoac ban dang nhap 2 diem trung nhau");
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            Console.Write("Moi nhap Mau cua Complex Object: ");
            this.Color = int.Parse(Console.ReadLine());
            this.SetDiem();
        }