Перегрузка оператора умножения для матрицы - C#

Узнай цену своей работы

Формулировка задачи:

Помогите пожалуйста! Нужно на этой неделе сдать работу, никак не могу разобраться. Вот имею даный код, но он чего-то не работает, посмотрите пожалуста!
Листинг программы
  1. using System;
  2. namespace Lab8
  3. {
  4. class Matrix
  5. {
  6. public int lines;
  7. public int columns;
  8. public int[,] matrix;
  9. public int this[int i]
  10. {
  11. get
  12. {
  13. if (i == 1) return lines;
  14. else if (i == 2) return columns;
  15. else return 0;
  16. }
  17. set
  18. {
  19. if (i == 1) lines = value;
  20. else if (i == 2) columns = value;
  21. }
  22. }
  23. public Matrix(int lines, int columns)
  24. {
  25. Random R = new Random();
  26. matrix = new int[lines, columns];
  27. for (int i = 0; i < lines; i++)
  28. {
  29. for (int j = 0; j < columns; j++)
  30. {
  31. matrix[i, j] = R.Next(9);
  32. }
  33. }
  34. }
  35. public static Matrix operator *(Matrix Matrix1, Matrix Matrix2)
  36. {
  37. Matrix Matrix3 = new Matrix(Matrix1.lines, Matrix1.columns);
  38. Matrix3.lines = Matrix1.lines;
  39. Matrix3.columns = Matrix1.columns;
  40. for (int i = 0; i < Matrix3.lines; i++)
  41. {
  42. for (int j = 0; j < Matrix3.columns; j++)
  43. {
  44. Matrix3.matrix[i, j] = 0;
  45. }
  46. }
  47. for (int i = 0; i < Matrix1.lines; i++)
  48. {
  49. for (int j = 0; j < Matrix2.columns; j++)
  50. {
  51. for (int k = 0; k < Matrix2.lines; k++)
  52. {
  53. Matrix3.matrix[i, j] += Matrix1.matrix[i, k] * Matrix2.matrix[k, j];
  54. }
  55. }
  56. }
  57. return Matrix3;
  58. }
  59. public override string ToString()
  60. {
  61. string st ="";
  62. for (int i = 0; i < lines; i++)
  63. {
  64. for (int j = 0; j < columns; j++)
  65. {
  66. st+=(this.matrix[i, j])+" ";
  67. }
  68. Console.WriteLine(" ");
  69. }
  70. return st;
  71. }
  72. }
  73. class Program
  74. {
  75. static void Main(string[] args)
  76. {
  77. Console.WriteLine("Enter the number of lines in matrix: ");
  78. int lines = Convert.ToInt16(Console.ReadLine());
  79. Console.WriteLine("Enter the number of columns in matrix: ");
  80. int columns = Convert.ToInt16(Console.ReadLine());
  81. Matrix NewMatrix1 = new Matrix(lines, columns);
  82. Matrix NewMatrix2 = new Matrix(lines, columns);
  83. Console.WriteLine(NewMatrix1);
  84. Console.WriteLine(NewMatrix2);
  85. Console.WriteLine(NewMatrix1 * NewMatrix2);
  86. Console.ReadKey();
  87. }
  88. }
  89. }

Решение задачи: «Перегрузка оператора умножения для матрицы»

textual
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6.  
  7. namespace ConsoleApplication1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = @"qwajkctyfgqazkc";
  14.             string pattern = @"a\Skc";//
  15.  
  16.             Console.WriteLine("Совпадений: " + Regex.Matches(input,pattern,RegexOptions.IgnoreCase).Count);
  17.  
  18.             Console.ReadKey();
  19.  
  20.         }
  21.     }
  22. }

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 4.286 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы