Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApplication4
  8. {
  9.     class myclass
  10.     {
  11.         float[,] m = new float[3, 3];
  12.         public myclass() {}
  13.         public myclass(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33)
  14.         {
  15.             m[0, 0] = m11;
  16.             m[0, 1] = m12;
  17.             m[0, 2] = m13;
  18.             m[1, 0] = m21;
  19.             m[1, 1] = m22;
  20.             m[1, 2] = m23;
  21.             m[2, 0] = m31;
  22.             m[2, 1] = m32;
  23.             m[2, 2] = m33;
  24.         }
  25.         public float this[int a, int b]
  26.         {
  27.             get
  28.             {
  29.                 return m[a, b];
  30.             }
  31.             set
  32.             {
  33.                 m[a, b] = value;
  34.             }
  35.         }
  36.         public static myclass operator *(myclass obj1, myclass obj2)
  37.         {
  38.             myclass res = new myclass();
  39.             for (int row = 0; row < 3; row++)
  40.             {  
  41.                 for (int col = 0; col < 3; col++)
  42.                 {  
  43.                     for (int inner = 0; inner < 3; inner++)
  44.                     {  
  45.                         res[row, col] += obj1[row, inner] * obj2[inner, col];  
  46.                     }
  47.                 }  
  48.             }
  49.             return res;
  50.         }
  51.         public override string ToString()
  52.         {
  53.             for (int i = 0; i < 3; i++)
  54.             {
  55.                 string str = "";
  56.                 for (int j = 0; j < 3; j++)
  57.                 {
  58.                     str = str + m[i, j].ToString() + "\t";
  59.                 }
  60.                 Console.WriteLine(str);
  61.             }
  62.             return "";
  63.         }
  64.  
  65.     }
  66.     class Program
  67.     {
  68.         static void Main(string[] args)
  69.         {
  70.             myclass obj1 = new myclass(1, 2, 3, 4, 5, 6, 7, 8, 9);
  71.             myclass obj2 = new myclass(1, 2, 3, 4, 5, 6, 7, 8, 9);
  72.             myclass mult = obj1 * obj2;
  73.             Console.WriteLine(mult);
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement