Beispiel #1
0
        public void AddDefaults()
        {
            Person p1 = new Person("First", "Stone", new DateTime(1880, 12, 02));
            Person p2 = new Person("Mia", "Humlight", new DateTime(1930, 7, 25));
            Person p3 = new Person("Toma", "Faithful", new DateTime(1945, 2, 27));

            Article[] arts1 = new Article[2];
            arts1[0] = new Article(new Person(), "Title ", 89);
            arts1[1] = new Article(new Person(), "Title 0", 100);
            Article[] arts2 = new Article[2];
            arts2[0] = new Article(p1, "Title 1", 99.9);
            arts2[1] = new Article(p2, "Title 2", 78);
            Article[] arts3 = new Article[2];
            arts3[0] = new Article(p2, "Title 3", 99.9);
            arts3[1] = new Article(p3, "Title 4", 56.9);
            Article[] arts4 = new Article[2];
            arts4[0] = new Article(p1, "Title 5", 76.1);
            arts4[1] = new Article(p2, "Title 6", 66.4);
            Magazine m1 = new Magazine("Some title", Frequency.Weekly, new DateTime(1950, 1, 1), 1200);
            Magazine m2 = new Magazine("Magazine", Frequency.Yearly, new DateTime(1990, 5, 4), 200);
            Magazine m3 = new Magazine("Some other magazine", Frequency.Monthly, new DateTime(2010, 11, 20), 5000);
            Magazine m4 = new Magazine();

            m1.AddArticles(arts3);
            m2.AddArticles(arts2);
            m3.AddArticles(arts4);
            m4.AddArticles(arts1);

            AddToList(m1);
            AddToList(m2);
            AddToList(m3);
            AddToList(m4);
        }
Beispiel #2
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();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            Magazine magazine = new Magazine();

            Console.WriteLine(magazine.ToShortString());

            Console.WriteLine(magazine[FrequencyEnum.Monthly]);
            Console.WriteLine(magazine[FrequencyEnum.Weekly]);
            Console.WriteLine(magazine[FrequencyEnum.Yearly]);

            magazine.name        = "Vogue";
            magazine.frequency   = FrequencyEnum.Monthly;
            magazine.circulation = 3;
            magazine.releaseDate = new DateTime(2021, 1, 31);
            magazine.articles    = new List <Article>()
            {
                new Article(new Person("Maryna", "Gulpak", new DateTime(2000, 4, 24)), "Fashion", 9.8), new Article(new Person("Yuri", "Kuz", new DateTime(1999, 7, 14)), "Models", 7.4)
            };

            Console.WriteLine($"\nMAGAZINE:\n\t{magazine.name}\n\t{magazine.frequency.ToString()}\n\t" +
                              $"{magazine.circulation.ToString()}" +
                              $"\n\t{magazine.releaseDate.ToString()}\n");

            foreach (var element in magazine.articles)
            {
                Console.WriteLine(element.ToString());
            }

            Console.WriteLine($"Average rating: {magazine.AverageRating}");
            magazine.AddArticles(new Article(new Person("Ihor", "Shapovalov", new DateTime(1971, 11, 29)), "Style", 7.9));
            Console.WriteLine(magazine.ToString());
            Console.WriteLine($"Average rating: {magazine.AverageRating}");

            int    nRows, nColumns;
            string strAmount;
            char   separator;

            Console.WriteLine("Please, choose the separator:  ,  /  .  \n");
            separator = Console.ReadKey().KeyChar;
            Console.WriteLine("\nAnd input amount of  rows and  amount of columns with chosen separator\n");
            strAmount = Console.ReadLine();

            var rowsAndColumnsAmount = strAmount.Split(separator);

            nRows    = Convert.ToInt32(rowsAndColumnsAmount.GetValue(0));
            nColumns = Convert.ToInt32(rowsAndColumnsAmount.GetValue(1));

            Article[] articlesOneDimensionalArray = new Article[nRows * nColumns];
            Article[,] articlesTwoDimensionalArray = new Article[nRows, nColumns];
            Article[][] articlesSteppedArray = new Article[nRows][];

            for (int i = 0; i < nRows * nColumns; i++)
            {
                articlesOneDimensionalArray[i] = new Article();
            }

            for (int i = 0; i < nRows; i++)
            {
                for (int j = 0; j < nColumns; j++)
                {
                    articlesTwoDimensionalArray[i, j] = new Article();
                }
            }

            for (int i = 0; i < nRows; i++)
            {
                articlesSteppedArray[i] = new Article[4];
            }
            for (int i = 0; i < nRows; i++)
            {
                for (int j = 0; j < nColumns; j++)
                {
                    articlesSteppedArray[i][j] = new Article();
                }
            }


            Stopwatch sw = new Stopwatch();

            sw.Start();
            long start1, result1, start2, result2, start3, result3;

            start1 = sw.ElapsedTicks;

            double startTimeOneDimensionalArray = Environment.TickCount;

            for (int i = 0; i < nRows * nColumns; i++)
            {
                articlesOneDimensionalArray[i].Name = "Mykola";
            }
            result1 = sw.ElapsedTicks - start1;
            sw.Stop();
            double endTimeOneDimensionalArray = Environment.TickCount;

            sw.Start();
            start2 = sw.ElapsedTicks;
            double startTimeTwoDimensionalArray = Environment.TickCount;

            for (int i = 0; i < nRows; i++)
            {
                for (int j = 0; j < nColumns; j++)
                {
                    articlesTwoDimensionalArray[i, j].Name = "Mykola";
                }
            }
            double endTimeTwoDimensionalArray = Environment.TickCount;

            result2 = sw.ElapsedTicks - start2;

            sw.Start();
            start3 = sw.ElapsedTicks;
            double startTimeSteppedArray = Environment.TickCount;

            for (int i = 0; i < nRows; i++)
            {
                for (int j = 0; j < nColumns; j++)
                {
                    articlesSteppedArray[i][j].Name = "Mykola";
                }
            }
            double endTimeSteppedArray = Environment.TickCount;

            result3 = sw.ElapsedTicks - start2;

            /*int resultTimeOneDimensionalArray = endTimeOneDimensionalArray - startTimeOneDimensionalArray;
             * int resultTimeTwoDimensionalArray = endTimeTwoDimensionalArray - startTimeTwoDimensionalArray;
             * int resultTimeSteppedArray = endTimeSteppedArray - startTimeSteppedArray;*/

            Console.WriteLine($"Rows: {nRows}\nColumns: {nColumns}\n\nOneDimensionalArrayTime: {result1} ms\n" +
                              $"TwoDimensionalArrayTime: {result2} ms\nSteppedArrayTime: {result3} ms");
        }