示例#1
0
        static void Main(string[] args)
        {
            char start = 'к', finish = 'ю';

            do
            {
                MyStrings testString  = new RusString(start, finish, 10);
                MyStrings testString1 = new LatString('a', 'q', 7);
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString1);
                Console.WriteLine(testString1.CountLetter('b'));
                // тестируем неверные входные данные
                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                }
                try
                {
                    testString1 = new LatString('6', 'x', 6);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                }
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString1);
                Console.WriteLine(testString1.CountLetter('j'));
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
        static void Main(string[] args)
        {
            char start  = 'к',
                 finish = 'ю';

            do
            {
                MyStrings testString = new RusString(start, finish, 10);
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('o'));

                // Тестируем.
                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Ошибка:" + ex.Message);
                    Console.WriteLine("Состояние объекта не изменено");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('o'));
            }while (Console.ReadKey().Key != ConsoleKey.Escape);

            // Теперь тестируем класс для латинских строк.
            start  = 'f';
            finish = 'l';
            Console.WriteLine("\n");
            do
            {
                MyStrings testString = new LatString(start, finish, 10);
                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('h'));

                // Тестируем.
                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Ошибка:" + ex.Message);
                    Console.WriteLine("Состояние объекта не изменено");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('h'));
            }while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
示例#3
0
        static void Main(string[] args)
        {
            char start = 'к', finish = 'ю';

            do
            {
                MyStrings testString = new RusString(start, finish, 10);

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());

                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Nothing was changed.");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());

                testString = new LatString(start, finish, 10);

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());

                try
                {
                    testString = new RusString(start, finish, -11);
                }
                catch (ArgumentOutOfRangeException)
                {
                    Console.WriteLine("Nothing was changed.");
                }

                Console.WriteLine(testString);
                Console.WriteLine(testString.CountLetter('о'));
                Console.WriteLine(testString.IsPalidrome());
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }
示例#4
0
        static void Main()
        {
            do
            {
                Console.Clear();

                RusString str;
                try
                {
                    Console.WriteLine("Enter start letter:");
                    char start = char.Parse(Console.ReadLine());
                    Console.WriteLine("Enter finish letter:");
                    char finish = char.Parse(Console.ReadLine());
                    Console.WriteLine("Enter length of string:");
                    int n = int.Parse(Console.ReadLine());
                    str = new RusString(start, finish, n);
                    Console.WriteLine($"String: {str}");
                    Console.WriteLine(str.IsPalindrom ? "Palindrom" : "Not a palindrom");
                    Console.WriteLine("Enter letter to find:");
                    char ch = char.Parse(Console.ReadLine());
                    Console.WriteLine($"Number of letter \'{ch}\' in string: {str.CountLetter(ch)}");
                }
                catch (ArgumentNullException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (FormatException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (OverflowException ex)
                {
                    Console.WriteLine(ex.Message);
                }
                catch (ArgumentException ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Console.WriteLine("Press Esc to exit. Press any other key to continue.");
            } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
        }
        static void Main(string[] args)
        {
            do
            {
                char start1, finish1, start2, finish2;
                do
                {
                    Console.Clear();
                    try
                    {
                        Console.WriteLine("Введите русские символы(начало и конец)");
                        start1  = Console.ReadKey().KeyChar;
                        finish1 = Console.ReadKey().KeyChar;
                        Console.WriteLine();
                        Console.WriteLine("Введите латинские символы(начало и конец)");
                        start2  = Console.ReadKey().KeyChar;
                        finish2 = Console.ReadKey().KeyChar;
                        break;
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Console.WriteLine("Введены неверные значения");
                    }
                } while (true);
                try
                {
                    MyStrings testString1 = new RusString(start1, finish1, 10);
                    MyStrings testString2 = new LatString(start2, finish2, 23);

                    Console.WriteLine("Для ру слов");

                    // тестируем неверные входные данные
                    try
                    {
                        Console.WriteLine(testString1);
                        Console.WriteLine(testString1.CountLetter('о'));
                        testString1 = new RusString(start1, start1, -11);
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                    }
                    catch (OverflowException ex)
                    {
                        Console.WriteLine("За массив выходим :(");
                    }

                    Console.WriteLine("Для лат слов");
                    // тестируем неверные входные данные
                    try
                    {
                        Console.WriteLine(testString2);
                        Console.WriteLine(testString2.CountLetter('о'));
                        testString2 = new RusString(start2, start2, -11);
                    }
                    catch (ArgumentOutOfRangeException ex)
                    {
                        Console.WriteLine("Состояние объекта не изменено");// если объект не сформирован
                    }
                    catch (OverflowException ex)
                    {
                        Console.WriteLine("За массив выходим :(");
                    }
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine("Введеные неверные значения");
                }
            } while (Console.ReadKey().Key != ConsoleKey.Escape);
        }