Example #1
0
        static void Main(string[] args)
        {
            // Лабораторная работа №3

            //        1. Создать объект типа StudentCollection. Добавить в коллекцию несколько
            //        различных элементов типа Student и вывести объект StudentCollection.

            StudentCollection studentCollection = new StudentCollection();

            studentCollection.AddStudents(
                TestCollections.GetStudent(5),
                TestCollections.GetStudent(2),
                TestCollections.GetStudent(1),
                TestCollections.GetStudent(3),
                TestCollections.GetStudent(4)
                );



            /*  2. Для созданного объекта StudentCollection вызвать методы,
             *  выполняющие сортировку списка List<Student> по разным критериям, и
             *  после каждой сортировки вывести данные объекта.Выполнить
             *  сортировку:
             *  - по фамилии студента;
             *  - по дате рождения;
             *  - по среднему баллу
             *
             * 3. Вызвать методы класса StudentCollection, выполняющие операции со
             * списком List<Student>, и после каждой операции вывести результат
             * операции. Выполнить
             * - вычисление максимального значения среднего балла для элементов списка;
             * - фильтрацию списка для отбора студентов с формой обучения
             * Education.Specialist;
             * - группировку элементов списка по значению среднего балла;
             * вывести все группы элементов.
             *
             * 4. Создать объект типа TestCollections. Вызвать метод для поиска в
             * коллекциях первого, центрального, последнего и элемента, не
             * входящего в коллекции. Вывести значения времени поиска для всех
             * четырех случаев. Вывод должен содержать информацию о том, к какой
             * коллекции и к какому элементу относится данное значение.*/



            studentCollection.SortByName();
            Console.WriteLine("Sorted by Name: \n {0}\n", string.Join(" ; ", studentCollection.Students.Select(x => x.GetName()).ToArray()));
            studentCollection.SortByDate();
            Console.WriteLine("Sorted by Date: \n {0}\n", string.Join(" ; ", studentCollection.Students.Select(x => x.GetName()).ToArray()));
            studentCollection.GetMaxMiddleScore();
            Console.WriteLine("Sorted by miiddle : \n {0}\n", string.Join(" ; ", studentCollection.Students.Select(x => x.GetName()).ToArray()));
            Console.WriteLine("Maximum middle Score: {0}\n", studentCollection.GetMaxMiddleScore());
            Console.WriteLine("Person with Education = Master :\n {0}\n", string.Join(" ; ", studentCollection.GetMasterStudents().Select(x => x.GetName()).ToArray()));



            int value = 3;

            Console.WriteLine("Students with middle Score more then {0}:\n {1}\n", value,
                              string.Join(" ; ", studentCollection.AverageMarkGroup(value).Select(x => x.GetName()).ToArray()));

            TestCollections test = new TestCollections(1);

            Console.WriteLine("Searching time:");
            test.MeasureTime();
            Console.ReadKey();
        }
Example #2
0
        public void RabbitGrowthTest(int a, int b, int c, int d, int e, int expected)
        {
            int actual = TestCollections.ArrayListDictionaryGetTotal(a, b, c, d, e);

            Assert.AreEqual(expected, actual);
        }
Example #3
0
        private static void Main(string[] args)
        {
            ManCollection MyCollection = new ManCollection();

            Man one = new Man(new Person("Andrew", "Matsuk", new DateTime(2001, 12, 3)), LevelsOfProficiency.A, 1);

            one.AddTOEFL(
                new TOEFL("C#", 100, new DateTime(2020, 02, 02)),
                new TOEFL("PHP", 98, new DateTime(2020, 04, 04))
                );
            MyCollection.AddMans(one);

            Man two = new Man(new Person("Roman", "Serediak", new DateTime(2002, 10, 19)), LevelsOfProficiency.C, 2);

            two.AddTOEFL(
                new TOEFL("C#", 2, new DateTime(2020, 02, 02)),
                new TOEFL("PHP", 2, new DateTime(2020, 04, 04))
                );
            MyCollection.AddMans(two);

            Man three = new Man(new Person("Vadym", "Samsonovych", new DateTime(2001, 10, 07)), LevelsOfProficiency.B, 3);

            three.AddTOEFL(
                new TOEFL("C#", 90, new DateTime(2020, 02, 02)),
                new TOEFL("PHP", 87, new DateTime(2020, 04, 04))
                );
            MyCollection.AddMans(three);

            Man four = new Man(new Person("Kate", "Zelenetska", new DateTime(2002, 05, 06)), LevelsOfProficiency.A, 4);

            four.AddTOEFL(
                new TOEFL("C#", 100, new DateTime(2020, 02, 02)),
                new TOEFL("PHP", 98, new DateTime(2020, 04, 04))
                );
            MyCollection.AddMans(four);

            string key;

            do
            {
                Console.WriteLine("1 - Show Collection");
                Console.WriteLine("2 - Sort By Second Name");
                Console.WriteLine("3 - Sort By Birthday");
                Console.WriteLine("4 - Sort By Average Grade");
                Console.WriteLine("5 - Max Average Mark");
                Console.WriteLine("6 - Average Mark Of Group");
                Console.WriteLine("7 - Student With Qualification A");
                Console.WriteLine("8 - Show Time Of Searching Elements In The Collections");
                Console.WriteLine("9 - Exit");

                key = Console.ReadLine();
                Console.Clear();

                switch (key)
                {
                case "1":
                {
                    foreach (Man item in MyCollection)
                    {
                        Console.WriteLine($"{item.ToShortString()};\n");
                    }

                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case "2":
                {
                    MyCollection.SortBySecondName();
                    Console.WriteLine("\t\t\t\tSorted by second name\n");
                    foreach (Man item in MyCollection)
                    {
                        Console.WriteLine($"{item.ToShortString()};\n");
                    }

                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case "3":
                {
                    MyCollection.SortByBirthday();
                    Console.WriteLine("\t\t\t\tSorted by Birthday\n");
                    foreach (Man item in MyCollection)
                    {
                        Console.WriteLine($"{item.ToShortString()};\n");
                    }

                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case "4":
                {
                    MyCollection.SortByAverageGrade();
                    Console.WriteLine("\t\t\t\tSorted by Marks\n");
                    foreach (Man item in MyCollection)
                    {
                        Console.WriteLine($"{item.ToShortString()};\n");
                    }

                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case "5":
                {
                    Console.WriteLine($"Max average mark is: {MyCollection.MaxAverageMark}");

                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case "6":
                {
                    Console.WriteLine($"{MyCollection.AverageMarkGroup(99)}");

                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case "7":
                {
                    Console.WriteLine("\t\t\tThe student who has qualification A\n");
                    foreach (Man item in MyCollection.QualificationA)
                    {
                        Console.WriteLine($"{item.ToShortString()};\n");
                    }

                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case "8":
                {
                    string key1;
                    do
                    {
                        TestCollections testCollection = new TestCollections(20);
                        Console.WriteLine("1 - Search time for an item that is not part of the collection");
                        Console.WriteLine("2 - Search time for the last item in the collection");
                        Console.WriteLine("3 - search time of the middle element of the collection");
                        Console.WriteLine("4 - Search time for the first item in the collection");
                        Console.WriteLine("5 - Show all elements");
                        Console.WriteLine("6 - Exit");

                        key1 = Console.ReadLine();
                        Console.Clear();

                        switch (key1)
                        {
                        case "1":
                        {
                            Console.WriteLine("\t\t\tThe item is not included in the collection.\n");
                            testCollection.SearchTheElem(21);

                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        case "2":
                        {
                            Console.WriteLine("\t\t\tThe last element of the collection.\n");
                            testCollection.SearchTheElem(20);

                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        case "3":
                        {
                            Console.WriteLine("\t\t\tThe item is in the middle of the collection.\n");
                            testCollection.SearchTheElem(10);

                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        case "4":
                        {
                            Console.WriteLine("\t\t\tThe first element of the collection.\n");
                            testCollection.SearchTheElem(1);

                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        case "5":
                        {
                            foreach (var item in testCollection)
                            {
                                Console.WriteLine(item);
                            }

                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }

                        default:
                        {
                            Console.WriteLine("Something went wrong");

                            Console.ReadLine();
                            Console.Clear();
                            break;
                        }
                        }
                    } while (key1 != "6");

                    break;
                }
                }
            } while (key != "9");
        }
Example #4
0
        static void Main(string[] args)
        {
            forLabFour();
            ResearchTeamCollection a = new ResearchTeamCollection();

            List <Person> per  = new List <Person>();
            Person        per1 = new Person();

            per1.Name       = "Kevin";
            per1.Surname    = "Lewin";
            per1.DateOfBorn = DateTime.MinValue;
            per.Add(per1);

            List <Paper> doc  = new List <Paper>();
            Paper        doc1 = new Paper();

            doc1.Autor             = per[0];
            doc1.NameOfPublication = "Some research";
            doc1.Date = DateTime.Now;
            doc.Add(doc1);

            List <Paper> docs2 = new List <Paper>();
            Paper        doc2  = new Paper();

            doc2.Autor             = per[0];
            doc2.NameOfPublication = "Some research";
            doc2.Date = DateTime.Now;
            docs2.Add(doc1);
            docs2.Add(doc2);

            ResearchTeam rt1 = new ResearchTeam();

            rt1.Name      = "Workers";
            rt1.RegNumber = 1;
            foreach (Paper item in docs2)
            {
                rt1.AddPapers(item);
            }

            rt1.Persons = per;

            ResearchTeam rt2 = new ResearchTeam();

            rt2.Name             = "Josefs";
            rt2.RegNumber        = 2;
            rt2.LengthOfResearch = TimeFrame.TwoYears;

            foreach (Paper item in doc)
            {
                rt2.AddPapers(item);
            }
            rt2.Persons = per;

            List <ResearchTeam> t = new List <ResearchTeam> {
                rt1, rt2
            };

            a.AddDefaults(t);

            a.RnameSort();
            Console.WriteLine("Name Sort");
            Console.WriteLine(a.ToString());
            a.RnumSort();
            Console.WriteLine("Registration Number Sort:");
            Console.WriteLine(a.ToString());
            a.DocsSort();
            Console.WriteLine("Docs Sort:");
            Console.WriteLine(a.ToString());
            Console.WriteLine("Min registration number:");
            Console.WriteLine(a.MinRegNum);
            Console.WriteLine("After time Sort:");
            foreach (ResearchTeam h in a.ResLogs)
            {
                Console.WriteLine(h.ToString());
            }
            Console.WriteLine("Group Sort:");
            foreach (ResearchTeam h1 in a.NGroup(1))
            {
                Console.WriteLine(h1.ToString());
            }
            TestCollections test = new TestCollections(1000);

            Console.WriteLine("Search Time:");
            Console.WriteLine(test.GetTime());
            Console.ReadLine();
        }
Example #5
0
    static void Main(string[] args)
    {
        Person p1 = new Person("Fyodr", "Uncle", new DateTime(2000, 11, 4));
        Person p2 = new Person();

        Student s1 = new Student(p1, Education.Bachelor, 1);

        Exam cs      = new Exam();
        Exam math    = new Exam("math", 4, new DateTime(2021 - 5 - 6));
        Exam physics = new Exam("physics", 4, new DateTime(2021 - 5 - 7));

        Exam[] exams = new Exam[3];
        exams[0] = cs;
        exams[1] = math;
        exams[2] = physics;
        List <Exam> examsList = new List <Exam>();

        examsList.AddRange(exams);
        s1.AddExams(examsList);

        Test t = new Test();

        Test[] tests = new Test[1];
        tests[0] = t;
        List <Test> testsList = new List <Test>();

        testsList.AddRange(tests);
        s1.AddTests(testsList);

        Student s2  = new Student();
        Exam    ex1 = new Exam();

        Exam[] exams2 = new Exam[1];
        exams2[0] = ex1;
        List <Exam> examsList2 = new List <Exam>();

        examsList2.AddRange(exams);
        s1.AddExams(examsList2);


        StudentCollection stcl = new StudentCollection();

        Student[] st = new Student[2];
        st[0] = s1;
        st[1] = s2;
        stcl.AddStudents(st);

        Console.WriteLine(stcl.ToString());
        stcl.compareByMeanValue();
        Console.WriteLine("compareByMeanValue " + stcl.ToShortString());
        stcl.compareByLastName();
        Console.WriteLine("compareByLastName " + stcl.ToShortString());
        stcl.compareByBirthdate();
        Console.WriteLine("compareByBirthdate " + stcl.ToShortString());

        Console.WriteLine("max mean value: " + stcl.maxMean);
        Console.WriteLine("specialists: " + stcl.specialists.ToString());

        // var grouped = stcl.AverageMarkGroup(4);
        // Console.WriteLine("grouped: ", grouped.ToString());

        TestCollections tc = new TestCollections(3);

        tc.findElementInList();
        tc.findElemetKeyDictionary();
        tc.findEdlemetValueDictionary();
    }
Example #6
0
        static void Main(string[] args)
        {
            //===============================lab1=================================
            /*Magazine magazine = 
                new Magazine("How to find...", Frequency.Yearly, new DateTime(2016, 11, 12), 1, new Article[] {new Article()});


            Console.WriteLine("Yarly: " + magazine[Frequency.Yearly]);
            Console.WriteLine("Monthly: " + magazine[Frequency.Montly]);
            Console.WriteLine("Weekly: " + magazine[Frequency.Weekly]);

            magazine.Shedule = Frequency.Yearly;
            magazine.Articles = new Article[] {new Article(new Person("Poll", "Tripp", new DateTime(1,1,1)), "Word's war", 6.7)};
            magazine.Edition = 500;
            magazine.Release = DateTime.Now;
            magazine.Title = "Last hope";
            
            Console.WriteLine(magazine);

            Article[] articles = new Article[]
            {
                new Article(new Person("Poll", "Tripp", new DateTime(1,1,1)), "Word's war", 6.7),
                new Article(new Person("Mia", "Ogliche", new DateTime(1,1,1)), "Girl with lovely heart", 4.3),
                new Article(new Person("Stiv", "Nesh", new DateTime(1,1,1)), "Evangelism", 9.1)
           
            };

            magazine.AddArticles(articles);

            Console.WriteLine(magazine);

            Method();
       
            Console.ReadLine();*/

            //================================Lab2=====================
            Edition ed1 = new Edition();
            Edition ed2 = new Edition();
            Console.WriteLine("ed1 equals ed2 {0}\n{1} - reference equals.", ed1.Equals(ed2), Object.ReferenceEquals(ed1, ed2));
            try
            {
                ed1.Edition = -1;
            }
            catch (Exception ex)
            {
                Console.WriteLine("Circulation can not be negative!\n" + ex.Message);
            }

            Article[] arts3 = new Article[2];
            arts3[0] = new Article(p1, "Title 1", 99.9);
            arts3[1] = new Article();
            Article[] arts4 = new Article[2];
            arts4[0] = new Article(p1, "Title 2", 59.9);
            arts4[1] = new Article(p2, "Title 4", 66.4);
            Person[] edtrs = new Person[3];
            edtrs[0] = new Person("Name1", "LastName1", new DateTime(1966, 10, 10));
            edtrs[1] = new Person("Name2", "LastName2", new DateTime(1982, 12, 31));
            edtrs[2] = new Person();

            Magazine m4 = new Magazine("Magazine 1", Frequency.Monthly, new DateTime(2000, 1, 1), 1000);
            m4.AddEditors(edtrs);
            m4.AddArticles(arts3);
            Console.WriteLine("{0},\n{1}", m4.ToString(), m4.EditionProp);

            var deepCopy = (Magazine)m4.DeepCopy();
            m4.Edition = 2000;
            m4.Release = new DateTime(1999, 12, 12);
            m4.AddArticles(arts4);

            Console.WriteLine("m4:\n{0}\nDeep copy:\n{1}", m4.ToString(), deepCopy.ToString());
            Console.WriteLine("Top articles:");
            foreach (Article m in m4.TopArticles(60))
                Console.WriteLine(m.ToString());
            Console.WriteLine("Similar articles:");
            foreach (Article m in m4.SimilarArticles("title"))
                Console.WriteLine(m.ToString());



            Console.WriteLine("\nMagazineEnumerator:");
            foreach (Article art in m4.ArticlesList)
            {
                Console.WriteLine("{0}", art.ToString());
            }

            Console.WriteLine("\nArticles by editors:");
            foreach (Article art in m4.ArticlesByEditors())
                Console.WriteLine(art.ToString());

            Console.WriteLine("\nEditors without articles:");
            foreach (Person p in m4.EditorsWithoutArticles())
                Console.WriteLine(p.ToString());

            //=====================================lab3=================================
          
            MagazineCollection mc = new MagazineCollection();
            mc.AddDefaults();
            //Console.WriteLine("\nMagazines:");
            //mc.ToString();
            Console.WriteLine("\nBy title:");
            mc.SortByTitle();
            Console.WriteLine(mc.ToString());
            Console.WriteLine("By release date:");
            mc.SortByReleaseDate();
            Console.WriteLine(mc.ToString());
            Console.WriteLine("By circulation:");
            mc.SortByCiculation(true);
            Console.WriteLine(mc.ToString());

            Console.WriteLine(mc.maxAverageRating);
            IEnumerable monthly = mc.GetMonthly;
            foreach (Magazine m in monthly)
                Console.WriteLine(m.ToString());
            double minrate = 70;
            Console.WriteLine("rating more than {0}:", minrate);
            List<Magazine> l = mc.RatingGroup(minrate);
            foreach (Magazine m in l)
                Console.WriteLine(m.ToString());
            int quantity = 1000;
            TestCollections collections = new TestCollections(quantity);
            Edition e1 = new Edition();
            e1.Title = e1.Title + "-0";
            Edition e2 = new Edition();
            e2.Title = e2.Title + "-" + (quantity - 1);
            Edition e3 = new Edition();
            e3.Title = e3.Title + "-" + quantity / 2;
            Edition e4 = new Edition();
            e4.Title = e4.Title + "10";

            /*Console.WriteLine("The first: {0}",collections.SearchingTime(e1));
			Console.WriteLine("The last: {0}", collections.SearchingTime(e2));
			Console.WriteLine("The middle: {0}", collections.SearchingTime(e3));
			Console.WriteLine("Not belongs to list: {0}", collections.SearchingTime(e4));*/
            Console.WriteLine("///////////////////////////Lab 4////////////////////");
      
            //==============================lab4=============================================

            MagazineCollection col1 = new MagazineCollection();
            MagazineCollection col2 = new MagazineCollection();

            Listener l1 = new Listener();
            Listener l2 = new Listener();
            col1.MagazineAdded += l1.EventHandler;
            col1.MagazineReplaced += l1.EventHandler;

            col2.MagazineAdded += l2.EventHandler;
            col2.MagazineReplaced += l2.EventHandler;
            col1.MagazineAdded += l2.EventHandler;
            col1.MagazineReplaced += l2.EventHandler;

            col1.collectionName = "Collection 1";
            col2.collectionName = "Collection 2";

            col1.AddDefaults();
            col2.AddDefaults();
            col2[1] = new Magazine();
            col1[3] = new Magazine();
            col1.Replace(2, new Magazine());
            Console.WriteLine("First listener:\n{0}", l1.ToString());

            Console.WriteLine("Second listener:\n{0}", l2.ToString());


            Console.WriteLine("///////////////////////////Lab 5////////////////////");
          
            //=================================lab5=========================

            Magazine mag1 = new Magazine();

            mag1.AddEditors(edtrs);
            mag1.AddArticles(arts3);
            mag1.Title = "Magazine to save";
            mag1.Circulation = 100500;
            mag1.Rate = Frequency.Monthly;
            Magazine mag1Copy = Magazine.DeepCopy(mag1);
            Console.WriteLine("Original object: {0}", mag1.ToString());
            Console.WriteLine("Deepcopy object: {0}", mag1Copy.ToString());
            Console.WriteLine("Type in a name of the file:");
            string file = Console.ReadLine();
            mag1.Load(file);
            Console.WriteLine(mag1.ToString());
            mag1.AddFromConsole();
            mag1.Save(file);
            Console.WriteLine(mag1.ToString());
            Magazine.Load(file, mag1);
            mag1.AddFromConsole();
            Magazine.Save(file, mag1);
            //mag1.Save("mag1.txt");
            /*Magazine mag2 = new Magazine();
			mag2.Load("mag1.txt");
			
			
			Console.WriteLine("Saved object: {0}", mag1.ToString());
			Console.WriteLine("Object from file: {0}", mag2.ToString());

			Magazine mag3 = new Magazine();
			mag3.AddFromConsole();
			*/

            Console.ReadLine();
        }
        // Запрос LINQ: Суммарное количество жителей всех стран на континенте (агрегирование данных)
        static void SumPoeopleContinentLINQ(TestCollections list, string continent)
        {
            int count = (from region in list.Regions where region.Continent == continent select region.PopulationSize).ToArray().Sum();

            Console.WriteLine("Суммарное количество жителей всех стран на континенте " + continent + " = " + count);
        }
Example #8
0
        private void LoadTestCollections()
        {
            IList <string> testCollectionFiles = null;

            try
            {
                testCollectionFiles = _testCollectionServiceService.GetTestCollectionFiles();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message, "Error Loading TestCollections", MessageBoxButton.OK, MessageBoxImage.Error);
            }

            if (testCollectionFiles == null)
            {
                return;
            }

            foreach (var testCollectionFile in testCollectionFiles)
            {
                TestCollection testCollection = null;

                try
                {
                    testCollection = _testCollectionServiceService.GetTestCollection(testCollectionFile);
                }
                catch (Exception e)
                {
                    MessageBox.Show("TestCollection: " + testCollectionFile + Environment.NewLine + e.Message,
                                    "Error Loading TestCollection", MessageBoxButton.OK, MessageBoxImage.Error);
                }

                if (testCollection == null)
                {
                    return;
                }

                var testCollectionViewModel = new TestCollectionViewModel
                {
                    Domain    = testCollection.DefaultDomain,
                    IsEnabled = testCollection.Enabled,
                    Name      = testCollection.File
                };

                if (testCollection.Tests == null)
                {
                    return;
                }

                foreach (var test in testCollection.Tests)
                {
                    var testViewModel = new TestViewModel
                    {
                        IsEnabled = test.Enabled,
                        Name      = test.Name,
                        Url       = test.Url,
                        IsEnabledChangedCommand = new RelayCommand(enabled =>
                        {
                            test.Enabled = (bool)enabled;
                            _testCollectionServiceService.SaveTestCollection(testCollection);
                        })
                    };

                    if (test.Commands == null)
                    {
                        return;
                    }

                    foreach (var command in test.Commands)
                    {
                        var commandViewModel = new CommandViewModel
                        {
                            Name    = command.Name,
                            Command = command,
                        };

                        var properties = _commandService.GetCommandValues(command);

                        foreach (var item in properties)
                        {
                            commandViewModel.Properties.Add(new CommandPropertyViewModel
                            {
                                Name  = item.Key,
                                Value = item.Value
                            });
                        }

                        testViewModel.Children.Add(commandViewModel);
                    }

                    testCollectionViewModel.Children.Add(testViewModel);
                }

                TestCollections.Add(testCollectionViewModel);
            }
        }
        // Метод расширения: Суммарное количество жителей всех стран на континенте (агрегирование данных)
        static void SumPoeopleContinentExtension(TestCollections list, string continent)
        {
            int count = list.Regions.Where(region => region.Continent == continent).Select(region => region.PopulationSize).ToArray().Sum();

            Console.WriteLine("Суммарное количество жителей всех стран на континенте " + continent + " = " + count);
        }
Example #10
0
        static void Main(string[] args)
        {
            TestCollections collections1 = new TestCollections(10);

            for (int i = 0; i < collections1.Size; i++)
            {
                Region region = new Region();
                region.RandomCreate();
                collections1[i] = region;
            }

            TestCollections collections2 = new TestCollections(5);

            for (int i = 0; i < collections2.Size; i++)
            {
                Region region = new Region();
                region.RandomCreate();
                collections2[i] = region;
            }

            int number = TypeInquiry();

            while (number != 0)
            {
                Console.Clear();

                switch (number)
                {
                case 1:
                {
                    int type = NumberUnquiry(number);
                    switch (type)
                    {
                    case 1:
                        ListRegionLINQ(collections1, "Россия");
                        break;

                    case 2:
                        CountPeopleCountryLINQ(collections1, 200000);
                        break;

                    case 3:
                        SumPoeopleContinentLINQ(collections1, "Евразия");
                        break;

                    case 4:
                        CommonItemsInCollectionsLINQ(collections1, collections2);
                        break;

                    case 5:
                        ExceptItemsInCollectionsLINQ(collections1, collections2);
                        break;
                    }
                }
                break;

                case 2:
                {
                    int type = NumberUnquiry(number);
                    switch (type)
                    {
                    case 1:
                        ListRegionExtension(collections1, "Китай");
                        break;

                    case 2:
                        CountPeopleCountryExtension(collections1, 100000);
                        break;

                    case 3:
                        SumPoeopleContinentExtension(collections1, "Африка");
                        break;

                    case 4:
                        CommonItemsInCollectionsExtension(collections2, collections1);
                        break;

                    case 5:
                        ExceptItemsInCollectionsExtension(collections2, collections1);
                        break;
                    }
                }
                break;
                }

                Console.Clear();
                number = TypeInquiry();
            }
        }
Example #11
0
        // Метод расширения:	Количество регионов с данным населением (получение счетчика)
        static void CountPeopleCountryExtension(TestCollections list, int populationSize)
        {
            var regionlist = list.Regions.Where(region => region.PopulationSize == populationSize).Count();

            Console.WriteLine("Количество регионов с населением в " + populationSize + " человек = " + regionlist);
        }
Example #12
0
        private static void Main(string[] args)
        {
            Person[] members = new Person[] { new Person("first" + 3, "last" + 3, new DateTime(3 + 1970, 3 % 12, 3 % 27)),
                                              new Person("first" + 2, "last" + 2, new DateTime(2 + 1970, 2 % 12, 2 % 27)),
                                              new Person("first" + 1, "last" + 1, new DateTime(1 + 1970, 1 % 12, 1 % 27)) };
            ResearchTeamCollection researchTeamCollection = new ResearchTeamCollection();

            ResearchTeam[] researchTeams = new ResearchTeam[]
            {
                new ResearchTeam("name" + 3, "study" + 3, 3 + 1, Enums.TimeFrame.Year,
                                 new List <Paper> {
                    new Paper("some" + 3, new Person("first" + 1, "last" + 1, new DateTime(3 + 1970, 3 % 12, 3 % 27)),
                              new DateTime(3 + 1970, 3 % 12, 3 % 27))
                }),
                new ResearchTeam("name" + 1, "study" + 1, 1 + 1, Enums.TimeFrame.TwoYears,
                                 new List <Paper> {
                    new Paper("some" + 1, new Person("first" + 1, "last" + 1, new DateTime(1 + 1970, 1 % 12, 1 % 27)),
                              new DateTime(1 + 1970, 1 % 12, 1 % 27))
                }),
                new ResearchTeam("name" + 50, "study" + 50, 50 + 1, Enums.TimeFrame.Year,
                                 new List <Paper> {
                    new Paper("some" + 50, new Person("first" + 1, "last" + 1, new DateTime(50 + 1970, 50 % 12, 50 % 27)),
                              new DateTime(50 + 1970, 50 % 12, 50 % 27))
                }),
                new ResearchTeam("name" + 21, "study" + 21, 21 + 1, Enums.TimeFrame.Year,
                                 new List <Paper> {
                    new Paper("some" + 21, new Person("first" + 1, "last" + 1, new DateTime(21 + 1970, 21 % 12, 21 % 27)),
                              new DateTime(21 + 1970, 21 % 12, 21 % 27))
                })
            };
            researchTeams[0].Members = members.Skip(2).ToList();
            researchTeams[1].Members = members.Skip(1).ToList();
            researchTeams[2].Members = members.ToList();
            researchTeamCollection.AddResearchTeams(researchTeams);
            Console.WriteLine(researchTeamCollection.ToString());

            researchTeamCollection.SortByRegistrationNumber();
            Console.WriteLine(researchTeamCollection.ToString());

            researchTeamCollection.SortByExploreTheme();
            Console.WriteLine(researchTeamCollection.ToString());

            researchTeamCollection.SortByCountOfPublishing();
            Console.WriteLine(researchTeamCollection.ToString());

            Console.WriteLine(researchTeamCollection.MinRegistryNumber);

            var str = string.Join(Environment.NewLine, researchTeamCollection.GetTwoYearsLongResearchTeams.Select(x => x.ToString()));

            Console.WriteLine(str);

            str = string.Join(Environment.NewLine, researchTeamCollection.NGroup(1).Select(x => x.ToString()));
            Console.WriteLine(str);

            TestCollections testCollections = new TestCollections(2000000);

            testCollections.TestCollectionsProductivity(1);
            testCollections.TestCollectionsProductivity(1000001);
            testCollections.TestCollectionsProductivity(1999999);
            testCollections.TestCollectionsProductivity(20000001);

            Console.ReadKey();
        }
Example #13
0
        static void Main()
        {
            var student = new Student
            {
                Birthday = DateTime.Parse("01.03.1994"),
                Exams = new List<Exam>
                {
                    new Exam {DisciplineName = "English", Mark = 6, Date = DateTime.Parse("03.12.2015")},
                    new Exam {DisciplineName = "Math", Mark = 3, Date = DateTime.Parse("03.05.2015")},
                    new Exam {DisciplineName = "Physics", Mark = 7, Date = DateTime.Parse("03.21.2015")},
                    new Exam {DisciplineName = "Biology", Mark = 5, Date = DateTime.Parse("03.17.2015")}
                },
                Education = Education.Bachelor
            };

            Console.WriteLine($"Source student:\n{student}\n");

            Console.WriteLine("Sorted exams by discipline name:\n");
            student.SortExamsByDisciplineName();
            Console.WriteLine(student);
            Console.WriteLine();

            Console.WriteLine("Sorted exams by mark:\n");
            student.SortExamsByMark();
            Console.WriteLine(student);
            Console.WriteLine();

            Console.WriteLine("Sorted exams by date:\n");
            student.SortExamsByDate();
            Console.WriteLine(student);
            Console.WriteLine();

            var students = new StudentCollection<string>(s => s.PersonId.ToString());
            students.AddDefaults(2);

            var student2 = new Student
            {
                Education = Education.Bachelor,
                Exams = new List<Exam>
                {
                    new Exam {DisciplineName = "English", Mark = 4, Date = DateTime.Parse("03.12.2015")},
                    new Exam {DisciplineName = "Math", Mark = 7, Date = DateTime.Parse("03.05.2015")},
                    new Exam {DisciplineName = "Physics", Mark = 9, Date = DateTime.Parse("03.21.2015")},
                    new Exam {DisciplineName = "Biology", Mark = 10, Date = DateTime.Parse("03.17.2015")}
                }
            };

            var student3 = new Student
            {
                Education = Education.Bachelor,
                Exams = new List<Exam>
                {
                    new Exam {DisciplineName = "English", Mark = 7, Date = DateTime.Parse("03.12.2015")},
                    new Exam {DisciplineName = "Math", Mark = 4, Date = DateTime.Parse("03.05.2015")},
                    new Exam {DisciplineName = "Physics", Mark = 8, Date = DateTime.Parse("03.21.2015")},
                    new Exam {DisciplineName = "Biology", Mark = 6, Date = DateTime.Parse("03.17.2015")}
                }
            };

            students.AddStudents(student, student2, student3);
            Console.WriteLine($"StudentCollection<string>:\n{students}");
            Console.WriteLine();
            Console.WriteLine($"StudentCollection<string>(short):\n{students.ToShortString()}");
            Console.WriteLine();

            Console.WriteLine($"Max average mark: {students.MaxAverageMark}\n");

            Console.WriteLine("The list of Bachelors:");
            var bachelors = students.GetWithEducationForm(Education.Bachelor);
            foreach (var bachelor in bachelors)
            {
                Console.WriteLine(bachelor.Value);
            }
            Console.WriteLine();

            Console.WriteLine("Grouping by education:");
            var grouped = students.GroupByEducation;
            foreach (var group in grouped)
            {
                Console.WriteLine($"{group.Key}:");
                foreach (var item in group)
                {
                    Console.WriteLine(item.Value);
                }
                Console.WriteLine();
            }


            var testCollections = new TestCollections<Person, Student>(5, count =>
            {
                var tempStudent = new Student();
                return new KeyValuePair<Person, Student>(tempStudent.Key, tempStudent);
            });
            for (var att = 0; att < TestAttemptsCount; att++)
            {
                Console.WriteLine($"************************ TEST {att} ************************");
                testCollections.PerformSearch(testCollections.Value,
                    tuple => Console.WriteLine($"{tuple.Item1} : {tuple.Item2}"));
                Console.WriteLine();
            }
        }
Example #14
0
        static void Main()
        {
            var person1 = new Person("Dzmitry", "Paulouski", new DateTime(1994, 3, 1));

            var student = new Student(
                person1,
                Education.Specialist,
                500);

            var studentCollection = new StudentCollection();
            studentCollection.AddDefaults(3);

            Console.WriteLine("StudentCollection:");
            Console.WriteLine(studentCollection);
            Console.WriteLine();

            Console.WriteLine("Sorting by LastName ****************************************");
            Console.WriteLine();
            studentCollection.SortByLastName();
            Console.WriteLine(studentCollection);
            Console.WriteLine();
            

            studentCollection.AddStudents(
                new Student
                {
                    Birthday = DateTime.Parse("01.03.1994"),
                    Exams = new List<Exam>
                    {
                        new Exam {DisciplineName = "English", Mark = 6},
                        new Exam {DisciplineName = "Math", Mark = 3},
                        new Exam {DisciplineName = "Physics", Mark = 6},
                        new Exam {DisciplineName = "Biology", Mark = 5}
                    }
                }, 
                new Student
                {
                    Birthday = DateTime.Parse("02.04.1987"),
                    Exams = new List<Exam>
                    {
                        new Exam {DisciplineName = "English", Mark = 3},
                        new Exam {DisciplineName = "Math", Mark = 4},
                        new Exam {DisciplineName = "Physics", Mark = 7},
                        new Exam {DisciplineName = "Biology", Mark = 4}
                    }
                },
                new Student
                {
                    Birthday = DateTime.Parse("02.04.1984"),
                    Exams = new List<Exam>
                    {
                        new Exam {DisciplineName = "English", Mark = 3},
                        new Exam {DisciplineName = "Math", Mark = 4},
                        new Exam {DisciplineName = "Physics", Mark = 7},
                        new Exam {DisciplineName = "Biology", Mark = 4}
                    }
                },
                new Student
                {
                    Birthday = DateTime.Parse("02.04.1997"),
                    Exams = new List<Exam>
                    {
                        new Exam {DisciplineName = "English", Mark = 6},
                        new Exam {DisciplineName = "Math", Mark = 3},
                        new Exam {DisciplineName = "Physics", Mark = 6},
                        new Exam {DisciplineName = "Biology", Mark = 5}
                    }
                }
            );

            Console.WriteLine("Sorting by Birthday ****************************************");
            Console.WriteLine();
            studentCollection.SortByBirthdayDate();
            Console.WriteLine(studentCollection);
            Console.WriteLine();


            Console.WriteLine("Sorting by AverageMark *************************************");
            Console.WriteLine();
            studentCollection.SortByAverageMark();
            Console.WriteLine(studentCollection.ToShortString());
            Console.WriteLine();


            Console.WriteLine("Grouping by AverageMark *************************************");
            Console.WriteLine();
            var grouped = studentCollection.AverageMarkGroup(3);
            foreach (var group in grouped)
            {
                Console.WriteLine($"Grouped by {group.Key}");
                foreach (var stud in group)
                {
                    Console.WriteLine(stud.ToShortString());
                }
                Console.WriteLine();
            }
            Console.WriteLine(studentCollection.ToShortString());
            Console.WriteLine();


            var testCollections = new TestCollections<Person, Student>(7);
            for (var att = 0; att < TestAttemptsCount; att++)
            {
                Console.WriteLine($"************************ TEST {att} ************************");
                testCollections.PerformSearch(testCollections.Value,
                    tuple => Console.WriteLine($"{tuple.Item1} : {tuple.Item2}"));
                Console.WriteLine();
            }


            Console.WriteLine();
        }
Example #15
0
        static void Main(string[] args)
        {
            TestCollections testCollections = new TestCollections(1000);
            Place           searchPZ = null, searchPM = null, searchPL = null;
            Area            searchArZ = null, searchArM = null, searchArL = null;
            City            searchCZ = null, searchCM = null, searchCL = null;
            Megapolice      searchMZ = null, searchMM = null, searchML = null;
            Address         searchAdZ = null, searchAdM = null, searchAdL = null;

            #region ifelse
            if (testCollections.CollectionOneList[0] is Address)
            {
                searchAdZ = (Address)testCollections.CollectionOneList[0].Clone();
            }
            else if (testCollections.CollectionOneList[0] is Megapolice)
            {
                searchMZ = (Megapolice)testCollections.CollectionOneList[0].Clone();
            }
            else if (testCollections.CollectionOneList[0] is City)
            {
                searchCZ = (City)testCollections.CollectionOneList[0].Clone();
            }

            else if (testCollections.CollectionOneList[0] is Area)
            {
                searchArZ = (Area)testCollections.CollectionOneList[0].Clone();
            }
            else if (testCollections.CollectionOneList[0] is Place)
            {
                searchPZ = (Place)testCollections.CollectionOneList[0].Clone();
            }
            if (testCollections.CollectionOneList[499] is Address)
            {
                searchAdM = (Address)testCollections.CollectionOneList[499].Clone();
            }
            else if (testCollections.CollectionOneList[499] is Megapolice)
            {
                searchMM = (Megapolice)testCollections.CollectionOneList[499].Clone();
            }
            else if (testCollections.CollectionOneList[499] is City)
            {
                searchCM = (City)testCollections.CollectionOneList[499].Clone();
            }

            else if (testCollections.CollectionOneList[499] is Area)
            {
                searchArM = (Area)testCollections.CollectionOneList[499].Clone();
            }
            else if (testCollections.CollectionOneList[499] is Place)
            {
                searchPM = (Place)testCollections.CollectionOneList[499].Clone();
            }
            if (testCollections.CollectionOneList[999] is Address)
            {
                searchAdL = (Address)testCollections.CollectionOneList[999].Clone();
            }
            else if (testCollections.CollectionOneList[999] is Megapolice)
            {
                searchML = (Megapolice)testCollections.CollectionOneList[999].Clone();
            }
            else if (testCollections.CollectionOneList[999] is City)
            {
                searchCL = (City)testCollections.CollectionOneList[999].Clone();
            }

            else if (testCollections.CollectionOneList[999] is Area)
            {
                searchArL = (Area)testCollections.CollectionOneList[999].Clone();
            }
            else if (testCollections.CollectionOneList[999] is Place)
            {
                searchPL = (Place)testCollections.CollectionOneList[999].Clone();
            }
            #endregion
            DateTime DtStart = DateTime.Now;
            #region ifelse
            if (!(searchPZ is null))
            {
                Console.WriteLine(testCollections.CollectionOneList.Contains(searchPZ));
            }