예제 #1
0
        public static void Main(string[] args)
        {
            House h1  = new House("Building 1", "3246  Timber Oak Drive", 4, 63000, 68);
            House h2  = new House("Building 2", "1140  Lynn Avenue", 3, 42000, 72);
            House h3  = new House("Building 3", "2721  Petunia Way", 6, 78000, 240);
            House h4  = new House("Building 4", "4992  Spring Avenue", 3, 33000, 74);
            House h5  = new House("Building 5", "414  Summit Street", 4, 54000, 98);
            House h6  = new House("Building 6", "664  Glenwood Avenue", 5, 80000, 152);
            House h7  = new House("Building 7", "1752  Browning Lane", 2, 24000, 49);
            House h8  = new House("Building 8", "3574  Big Indian", 4, 51000, 82);
            House h9  = new House("Building 9", "4218  Crummit Lane", 3, 58000, 78);
            House h10 = new House("Building 10", "4559  Holly Street", 4, 92000, 98);

            House[] houses = new House[10];
            houses[0] = h1;
            houses[1] = h2;
            houses[2] = h3;
            houses[3] = h4;
            houses[4] = h5;
            houses[5] = h6;
            houses[6] = h7;
            houses[7] = h8;
            houses[8] = h9;
            houses[9] = h10;

            string prn01 = "Назва:\t\tАдреса:\t\t\t\tКiлькiсть кiмнат:\tЦiна ($):\tПлоща (кв.м):";

            Console.WriteLine("Список без сортування");
            Console.WriteLine(prn01);
            for (int i = 0; i < houses.Length; i++)
            {
                Console.WriteLine(houses[i].Name + "\t" + houses[i].Address + "\t\t" + houses[i].Number_of_rooms + "\t\t\t" + houses[i].Price + "\t\t" + houses[i].Area);
            }

            while (true)
            {
                Console.WriteLine("\nНатиснiть на одну з вказаних клавiш, щоб вибрати режим роботи: ");
                Console.WriteLine("Реалiзацiя iнтерфейсу  IComparable для порiвняння будинкiв за цiною  - 1");
                Console.WriteLine("Реалiзацiя в класi iнтерфейсу IComparer для порiвняння будинкiв за цiною i за площею - 2");
                Console.WriteLine("Реалiзацiя iнтерфейсу IEnumerable - 3");
                Console.WriteLine("Вихiд з програми - будь-яка iнша клавiша");

                ConsoleKeyInfo cki;
                cki = Console.ReadKey(true);
                if (cki.Key == ConsoleKey.NumPad1)
                {
                    Array.Sort(houses);
                    Console.WriteLine("\nСортування за цiною");
                    Console.WriteLine(prn01);
                    for (int i = 0; i < houses.Length; i++)
                    {
                        Console.WriteLine(houses[i].Name + "\t" + houses[i].Address + "\t\t" + houses[i].Number_of_rooms + "\t\t\t" + houses[i].Price + "\t\t" + houses[i].Area);
                    }
                }
                else if (cki.Key == ConsoleKey.NumPad2)
                {
                    Array.Sort(houses, new House.SortByPrice());
                    Console.WriteLine("\nСортування за цiною");
                    Console.WriteLine(prn01);
                    for (int i = 0; i < houses.Length; i++)
                    {
                        Console.WriteLine(houses[i].Name + "\t" + houses[i].Address + "\t\t" + houses[i].Number_of_rooms + "\t\t\t" + houses[i].Price + "\t\t" + houses[i].Area);
                    }

                    Array.Sort(houses, new House.SortByArea());
                    Console.WriteLine("\nСортування за площею");
                    Console.WriteLine(prn01);
                    for (int i = 0; i < houses.Length; i++)
                    {
                        Console.WriteLine(houses[i].Name + "\t" + houses[i].Address + "\t\t" + houses[i].Number_of_rooms + "\t\t\t" + houses[i].Price + "\t\t" + houses[i].Area);
                    }
                }
                else if (cki.Key == ConsoleKey.NumPad3)
                {
                    Array.Sort(houses, new House.SortByPrice());
                    Houses HouseCollections01 = new Houses(houses);

                    Console.WriteLine("\nСортування за цiною");
                    Console.WriteLine(prn01);
                    foreach (var house in HouseCollections01)
                    {
                        Console.WriteLine(house.Name + "\t" + house.Address + "\t\t" + house.Number_of_rooms + "\t\t\t" + house.Price + "\t\t" + house.Area);
                    }

                    Array.Sort(houses, new House.SortByArea());
                    Houses HouseCollections02 = new Houses(houses);

                    Console.WriteLine("\nСортування за площею");
                    Console.WriteLine(prn01);
                    foreach (var house in HouseCollections02)
                    {
                        Console.WriteLine(house.Name + "\t" + house.Address + "\t\t" + house.Number_of_rooms + "\t\t\t" + house.Price + "\t\t" + house.Area);
                    }
                }
                else
                {
                    break;
                }
            }
        }
예제 #2
0
        public static void Main(string[] args)
        {
            Document h1  = new Document("Document 1", "2555  adfsjaglal", 6, 120, 04);
            Document h2  = new Document("Document 2", "2543  ahahdhahha", 3, 60, 06);
            Document h3  = new Document("Document 3", "5774  aahadfjfgkj", 3, 40, 10);
            Document h4  = new Document("Document 4", "5694  adjgxfhgfdd", 7, 300, 08);
            Document h5  = new Document("Document 5", "5777  adjgxfhgfdd", 5, 500, 01);
            Document h6  = new Document("Document 6", "485  adjgxfhgfdd", 5, 400, 14);
            Document h7  = new Document("Document 7", "467  adjgxfhgfdd", 2, 200, 17);
            Document h8  = new Document("Document 8", "2785  adjgxfhgfdd", 2, 70, 20);
            Document h9  = new Document("Document 9", "9653 adjgxfhgfdd", 3, 50, 21);
            Document h10 = new Document("Document 10", "3621  adjgxfhgfdd", 1, 140, 22);

            Document[] documentes = new Document[10];
            documentes[0] = h1;
            documentes[1] = h2;
            documentes[2] = h3;
            documentes[3] = h4;
            documentes[4] = h5;
            documentes[5] = h6;
            documentes[6] = h7;
            documentes[7] = h8;
            documentes[8] = h9;
            documentes[9] = h10;

            string prn01 = "Назва:\t\tНомер:\t\t\t\tКiлькiсть документів:\tСторінки ($):\tДата(день):";

            Console.WriteLine("Список без сортування");
            Console.WriteLine(prn01);
            for (int i = 0; i < documentes.Length; i++)
            {
                Console.WriteLine(documentes[i].Name + "\t" + documentes[i].Number + "\t\t" + documentes[i].Number_of_documents + "\t\t\t" + documentes[i].Number_of_pages + "\t\t" + documentes[i].Date);
            }

            while (true)
            {
                Console.WriteLine("\nНатиснiть на одну з вказаних клавiш, щоб вибрати режим роботи: ");
                Console.WriteLine("Реалiзацiя iнтерфейсу  IComparable для порiвняння будинкiв за цiною  - 1");
                Console.WriteLine("Реалiзацiя в класi iнтерфейсу IComparer для порiвняння документів за кількістю сторінок i за датою створення - 2");
                Console.WriteLine("Реалiзацiя iнтерфейсу IEnumerable - 3");
                Console.WriteLine("Вихiд з програми - будь-яка iнша клавiша");

                ConsoleKeyInfo cki;
                cki = Console.ReadKey(true);
                if (cki.Key == ConsoleKey.NumPad1)
                {
                    Array.Sort(documentes);
                    Console.WriteLine("\nСортування за кількістю сторінок ");
                    Console.WriteLine(prn01);
                    for (int i = 0; i < documentes.Length; i++)
                    {
                        Console.WriteLine(documentes[i].Name + "\t" + documentes[i].Number + "\t\t" + documentes[i].Number_of_documents + "\t\t\t" + documentes[i].Number_of_pages + "\t\t" + documentes[i].Date);
                    }
                }
                else if (cki.Key == ConsoleKey.NumPad2)
                {
                    Array.Sort(documentes, new Document.SortByPrice());
                    Console.WriteLine("\nСортування за кількістю сторінок");
                    Console.WriteLine(prn01);
                    for (int i = 0; i < documentes.Length; i++)
                    {
                        Console.WriteLine(documentes[i].Name + "\t" + documentes[i].Number + "\t\t" + documentes[i].Number_of_documents + "\t\t\t" + documentes[i].Number_of_pages + "\t\t" + documentes[i].Date);
                    }

                    Array.Sort(documentes, new Document.SortByArea());
                    Console.WriteLine("\nСортування за датою створення");
                    Console.WriteLine(prn01);
                    for (int i = 0; i < documentes.Length; i++)
                    {
                        Console.WriteLine(documentes[i].Name + "\t" + documentes[i].Number + "\t\t" + documentes[i].Number_of_documents + "\t\t\t" + documentes[i].Number_of_pages + "\t\t" + documentes[i].Date);
                    }
                }
                else if (cki.Key == ConsoleKey.NumPad3)
                {
                    Array.Sort(documentes, new Document.SortByPrice());
                    Houses HouseCollections01 = new Houses(documentes);

                    Console.WriteLine("\nСортування за кількістю сторінок");
                    Console.WriteLine(prn01);
                    foreach (var document in HouseCollections01)
                    {
                        Console.WriteLine(document.Name + "\t" + document.Number + "\t\t" + document.Number_of_documents + "\t\t\t" + document.Number_of_pages + "\t\t" + document.Date);
                    }

                    Array.Sort(documentes, new Document.SortByArea());
                    Houses HouseCollections02 = new Houses(documentes);

                    Console.WriteLine("\nСортування за датою створення");
                    Console.WriteLine(prn01);
                    foreach (var document in HouseCollections02)
                    {
                        Console.WriteLine(document.Name + "\t" + document.Number + "\t\t" + document.Number_of_documents + "\t\t\t" + document.Number_of_pages + "\t\t" + document.Date);
                    }
                }
                else
                {
                    break;
                }
            }
        }