Exemplo n.º 1
0
        public bool Replace(int index, Magazine magazine)
        {
            if (index < 0 || index >= _magazines.Count)
            {
                return(false);
            }
            var handler = MagazineReplaced;

            _magazines[index] = magazine;
            handler?.Invoke(this, new MagazineListHandlerEventArgs(Name, "Replaced", index));
            return(true);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Person person = new Person("AuthorFirstName", "AuthorLastName", new DateTime(1849, 9, 13));

            Console.WriteLine(person);
            Article myArticle = new Article(person, "My Article", 5);

            Magazine magazine = new Magazine("Weekly magazine", Frequency.WEEKLY, new DateTime(2020, 2, 10), 50);

            magazine.AddArticles(new Article());
            Console.WriteLine(magazine.ToShortString());

            Console.WriteLine("Is magazine weekly: " + magazine[Frequency.WEEKLY]);
            Console.WriteLine("Is magazine montly: " + magazine[Frequency.MONTLY]);
            Console.WriteLine("Is magazine yearly: " + magazine[Frequency.YEARLY]);

            magazine.Name        = "Montly magazine";
            magazine.Articles    = new Article[] { myArticle };
            magazine.Frequency   = Frequency.MONTLY;
            magazine.Quantity    = 22;
            magazine.ReleaseDate = new DateTime(2020, 3, 10);
            Console.WriteLine(magazine.ToString());

            magazine.AddArticles(new Article(person, "Some new article", 7));
            Console.WriteLine(magazine.ToString());

            Console.WriteLine("\n");
            Console.WriteLine("Enter nRows {divider} nCols");
            Console.WriteLine("Allowed dividers: '*', 'x', ',', ' '");
            string rawInput = Console.ReadLine();

            string[] nSize = rawInput.Split('*', 'x', ',', ' ');
            int      nRows = int.Parse(nSize[0].Trim());
            int      nCols = int.Parse(nSize[1].Trim());

            PrintOneDimensionTime(nRows, nCols);
            GC.Collect();

            PrintTwoDimensionTime(nRows, nCols);
            GC.Collect();

            PrintTeethArrayTime(nRows, nCols);
            GC.Collect();

            Console.ReadLine();
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Magazine m = new Magazine();

            Console.WriteLine(m.ToShortString());
            Console.WriteLine($"\n{Frequency.Yearly} => {m[Frequency.Yearly]}");
            Console.WriteLine($"{Frequency.Montly} => {m[Frequency.Montly]}");
            Console.WriteLine($"{Frequency.Weekly} => {m[Frequency.Weekly]}\n");
            m.addArticles(new Article[] {
                new Article(new Person("First Name", "Last Name", new DateTime(1990, 1, 15)), "Most Popular", 7.4)
            });
            m.setName("New Name");
            m.setPublicationDate(new DateTime(2017, 1, 1));
            m.setEdition(2);
            m.setFrequency(Frequency.Weekly);
            Console.WriteLine(m.ToString());

            Console.ReadLine();
        }
Exemplo n.º 4
0
 protected bool Equals(Magazine other)
 {
     return(string.Equals(_magazineName, other._magazineName) && _timing == other._timing && _magazineDate.Equals(other._magazineDate) && _magazineCirculation == other._magazineCirculation && Equals(_article, other._article));
 }
Exemplo n.º 5
0
        private static void Main(string[] args)
        {
            var magazine = new Magazine
            {
                Name = "test"
            };

            var copy = magazine.DeepCopy();

            copy.Name = "Copy";

            Console.WriteLine($"Original:{Environment.NewLine}{magazine}"
                              + $"{Environment.NewLine}Copy:{Environment.NewLine}{copy}");

            Console.Write("Enter file name: ");
            var filename = Console.ReadLine();

            var directory = "WrongPath";

            try
            {
                directory = Path.GetDirectoryName(filename);
            }
            catch
            {
                Console.WriteLine("Input is not correct path");
            }

            while (directory == "WrongPath" || !Directory.Exists(directory))
            {
                Console.WriteLine("Directory does not exist");
                Console.Write("Enter file name: ");
                filename = Console.ReadLine();
                try
                {
                    directory = Path.GetDirectoryName(filename);
                }
                catch
                {
                    Console.WriteLine("Input is not correct path");
                }
            }

            if (File.Exists(filename))
            {
                magazine.Load(filename);
            }
            else
            {
                Console.WriteLine("New file will be created");
            }

            Console.WriteLine(magazine);

            magazine.AddFromConsole();

            magazine.Save(filename);

            Magazine.Load(filename, magazine);
            magazine.AddFromConsole();
            Magazine.Save(filename, magazine);
            Console.WriteLine(magazine);

            Console.ReadKey();
        }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            Magazine magazine = new Magazine("New York Times", Frequency.Monthly, new DateTime(2009, 12, 31), 300);

            Console.WriteLine(magazine.ToShortString());

            Console.WriteLine($"Weekly: {magazine[Frequency.Weekly]}");
            Console.WriteLine($"Monthly: {magazine[Frequency.Monthly]}");
            Console.WriteLine($"Yearly: {magazine[Frequency.Yearly]}");

            magazine.FrequencyMagazine = Frequency.Weekly;
            magazine.EditionMagazine   = 21;
            magazine.NameMagazine      = "Daily Bugles";
            magazine.DatePublished     = new DateTime(2012, 11, 11);
            Console.WriteLine(magazine.ToString());

            magazine.AddArticles(new Article(new Person("Mary", "Watson", new DateTime(1990, 09, 02)), "SCI-FI", 9.9));
            Console.WriteLine(magazine.ToString());

            Console.WriteLine("---------------------------");

            //-------------------Time-----------------------
            Console.Write("Delimiters: ");
            String delimiter = Console.ReadLine();

            Console.Write("Input count of rows and cols, using delimiter: ");
            String[] rowsCols = Console.ReadLine().Split(delimiter.ToCharArray());

            int rows = int.Parse(rowsCols[0]);
            int cols = int.Parse(rowsCols[1]);

            Article[] normalArray = new Article[rows * cols];
            for (int i = 0; i < normalArray.Length; i++)
            {
                normalArray[i] = new Article();
            }

            Article[,] twoDimensiomalAray = new Article[rows, cols];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    twoDimensiomalAray[i, j] = new Article();
                }
            }

            Article[][] jaggedRectangularArray = new Article[rows][];
            for (int i = 0; i < rows; i++)
            {
                jaggedRectangularArray[i] = new Article[cols];
                for (int j = 0; j < cols; j++)
                {
                    jaggedRectangularArray[i][j] = new Article();
                }
            }

            int rowsCount = 0;
            int all       = rows * cols;

            while (all - rowsCount > 0)
            {
                all -= rowsCount;
                rowsCount++;
            }

            Article[][] jaggedArray = new Article[rowsCount][];
            for (int i = 0; i < rowsCount; i++)
            {
                jaggedArray[i] = new Article[i + 1];
                for (int j = 0; j < i + 1; j++)
                {
                    jaggedArray[i][j] = new Article();
                }
            }

            int startTime;
            int finishTime;

            startTime = Environment.TickCount;
            for (int i = 0; i < normalArray.Length; i++)
            {
                normalArray[i].Name = "Atricle 1";
            }

            finishTime = Environment.TickCount;

            Console.WriteLine($"\nNormal array \nCount of elements: {normalArray.Length} \nTime: {-startTime + finishTime}\n");

            startTime = Environment.TickCount;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    twoDimensiomalAray[i, j].Name = "Article1";
                }
            }
            finishTime = Environment.TickCount;

            Console.WriteLine($"Twodimensional array \nCount of rows: {rows}\nCount of cols: {cols}");
            Console.WriteLine($"Time: {-startTime + finishTime}\n");

            startTime = Environment.TickCount;
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < cols; j++)
                {
                    jaggedRectangularArray[i][j].Name = "Article1";
                }
            }
            finishTime = Environment.TickCount;

            Console.WriteLine($"Jagged rectangle array \nCount of rows: {rows}\nCount of cols: {cols}");
            Console.WriteLine($"Time: {-startTime + finishTime}\n");

            startTime = Environment.TickCount;
            for (int i = 0; i < rowsCount; i++)
            {
                for (int j = 0; j <= i; j++)
                {
                    jaggedArray[i][j].Name = "Article1";
                }
            }
            finishTime = Environment.TickCount;

            Console.Write($"Jagged array \nCount of rows: {rowsCount}\nCount of cols: ");
            foreach (Article[] arr in jaggedArray)
            {
                Console.Write($"{arr.Length} ");
            }
            Console.WriteLine($"\nTime: {-startTime + finishTime}");


            Console.ReadLine();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            Magazine one = new Magazine();

            Article[] article = new Article[3];
            article[0] = new Article(new Person("Tess", "Geritsen", new DateTime(1990, 10, 6)), "Fire!", 4.2);
            article[1] = new Article(new Person("Lion", "Getenberg", new DateTime(1995, 6, 13)), "Vegetables!", 4.8);
            article[2] = new Article(new Person("Jey", "Hirston", new DateTime(1997, 11, 24)), "Fruits!", 4.0);
            one        = new Magazine("Viva", Frequency.Monthly, DateTime.Now, 3, article);
            Console.WriteLine(one.ToShortString());
            Console.WriteLine(one.ToString());
            Console.WriteLine(one[Frequency.Yearly]);
            Article[] articles = new Article[2];
            articles[0] = new Article(new Person("Stephen", "King", new DateTime(1989, 5, 6)), "Joyland!", 5.0);
            articles[1] = new Article(new Person("Dan", "Braun", new DateTime(1970, 12, 23)), "Digital castle!", 4.8);
            one.AddArticles(articles);
            Console.WriteLine(one.ToString());
            string dimension = Console.ReadLine();

            string[] dim    = dimension.Split(' ');
            int      rows   = Convert.ToInt32(dim[0]);
            int      column = Convert.ToInt32(dim[1]);

            Stopwatch stopwatch1 = new Stopwatch();

            stopwatch1.Start();
            Article[] art1 = new Article[rows * column];
            for (int i = 0; i < column * rows; i++)
            {
                art1[i] = new Article();
            }
            stopwatch1.Stop();
            TimeSpan ts         = stopwatch1.Elapsed;
            string   elasedTime = String.Format("{0:00}:{1:00}:{2:00}:{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);

            Console.WriteLine("RunTime1 = " + elasedTime);

            Stopwatch stopwatch2 = new Stopwatch();

            stopwatch2.Start();
            Article[,] art2 = new Article[rows, column];
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    art2[i, j] = new Article();
                }
            }
            stopwatch2.Stop();
            TimeSpan ts2         = stopwatch2.Elapsed;
            string   elasedTime2 = String.Format("{0:00}:{1:00}:{2:00}:{3:00}", ts2.Hours, ts2.Minutes, ts2.Seconds, ts2.Milliseconds);

            Console.WriteLine("RunTime2 = " + elasedTime2);

            Stopwatch stopwatch3 = new Stopwatch();

            stopwatch3.Start();
            Article[][] art3 = new Article[rows][];
            for (int i = 0; i < rows; i++)
            {
                art3[i] = new Article[column];
                for (int j = 0; j < column; j++)
                {
                    art3[i][j] = new Article();
                }
            }
            stopwatch3.Stop();
            TimeSpan ts3         = stopwatch3.Elapsed;
            string   elasedTime3 = String.Format("{0:00}:{1:00}:{2:00}:{3:00}", ts3.Hours, ts3.Minutes, ts3.Seconds, ts3.Milliseconds);

            Console.WriteLine("RunTime3 = " + elasedTime3);
            Console.ReadLine();
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            Person   vasiaIvanov   = new Person("Vasia", "Ivanov", new DateTime(1998, 12, 12));
            Article  firstArtucle  = new Article(vasiaIvanov, "First", 10);
            Magazine firstMagazine = new Magazine();

            Console.WriteLine("First task is (toShortString):\n" + firstMagazine.ToShortString());
            Console.WriteLine("Second task is (Frequency):\n" + Frequency.Monthly + " " + Frequency.Weekly + " " + Frequency.Yearly);

            firstMagazine = new Magazine("My magazine", Frequency.Monthly, DateTime.Today, 10, new[] { firstArtucle });
            Console.WriteLine("Third task is (toString + magazine all params):\n" + firstMagazine);

            firstMagazine.AddArticles(firstArtucle, firstArtucle);
            Console.WriteLine("Fourth task is (toString + AddArticles):\n" + firstMagazine.ToString());

            Console.WriteLine("Fifth task is (timer in massifs):\n");
            string inputText = Console.ReadLine();

            int nRows    = Int32.Parse(inputText.Split(' ')[0]);
            int mColumns = Int32.Parse(inputText.Split(' ')[1]);

            int sum  = 0;
            int size = 0;

            while (sum < nRows * mColumns)
            {
                sum += ++size;
            }

            Article[] oneDimension = new Article[nRows * mColumns];
            Article[,] twoDimension = new Article[nRows, mColumns];
            Article[][] cogged = new Article[size][];

            var timeStart = Environment.TickCount;

            for (int i = 0; i < nRows * mColumns; i++)
            {
                oneDimension[i] = firstArtucle;
            }
            var timeEnd = Environment.TickCount;

            Console.WriteLine("\nOne dimension is: " + (timeEnd - timeStart));

            timeStart = Environment.TickCount;
            for (int i = 0; i < nRows; i++)
            {
                for (int j = 0; j < mColumns; j++)
                {
                    twoDimension[i, j] = firstArtucle;
                }
            }
            timeEnd = Environment.TickCount;
            Console.WriteLine("\nTwo dimension is: " + (timeEnd - timeStart));

            for (int i = 0; i < size; i++)
            {
                if (i == size - 1)
                {
                    cogged[i] = new Article[nRows * mColumns - (sum - size)];
                    break;
                }
                cogged[i] = new Article[i + 1];
            }

            timeStart = Environment.TickCount;
            foreach (var lineArray in cogged)
            {
                for (var j = 0; j < lineArray.Length; j++)
                {
                    lineArray[j] = firstArtucle;
                }
            }
            timeEnd = Environment.TickCount;
            Console.WriteLine("\nTwo dimension2 is: " + (timeEnd - timeStart));

            Console.Read();
        }