Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to program...\n");

            Console.WriteLine("Enter Client Data...");
            Console.Write("Name...: ");
            string name = Console.ReadLine();

            Console.Write("Email...: ");
            string email = Console.ReadLine();

            Console.Write("Birth Day (DD/MM/YYY)...: ");
            DateTime birthDay = DateTime.Parse(Console.ReadLine());

            Client client = new Client(name, email, birthDay);


            Console.WriteLine();//Jump a line in execution.

            Console.WriteLine("Enter order data....");
            Console.Write("Status...: ");
            OrderStatus status = Enum.Parse <OrderStatus>(Console.ReadLine());

            Console.WriteLine();//Jump a line in execution.

            Console.Write("How many items to this order? ...: ");
            int qtdOrderItems = int.Parse(Console.ReadLine());

            OrderP orderP = new OrderP(status, client);

            for (int i = 1; i <= qtdOrderItems; i++)
            {
                Console.WriteLine($"Enter {i} item data...");
                Console.Write("Product name...: ");
                string pName = Console.ReadLine();
                Console.Write("Product price...: ");
                double pPrice = double.Parse(Console.ReadLine(), CultureInfo.InvariantCulture);
                Console.Write("Quantity...: ");
                int pQuantity = int.Parse(Console.ReadLine());

                Product   product   = new Product(pName, pPrice);
                OrderItem orderItem = new OrderItem(pQuantity, pPrice, product);
                orderP.AddItem(orderItem);

                Console.WriteLine();//Jump a line in execution
            }
            Console.WriteLine(orderP);
            Console.WriteLine($"TOTAL: {orderP.Total().ToString("F2")}");
        }
Exemplo n.º 2
0
        //生成凸包多边形
        public void Polygon(List <Point> CPoints, out Point P0, out List <Point> OPoints, out List <Point> PolyPoints1)
        {
            OPoints = new List <Point>();

            int    n    = CPoints.Count();
            double ymin = CPoints[0].Y;

            P0 = CPoints[0];
            for (int i = 0; i < n; i++)
            {
                if (CPoints[i].Y < ymin)
                {
                    ymin = CPoints[i].Y;
                    P0   = CPoints[i];
                }
            }

            List <OrderP> OrderPoint = new List <OrderP>();
            OrderP        orderP;

            for (int i = 0; i < n; i++)
            {
                if (CPoints[i] != P0)
                {
                    orderP       = new OrderP();
                    orderP.p     = CPoints[i];
                    orderP.angle = Math.Atan2(CPoints[i].Y - P0.Y, CPoints[i].X - P0.X);
                    OrderPoint.Add(orderP);
                }
            }

            for (int i = 0; i < n - 1; i++)
            {
                for (int j = 0; j < n - 2 - i; j++)
                {
                    if (OrderPoint[j].angle > OrderPoint[j + 1].angle)
                    {
                        OrderP p = new OrderP();
                        p = OrderPoint[j + 1];
                        OrderPoint[j + 1] = OrderPoint[j];
                        OrderPoint[j]     = p;
                    }
                }
            }

            for (int i = 0; i < OrderPoint.Count; i++)
            {
                if (i != OrderPoint.Count - 1)
                {
                    if (OrderPoint[i].angle != OrderPoint[i + 1].angle)
                    {
                        OPoints.Add(OrderPoint[i].p);
                    }
                    else
                    {
                        i++;
                    }
                }
                else
                {
                    OPoints.Add(OrderPoint[i].p);
                }
            }

            List <Point> PolyPoints = new List <Point>();

            PolyPoints.Add(P0);
            Point  pi, pj, pk;
            double m;
            int    count = OPoints.Count + 1;
            int    n1    = count - 2;
            int    pc    = count;

            for (int i = 0; i < OPoints.Count; i++)
            {
                PolyPoints.Add(OPoints[i]);
            }

            for (int i = 1; i < n1; i++)
            {
                pi = PolyPoints[i];
                pj = PolyPoints[i + 1];
                pk = PolyPoints[i + 2];
                m  = (pi.X - pj.X) * (pk.Y - pj.Y) - (pi.Y - pj.Y) * (pk.X - pj.X);
                if (m >= 0)
                {
                    for (int j = i + 1; j < count - 1; j++)
                    {
                        PolyPoints[j] = PolyPoints[j + 1];
                    }
                    i = 1;
                    pc--;
                    n1--;
                }
            }

            PolyPoints1 = new List <Point>();
            for (int i = 0; i < pc; i++)
            {
                PolyPoints1.Add(PolyPoints[i]);
            }
        }