Ejemplo n.º 1
0
    public object Clone()
    {
        DeepCloneClass result = new DeepCloneClass();

        for (int i = 0; i < 5; ++i)
        {
            for (int j = 0; j < 5; ++j)
            {
                result.mat[i, j] = this.mat[i, j];
            }
        }
        return(result);;
    }
Ejemplo n.º 2
0
    static void Main()
    {
        Matrix one = new Matrix();

        one.Output();
        Matrix two = new Matrix();

        Console.WriteLine(two.ToString());
        _ = new Matrix();
        Matrix three = one + two;

        Console.WriteLine(three.ToString());
        if (one != two)
        {
            Console.WriteLine("Neravni");
        }

        //пример работы реализации Прототипа
        DeepCloneClass dc1 = new DeepCloneClass();
        DeepCloneClass dc2 = (DeepCloneClass)dc1.Clone();

        Console.WriteLine(dc1.ToString());
        Console.WriteLine(dc2.ToString());

        try
        {
            Console.WriteLine("Вводите значения 1 матрицы больше 0");
            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 5; ++j)
                {
                    one.mat[i, j] = Convert.ToInt32(Console.ReadLine());
                    if (one.mat[i, j] <= 0)
                    {
                        throw new InputException("Неправильный ввод");
                    }
                }
            }
        }
        catch (InputException ex)
        {
            Console.WriteLine("Ошибка: " + ex.Message);
        }

        try
        {
            Console.WriteLine("Значение 2 матрицы меньше 0");
            for (int i = 0; i < 5; ++i)
            {
                for (int j = 0; j < 5; ++j)
                {
                    two.mat[i, j] = Convert.ToInt32(Console.ReadLine());
                    if (two.mat[i, j] >= 0)
                    {
                        throw new InputException("Неправильный ввод");
                    }
                }
            }
        }
        catch (InputException ex)
        {
            Console.WriteLine("Ошибка: " + ex.Message);
        }

        try
        {
            Console.WriteLine("Действие");
            string act = Console.ReadLine();
            if (act != "+" || act != "-" || act != "*")
            {
                throw new InputException("Неправильный ввод");
            }
            else
            {
                if (act == "+")
                {
                    three = one + two;
                }
                if (act == "-")
                {
                    three = one - two;
                }
                if (act == "*")
                {
                    three = one * two;
                }
            }
        }
        catch (InputException ex)
        {
            Console.WriteLine("Ошибка: " + ex.Message);
        }
        Console.WriteLine(three.ToString());
    }