Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 11.56 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace ClassLibrary8
  7. {
  8.     public class DoubleArrayService
  9.     {
  10.         public static void ResetArray(int[,] Matrix)
  11.         {
  12.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי שיש בו ערכים
  13.             //טענת יציאה: הפעולה מאפסת את המערך
  14.  
  15.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  16.                 for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  17.                     Matrix[shura, amuda] = 0;
  18.         }
  19.  
  20.         public static void InsertArray(int[,] Matrix)
  21.         {
  22.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי שאין בו ערכים
  23.             //טענת יציאה: הפעולה מכניסה ערכים למשתי המערך
  24.  
  25.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  26.                 for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  27.                 {
  28.                     Console.WriteLine("Insert number: ");
  29.                     Matrix[shura, amuda] = int.Parse(Console.ReadLine());
  30.                 }
  31.         }
  32.  
  33.         public static void PrintArray(int[,] Matrix)
  34.         {
  35.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי מלא בערכים
  36.             //טענת יציאה: הפעולה מדפיסה את משתני המערך לפי סדר קליטתם
  37.  
  38.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  39.             {
  40.                 for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  41.                     Console.WriteLine(Matrix[shura, amuda] + " ");
  42.                 Console.WriteLine();
  43.             }
  44.         }
  45.  
  46.         public static int SumOfMatrix(int[,] Matrix)
  47.         {
  48.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי שיש בו ערכים
  49.             //טענת יציאה: הפעולה מחזירה את סכום איברי המערך
  50.  
  51.             int sum = 0;
  52.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  53.                 for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  54.                     sum += Matrix[shura, amuda];
  55.             return sum;
  56.         }
  57.  
  58.         public static void RandomNumbersToArray(int[,] Matrix)
  59.         {
  60.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי שאין בו ערכים
  61.             //טענת יציאה: הפעולה מכניסה ערכים רנדומליים בין 1 ל-9 למערך
  62.  
  63.             Random rnd = new Random();
  64.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  65.                 for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  66.                     Matrix[shura, amuda] = rnd.Next(11, 100);
  67.         }
  68.  
  69.         public static void PrintNumbersOfAlahson(int[,] Matrix)
  70.         {
  71.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  72.             //טענת יציאה: הפעולה מדפיסה את איברי האלכסון הראשי
  73.  
  74.             for (int i = 0; i < Matrix.GetLength(0); i++)
  75.                 Console.WriteLine(Matrix[i, i] + " ");
  76.         }
  77.  
  78.         public static int SumOfShura(int[,] Matrix, int shura)
  79.         {
  80.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי ומספר שורה
  81.             //טענת יציאה: הפעולה מחשבת את סכום השורה שנשלחה
  82.             //לבדוק את הפעולה הזאת ואת הבאה
  83.             int sum = 0;
  84.             for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  85.             {
  86.                 sum += Matrix[shura, amuda];
  87.             }
  88.             return sum;
  89.         }
  90.  
  91.         public static int SumOfAmuda(int[,] Matrix, int Amuda)
  92.         {
  93.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי ומספר שורה
  94.             //טענת יציאה: הפעולה מחשבת את סכום השורה שנשלחה
  95.  
  96.             int sum = 0;
  97.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  98.             {
  99.                 sum += Matrix[shura, Amuda];
  100.             }
  101.             return sum;
  102.         }
  103.  
  104.         public static int SumOfFrame(int[,] Matrix)
  105.         {
  106.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי עם ערכים
  107.             //טענת יציאה: הפעולה מחזירה את סכום האיברים במסגרת
  108.  
  109.             int sum = 0;
  110.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  111.                 for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  112.                     if (amuda == 0 || shura == 0 || shura == Matrix.GetLength(0) - 1 || amuda == Matrix.GetLength(1) - 1)
  113.                         sum += Matrix[shura, amuda];
  114.             return sum;
  115.         }
  116.  
  117.         public static void PrintNumbersOfAlahsonmishni(int[,] Matrix)
  118.         {
  119.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי עם ערכים
  120.             //טענת יציאה: הפעולה מדפיסה את האיברים באלכסון המשני
  121.  
  122.             for (int i = Matrix.GetLength(0) - 1; i >= 0; i--)
  123.                 Console.WriteLine("{0} ", Matrix[i, Matrix.GetLength(0) - 1 - i]);
  124.         }
  125.  
  126.         public static int[] SumOfShurotInNewArray(int[,] Matrix)
  127.         {
  128.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  129.             //טענת יציאה: הפעולה מחזירה מערך חד ממדי שבו סכומי השורות
  130.             //לבדוק
  131.  
  132.             int[] SumArray = new int[Matrix.GetLength(0)];
  133.             for (int shura = 0; shura < Matrix.GetLength(0); shura++)
  134.             {
  135.                 SumArray[shura] = SumOfShurotInNewArray(Matrix, shura);
  136.             }
  137.             return SumArray;
  138.         }
  139.  
  140.         public static int[] SumOfAmudotInNewArray(int[] Matrix)
  141.         {
  142.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  143.             //טענת יציאה: הפעולה מחזירה מערך חד ממדי שבו סכומי העמודות
  144.  
  145.             int[] SumArray = new int[Matrix.GetLength(1)];
  146.             for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
  147.             {
  148.                 SumArray[amuda] = SumOfAmuda(Matrix, amuda);
  149.             }
  150.             return SumArray;
  151.         }
  152.  
  153.         public static void PrintTriangleAboveAlahson(int[,] Matrix)
  154.         {
  155.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  156.             //טענת יציאה: הפעולה מדפיסה את המשולש מתחת לאלכסון הראשי
  157.  
  158.             for (int shura = 0; shura < Matrix.GetLength(0) - 1; shura++)
  159.             {
  160.                 for (int t = 0; t < shura; t++)
  161.                 {
  162.                     Console.WriteLine(" ");
  163.                 }
  164.                 for (int amuda = shura + 1; amuda < Matrix.GetLength(1); amuda++)
  165.                 {
  166.                     Console.WriteLine(Matrix[shura, amuda] + " ");
  167.                 }
  168.                 Console.WriteLine();
  169.             }
  170.         }
  171.  
  172.         public static void PrintTriangleUnderAlahson(int[,] Matrix)
  173.         {
  174.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  175.             //טענת יציאה: הפעולה מדפיסה את המשולש מתחת לאלכסון הראשי
  176.  
  177.             for (int shura = 1; shura < Matrix.GetLength(0); shura++)
  178.             {
  179.                 for (int amuda = 0; amuda < shura; amuda++)
  180.                     Console.WriteLine(Matrix[shura, amuda] + " ");
  181.                 Console.WriteLine();
  182.             }
  183.         }
  184.  
  185.         public static void PrintTriangleAboveAlahsonMishni(int[,] Matrix)
  186.         {
  187.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  188.             //טענת יציאה: הפעולה מדפיסה את המשולש מעל לאלכסון המשני
  189.  
  190.             for (int i = 0; i < Matrix.GetLength(0) - 1; i++)
  191.             {
  192.                 for (int j = 0; j < Matrix.GetLength(1) - 1 - i; j++)
  193.                     Console.WriteLine(Matrix[i, j] + " ");
  194.                 Console.WriteLine();
  195.             }
  196.         }
  197.  
  198.         public static void PrintTriangleUnderAlahsonMishni(int[,] Matrix)
  199.         {
  200.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  201.             //טענת יציאה: הפעולה מדפיסה את המשולש מתחת לאלכסון המשני
  202.  
  203.             for (int i = 1; i < Matrix.GetLength(0); i++)
  204.             {
  205.                 for (int t = 0; t < Matrix.GetLength(0) - i; t++)
  206.                     Console.WriteLine(" ");
  207.                 for (int j = Matrix.GetLength(1) - i; j < Matrix.GetLength(1); j++)
  208.                     Console.WriteLine(Matrix[i, j] + " ");
  209.                 Console.WriteLine();
  210.             }
  211.         }
  212.  
  213.         public static int Max(int[,] Matrix)
  214.         {
  215.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  216.             //טענת יציאה: הפעולה מחזירה את המספר המקסימלי מאיברי המערך
  217.  
  218.             int max = 0;
  219.             for (int i = 0; i < Matrix.GetLength(0); i++)
  220.                 for (int j = 0; j < Matrix.GetLength(1); j++)
  221.                     if (Matrix[i, j] > max)
  222.                         max = Matrix[i, j];
  223.             return max;
  224.         }
  225.  
  226.         public static int Min(int[,] Matrix)
  227.         {
  228.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי
  229.             //טענת יציאה: הפעולה מחזירה את המספר המינימלי מאיברי המערך
  230.  
  231.             int min = Matrix[0, 0];
  232.             for (int i = 0; i < Matrix.GetLength(0); i++)
  233.                 for (int j = 0; j < Matrix.GetLength(1); j++)
  234.                     if (Matrix[i, j] < min)
  235.                         min = Matrix[i, j];
  236.             return min;
  237.         }
  238.  
  239.         public static void MatrixShow(int[,] Matrix)
  240.         {
  241.             //פעולה המציגה את איברי המטריצה
  242.  
  243.             int n = Matrix.GetLength(0); //מספר השורות במטריצה      
  244.             int m = Matrix.GetLength(1); //מספר העמודות במטריצה
  245.  
  246.             for (int i = 0; i < n; i++)
  247.             {
  248.                 for (int j = 0; i < m; j++)
  249.                     Console.WriteLine(Matrix[i, j] + "\t");
  250.                 Console.WriteLine();
  251.             }
  252.         }
  253.  
  254.         public static void MatrixFill(int[,] Matrix)
  255.         {
  256.             //הפעולה ממלאת את המטריצה במספרים רנדומליים 0 ו-1
  257.  
  258.             int n = Matrix.GetLength(0); //מספר השורות במטריצה
  259.             int m = Matrix.GetLength(1); //מספר העמודות במטריצה
  260.  
  261.             Random rnd = new Random();
  262.             for (int i = 0; i < n; i++)
  263.                 for (int j = 0; j < m; j++)
  264.                     Matrix[i, j] = rnd.Next(2);
  265.         }
  266.  
  267.         public static bool ArrayBoundaries(int[,] Matrix, int Col, int Row)
  268.         {
  269.             //טענת כניסה: הפעולה מקבלת מערך דו ממדי שורה ועמודה
  270.             //טענת יציאה: הפעולה מחזירה אמת אם השורה והעמודה לא חרגו מגבולות המערך אחרת הפעולה מחזירה שקר
  271.  
  272.             if (Col >= 0 && Row >= 0 && Col < Matrix.GetLength(0) && Row < Matrix.GetLength(1))
  273.                 return true;
  274.             return false;
  275.         }
  276.  
  277.        
  278.     }
  279. }