Esempio n. 1
0
        private static void Main(string[] args)
        {
            Stack Stack1 = new Stack();

            Stack1.Push(2); Stack1 = Stack1 + 5 + 6 + 3 + 9 + 4 + 111;
            Stack1--;
            Console.WriteLine("Current size of stack1 = {0}", Stack1.StackSize());
            Console.WriteLine("Stack1: "); Stack1.ShowStack();
            Console.WriteLine("Sum is: {0}", StatisticOperation.StackSum(Stack1));
            Console.WriteLine("Delta between min&max elements: {0}", StatisticOperation.DeltaBetweenMinAndMax(Stack1));
            Console.WriteLine("Number of elements in stack: {0}", StatisticOperation.CountElements(Stack1));
            Console.WriteLine("Average stack element: {0}", Stack1.Average());

            Stack Stack2 = new Stack();

            if (Stack2)
            {
                Console.WriteLine("Stack is empty");
            }

            Stack2 = Stack1 > Stack2;
            Console.WriteLine("Stack2");  Stack2.ShowStack();
            Console.WriteLine("Stack1");  Stack1.ShowStack();
            string String1 = "Предложение 1. Предложение 2. Предложение 3! Предложение 4?";

            Console.WriteLine("Строка \"{0}\", \nколичество предложений в строке: {1}", String1, String1.StringSentCount());
        }
Esempio n. 2
0
        static void Main()
        {
            List a = new List();
            List b = new List();

            b = "What's " + "up" + "?" + b;
            b.Listt();
            string s = "fist";

            a = s + a;
            a = "Sec" + a;
            a = "no" + a;
            a = "Hey" + a;
            a = "no" + a;
            a.Listt();
            Console.WriteLine(a.Letters() + " element(s) with a capital letter");
            if (a.Repeat())
            {
                Console.WriteLine("There are duplicate elements");
            }
            else
            {
                Console.WriteLine("No duplicates");
            }
            a = a--;
            a.Listt();
            if (a.Repeat())
            {
                Console.WriteLine("There are duplicate elements");
            }
            else
            {
                Console.WriteLine("No duplicates");
            }
            a = a * b;
            a.Listt();

            List.Owner owner = new List.Owner();
            Console.WriteLine(owner);
            List.Date date = new List.Date(24, 10, 2020);
            date.ShowDate();

            Console.WriteLine("Sum of array: " + StatisticOperation.CountSum(a));
            Console.WriteLine("Delta: " + StatisticOperation.CountDelta(a));
            Console.WriteLine("Number of elements: " + StatisticOperation.Number(a));

            string str = "Let's go home and sleep enough.Please!";

            Console.WriteLine($"-----string-----\n{str}");
            Console.WriteLine("Sentences in phrase: " + str.CountPhrases());
            string str1 = "Кошка съела паука! Тра-та-та";

            Console.WriteLine($"-----string-----\n{str1}");
            Console.WriteLine("Sentences in phrase: " + str1.CountPhrases());
            Console.ReadKey();
        }
Esempio n. 3
0
        public static void CallStaticClasses()
        {
            var collection1 = new Set <int>()
            {
                1, 5, 2, 8, 3
            };

            StatisticOperation.Sum(collection1);
            StatisticOperation.Difference(collection1);
            StatisticOperation.Count(collection1);
            Console.WriteLine(StatisticOperation.DotInTheEnd_ext("В конце должна стоять точка"));

            var list5 = new List <string>()
            {
                "test", "TEST", null, "Peepo", null, ":--D"
            };

            StatisticOperation.RemoveAllNull_ext(list5);
            foreach (var item in list5)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine("\nДлина: " + list5.Count);
        }
Esempio n. 4
0
        private static void Main(string[] args)
        {
            Stack <int> Stack1 = new Stack <int>();

            Stack1.Push(2); Stack1 = Stack1 + 5 + 6 + 3 + 9 + 4 + 111 + 2834;
            Stack1--;
            Console.WriteLine("Current size of stack1 = {0}", Stack1.StackSize());
            Console.WriteLine("Stack1: "); Stack1.Show();
            Console.WriteLine("Sum is: {0}", StatisticOperation.StackSum(Stack1));
            Console.WriteLine("Delta between min&max elements: {0}", StatisticOperation.DeltaBetweenMinAndMax(Stack1));
            Console.WriteLine("Number of elements in stack: {0}", StatisticOperation.CountElements(Stack1));
            Console.WriteLine("Average stack element: {0}", Stack1.Average());

            Stack <int> Stack2 = new Stack <int>();

            if (Stack2)
            {
                Console.WriteLine("Stack is empty");
            }

            Stack2 = Stack1 > Stack2;
            Console.WriteLine("Stack2"); Stack2.Show();
            Console.WriteLine("Stack1"); Stack1.Show();
            string String1 = "Предложение 1. Предложение 2. Предложение 3! Предложение 4?";

            Console.WriteLine("Строка \"{0}\", \nколичество предложений в строке: {1}", String1, String1.StringSentCount());

            Stack <float> Stack3 = new Stack <float>();

            Stack3.Push(8.65f);
            Stack3.Show();

            Stack <bool> BoolStack = new Stack <bool>();

            BoolStack = BoolStack + true + false + true + false + false;
            BoolStack.Show();


            Stack <Parrot> StackParrot = new Stack <Parrot>();
            Parrot         par1        = new Parrot();
            Parrot         par2        = new Parrot("Popug");
            Parrot         par3        = new Parrot("Пипиг", 2020);

            StackParrot.Push(par1);
            StackParrot = StackParrot + par2 + par3;
            StackParrot.Show();

            StreamWriter writer = null;

            try
            {
                writer = new StreamWriter(@"G:\3 семестр\ООТПиСП лабораторные\Лабораторная работа 8\Lab08\FileOut.txt", false);
                if (writer == null)
                {
                    throw new Exception("Ошибка открытия файла");
                }


                Stack2.WriteToFile(writer);
                Stack <int> Stack4 = new Stack <int>();
                string[]    temp   = StatisticOperation.ReadFromFile();
                foreach (string s in temp)
                {
                    Stack4 += Convert.ToInt32(s);
                }
                Stack4.Show();

                Stack4.WriteToFile(writer);
                StackParrot.WriteToFile(writer);
                Stack3.WriteToFile(writer);
                BoolStack.WriteToFile(writer);
            }
            finally
            {
                Console.WriteLine("Закрыть открытый файл");
                if (writer != null)
                {
                    writer.Close();
                }
            }
        }
Esempio n. 5
0
        static void Main(string[] args)
        {
            Set setFirst  = new Set();
            Set setFirst1 = new Set();
            Set setSecond = new Set();

            Set.Date.PrintDate();
            setFirst.ThisOwner.WriteOwner();

            for (int i = 0; i < 10; i++)
            {
                setFirst  = setFirst << i;
                setFirst1 = setFirst1 << i;
            }
            setFirst.PrintElem();
            setFirst1.PrintElem();

            for (int i = 5; i < 20; i++)
            {
                setSecond = setSecond << i;
            }
            setSecond.PrintElem();
            setSecond = setSecond >> 19;
            setSecond.PrintElem();

            if (setFirst == setFirst1)
            {
                Console.WriteLine("== is work");
            }

            if (setFirst != setSecond)
            {
                Console.WriteLine("!= is work");
            }

            Set setN = new Set();

            setN = setN << 9;
            setN.PrintElem();
            if (setN > setFirst)
            {
                Console.WriteLine("> is work");
            }

            Set setIntersection = setFirst % setSecond;

            setIntersection.PrintElem();

            Random rnd = new Random();

            for (int i = 0; i < 10; i++)
            {
                setN = setN << rnd.Next(0, 10);
            }
            setN.PrintElem();
            setN = StatisticOperation.Regulize(setN);
            setN.PrintElem();


            string str = "HELLO WORLD IT IS ME OLEG A";

            Console.WriteLine(str.FindMinimalWord());
        }
Esempio n. 6
0
        //  Вариант 4
        static void Main(string[] args)
        {
            var collection1 = new Set <int>()
            {
                1, 5, 2, 8, 3
            };
            var collectionUn = new Set <int>()
            {
                4, 2, 5, 8, 7
            };

            var collection2 = new Set <int>()
            {
                4, 6, 9, 7, 0
            };
            var collection3 = new Set <int>()
            {
                1, 2, 3
            };
            var collectionStr = new Set <string>()
            {
                "test", "123", null, "here_must_be_a_dot"
            };

            //---------------------------------------------
            // Extension Method 1
            String str = "There must be dot in the end";

            Console.WriteLine("Extension method 1: " + str.DotInTheEnd());
            //---------------------------------------------

            //---------------------------------------------
            //  Extension Method 2
            var listWithNull = new List <string>()
            {
                "test", "123", null, "peepo"
            };

            listWithNull.RemoveAllNull();
            Console.WriteLine("\n\nExtennsion method 2:");
            foreach (var item in listWithNull)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine("\nДлина: " + listWithNull.Count());
            //---------------------------------------------

            //---------------------------------------------
            // Проверка метода статического класса
            StatisticOperation.Sum(collection1);
            StatisticOperation.Difference(collection1);
            StatisticOperation.Count(collection1);
            Console.WriteLine(StatisticOperation.DotInTheEnd_ext("В конце должна стоять точка"));

            var list5 = new List <string>()
            {
                "test", "TEST", null, "Peepo", null, ":--D"
            };

            StatisticOperation.RemoveAllNull_ext(list5);
            foreach (var item in list5)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine("\nДлина: " + list5.Count);
            //---------------------------------------------

            //---------------------------------------------
            //  Вложенный объект
            Set <int> .Owner owner = new Set <int> .Owner();

            Console.WriteLine("\n\nИнициализация вложенного объекта");
            owner.Id      = 1;
            owner.Name    = "Sam";
            owner.OrgName = "Sony Inc.";
            Console.WriteLine("Id: " + owner.Id);
            Console.WriteLine("Name: " + owner.Name);
            Console.WriteLine("OrgName: " + owner.OrgName);
            //---------------------------------------------

            var res2 = collection1 & collectionUn;  //  Объединение

            Console.WriteLine("\n\nUnion:");
            foreach (int item in res2)
            {
                Console.Write($"{item} ");
            }


            collection1.Add(7);     //  Добавление элемента

            Console.WriteLine("\n\ncollection1:");
            foreach (int item in collection1)
            {
                Console.Write($"{item} ");
            }
            Console.WriteLine("\n\ncollection2:");
            foreach (int item in collection2)
            {
                Console.Write($"{item} ");
            }

            Console.WriteLine("\n\ncollection3:");
            foreach (int item in collection3)
            {
                Console.Write($"{item} ");
            }

            Console.WriteLine("\n\nДобавление элемента в collection1: ");
            foreach (int item in collection1)
            {
                Console.Write($"{item} ");
            }

            collection1 -= 7;       //  Удаление элемента

            Console.WriteLine("\n\nУдаление элемента из collection1: ");
            foreach (int item in collection1)
            {
                Console.Write($"{item} ");
            }

            var resCollection1 = collection1 * collection2;

            Console.WriteLine("\n\nПересечение множеств:");
            foreach (int item in collection1)
            {
                Console.Write($"{item} ");
            }

            Console.WriteLine($"\n\nПроверка на подмножество 3 и 1: {collection3 > collection1}");

            Console.WriteLine($"\n\nПроверка на равенство множеств 3 и 2: {collection3 < collection2}");

            Console.WriteLine("\n\ncollection2: ");
            foreach (int item in collection2)
            {
                Console.Write($"{item} ");
            }

            Console.ReadLine();
        }