Exemplo n.º 1
0
        static UnitsBase[] UnitArray()
        {
            int countBooks = rnd.Next(3, 6);
            int countCards = rnd.Next(3, 6);
            int countCDs   = rnd.Next(3, 6);

            UnitsBase[] p = new UnitsBase[countBooks + countCards + countCDs];

            for (int i = 0; i < countBooks; ++i)
            {
                p[i] = new Books(rnd.Next(1, 101), rnd.Next(50, 500), GenerateName(), rnd.Next(30, 100), rnd.Next(0, 2) == 1);
            }

            for (int i = countBooks; i < countBooks + countCards; ++i)
            {
                p[i] = new Cards(rnd.Next(1, 101), rnd.Next(50, 500), GenerateName(), GenerateName());
            }

            for (int i = countBooks + countCards; i < p.Length; ++i)
            {
                p[i] = new CD(rnd.Next(1, 101), rnd.Next(50, 500), GenerateName(), rnd.Next(30, 1201));
            }

            return(p);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            do
            {
                Console.Clear();

                UnitsBase[] arr = new UnitsBase[5];
                int         skidca;
                Console.Write("Enter skidca = ");
                int.TryParse(Console.ReadLine(), out skidca);
                for (int i = 0; i < arr.Length; i++)
                {
                    if (rnd.Next(0, 2) == 0)
                    {
                        arr[i] = new CD("cd", rnd.Next(20, 150), skidca, 0, rnd.Next(100, 500));
                    }
                    else if (rnd.Next(0, 2) == 1)
                    {
                        arr[i] = new Cards("cards", rnd.Next(5, 100), skidca, 1, "OUO");
                    }
                    else
                    {
                        arr[i] = new Books("book", rnd.Next(20, 150), skidca, 2, rnd.Next(20, 150), true);
                    }
                }

                for (int i = 0; i < arr.Length; i++)
                {
                    Console.WriteLine($"{arr[i].name}\tprise = {arr[i].price}\twhith_skidka ={arr[i].Discount()} ");
                }
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }