805 / 532 / 158
Регистрация: 27.01.2015
Сообщений: 3,017
Записей в блоге: 1
1

Перегрузить операции уже написанных методов

29.03.2015, 09:35. Показов 486. Ответов 1
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Добрый день, не могли бы Вы перегрузить методы multimat (*), addmat(+) и transpon(%)?
На C++ я бы и сам все сделал, но вот С## не знаю вовсе)
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using System;
 
namespace Matrices
{
    public class Matrix
    {
        public double[,] array;
        static public int n;
        static public double GetDeterminant(double[,] matrix);
        static public double[,] GetMinorMatrix(double[,] matrix, int row, int col);
        public void addmat(Matrix B)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    array[i, j] = B.array[i, j] + array[i, j];
                }
            }
        }
        public void SetMatrix();
        public static void PrintMatrix(Matrix m);
        public void transpon()
        {
            double[,] temp;
            temp = new double[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    temp[j, i] = array[i, j];
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    array[i, j] = temp[i, j];
                }
            }
        }
        public void multimat(Matrix B)
        {
            double[,] temp1 = new double[n, n];
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    temp1[i, j] = 0;
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int l = 0; l < n; l++)
                        temp1[i, j] += array[i, l] * B.array[l, j];
                }
            }
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    array[i, j] = temp1[i, j];
                }
            }
        }
    }
    class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Введите размерность матриц:");
        Matrix.n = int.Parse(Console.ReadLine());
        Console.WriteLine("Введите матрицу А:\n");
        Matrix A = new Matrix(); A.SetMatrix();
        Console.WriteLine("\nВведите матрицу В:\n");
        Matrix B = new Matrix(); B.SetMatrix();
        Console.Clear();
        Console.WriteLine("Исходная матрица А:\n"); Matrix.PrintMatrix(A);
        Console.WriteLine("\nИсходная матрица В:\n"); Matrix.PrintMatrix(B);
        Console.WriteLine("\nОпределитель матрицы A равен:\n" + Matrix.GetDeterminant(A.array));
        Console.Read();
    }
}
}
Добавлено через 1 час 19 минут
Помогите, прошу =)
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
29.03.2015, 09:35
Ответы с готовыми решениями:

Перегрузить операции сравнения комплексных чисел и операции потокового вывода
Создать класс комплексное число. Перегрузить операции сравнения комплексных чисел! =, ==,&gt;, &lt;,&gt; =,...

Перегрузить операции +, +=, ==, [], ()
Для класса String перегрузить операции + + = == () таким образом, чтобы обеспечивалось выполнение...

Перегрузить операции
Здравствуйте! Есть уже готовая программа , но в ней нужно перегрузить операции + добавление...

Как перегрузить операции?
Я с горем пополам создал класс Bitstring для работы с 64-битовыми строками. Битовая строка...

1
Эксперт .NET
5531 / 4296 / 1216
Регистрация: 12.10.2013
Сообщений: 12,329
Записей в блоге: 2
29.03.2015, 10:11 2
Ferrari F1, что-то типа этого?
C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace ConsoleApplication2 {
    class Program {
        static void Main(string[] args) {
            Matrix _m1 = new Matrix(5, 5);
            _m1.FillMatrix();
            _m1.PrintMatrix();
            Console.WriteLine();
 
            Matrix _m2 = new Matrix(5, 5);
            _m2.FillMatrix();
            _m2.PrintMatrix();
            Console.WriteLine();
 
            Matrix _m3 = _m1 + _m2;
            _m3.PrintMatrix();
            Console.WriteLine();
 
            Matrix _m4 = _m1 * _m2;
            _m4.PrintMatrix();
 
            Console.ReadLine();
        }
    }
    class Matrix {
        private double[,] _matrix;
        private int width;
        private int height;
 
        public int Width {
            get { return width; }
        }
        public int Height {
            get { return height; }
        }
        public Matrix(int n, int m) {
            height = n;
            width = m;
            _matrix = new double[n, m];
        }
        public double this[int n, int m] {
            get {
                return _matrix[n, m];
            }
            set {
                _matrix[n, m] = value;
            }
        }
        public void Add(Matrix m) {
            if (m.Height != this.Height || m.Width != this.Width) {
                throw new ArgumentException("Wrong argument!");
            }
            for (int i = 0; i < height; i++) {
                for (int j = 0; j < width; j++) {
                    _matrix[i, j] = _matrix[i, j] + m[i, j];
                }
            }
        }
        public static Matrix operator + (Matrix m1, Matrix m2){
            if (m1.Height != m2.Height || m1.Width != m2.Width) {
                throw new ArgumentException("Wrong argument!");
            }
            Matrix temp=new Matrix(m1.Height, m1.Width);
            for(int i= 0; i < m1.Height; i++){
                for(int j = 0; j < m1.Width; j++){
                    temp[i,j]=m1[i,j]+m2[i,j];
                }  
            }
            return temp;
        }
        public static Matrix operator *(Matrix m1, Matrix m2) {
            if (m1.Height != m2.Height || m1.Width != m2.Width) {
                throw new ArgumentException("Wrong argument!");
            }
            Matrix temp = new Matrix(m1.Height, m1.Width);
            for (int i = 0; i < m1.Height; i++) {
                for (int j = 0; j < m1.Width; j++) {
                    temp[i, j] = m1[i, j] * m2[i, j];
                }
            }
            return temp;
        }
        public void FillMatrix() {
            Random r = new Random();
            for (int i = 0; i < this.Height; i++) {
                for (int j = 0; j < this.Width; j++) {
                    this[i, j] = r.Next(10);
                }
            }
        }
        public void PrintMatrix() {
            for (int i = 0; i < this.Height; i++) {
                for (int j = 0; j < this.Width; j++) {
                    Console.Write("{0}\t", this[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}
1
29.03.2015, 10:11
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
29.03.2015, 10:11
Помогаю со студенческими работами здесь

Перегрузить операции очереди
Очередь. Дополнительно перегрузить следующие операции: · + - добавить элемент; · извлечь...

Перегрузить операции в стеке и очереди
мне нужно перегрузить операции в стэке и очереде, это я знаю как, а вот как написать стэк и...

Перегрузить операторную функцию для операции !
Доброго времени суток форумчане! Задание звучит так:Дополнительно перегрузить операторную функцию...

Перегрузить операции добавления/извлечения из стека
Класс - стек stack. Дополнительно перегрузить следующие операции: + -Добавить элементы в стек -...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
2
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru