- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ClassLibrary8
- {
- public class DoubleArrayService
- {
- public static void ResetArray(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי שיש בו ערכים
- //טענת יציאה: הפעולה מאפסת את המערך
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- Matrix[shura, amuda] = 0;
- }
- public static void InsertArray(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי שאין בו ערכים
- //טענת יציאה: הפעולה מכניסה ערכים למשתי המערך
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- {
- Console.WriteLine("Insert number: ");
- Matrix[shura, amuda] = int.Parse(Console.ReadLine());
- }
- }
- public static void PrintArray(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי מלא בערכים
- //טענת יציאה: הפעולה מדפיסה את משתני המערך לפי סדר קליטתם
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- {
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- Console.WriteLine(Matrix[shura, amuda] + " ");
- Console.WriteLine();
- }
- }
- public static int SumOfMatrix(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי שיש בו ערכים
- //טענת יציאה: הפעולה מחזירה את סכום איברי המערך
- int sum = 0;
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- sum += Matrix[shura, amuda];
- return sum;
- }
- public static void RandomNumbersToArray(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי שאין בו ערכים
- //טענת יציאה: הפעולה מכניסה ערכים רנדומליים בין 1 ל-9 למערך
- Random rnd = new Random();
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- Matrix[shura, amuda] = rnd.Next(11, 100);
- }
- public static void PrintNumbersOfAlahson(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מדפיסה את איברי האלכסון הראשי
- for (int i = 0; i < Matrix.GetLength(0); i++)
- Console.WriteLine(Matrix[i, i] + " ");
- }
- public static int SumOfShura(int[,] Matrix, int shura)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי ומספר שורה
- //טענת יציאה: הפעולה מחשבת את סכום השורה שנשלחה
- //לבדוק את הפעולה הזאת ואת הבאה
- int sum = 0;
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- {
- sum += Matrix[shura, amuda];
- }
- return sum;
- }
- public static int SumOfAmuda(int[,] Matrix, int Amuda)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי ומספר שורה
- //טענת יציאה: הפעולה מחשבת את סכום השורה שנשלחה
- int sum = 0;
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- {
- sum += Matrix[shura, Amuda];
- }
- return sum;
- }
- public static int SumOfFrame(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי עם ערכים
- //טענת יציאה: הפעולה מחזירה את סכום האיברים במסגרת
- int sum = 0;
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- if (amuda == 0 || shura == 0 || shura == Matrix.GetLength(0) - 1 || amuda == Matrix.GetLength(1) - 1)
- sum += Matrix[shura, amuda];
- return sum;
- }
- public static void PrintNumbersOfAlahsonmishni(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי עם ערכים
- //טענת יציאה: הפעולה מדפיסה את האיברים באלכסון המשני
- for (int i = Matrix.GetLength(0) - 1; i >= 0; i--)
- Console.WriteLine("{0} ", Matrix[i, Matrix.GetLength(0) - 1 - i]);
- }
- public static int[] SumOfShurotInNewArray(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מחזירה מערך חד ממדי שבו סכומי השורות
- //לבדוק
- int[] SumArray = new int[Matrix.GetLength(0)];
- for (int shura = 0; shura < Matrix.GetLength(0); shura++)
- {
- SumArray[shura] = SumOfShurotInNewArray(Matrix, shura);
- }
- return SumArray;
- }
- public static int[] SumOfAmudotInNewArray(int[] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מחזירה מערך חד ממדי שבו סכומי העמודות
- int[] SumArray = new int[Matrix.GetLength(1)];
- for (int amuda = 0; amuda < Matrix.GetLength(1); amuda++)
- {
- SumArray[amuda] = SumOfAmuda(Matrix, amuda);
- }
- return SumArray;
- }
- public static void PrintTriangleAboveAlahson(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מדפיסה את המשולש מתחת לאלכסון הראשי
- for (int shura = 0; shura < Matrix.GetLength(0) - 1; shura++)
- {
- for (int t = 0; t < shura; t++)
- {
- Console.WriteLine(" ");
- }
- for (int amuda = shura + 1; amuda < Matrix.GetLength(1); amuda++)
- {
- Console.WriteLine(Matrix[shura, amuda] + " ");
- }
- Console.WriteLine();
- }
- }
- public static void PrintTriangleUnderAlahson(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מדפיסה את המשולש מתחת לאלכסון הראשי
- for (int shura = 1; shura < Matrix.GetLength(0); shura++)
- {
- for (int amuda = 0; amuda < shura; amuda++)
- Console.WriteLine(Matrix[shura, amuda] + " ");
- Console.WriteLine();
- }
- }
- public static void PrintTriangleAboveAlahsonMishni(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מדפיסה את המשולש מעל לאלכסון המשני
- for (int i = 0; i < Matrix.GetLength(0) - 1; i++)
- {
- for (int j = 0; j < Matrix.GetLength(1) - 1 - i; j++)
- Console.WriteLine(Matrix[i, j] + " ");
- Console.WriteLine();
- }
- }
- public static void PrintTriangleUnderAlahsonMishni(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מדפיסה את המשולש מתחת לאלכסון המשני
- for (int i = 1; i < Matrix.GetLength(0); i++)
- {
- for (int t = 0; t < Matrix.GetLength(0) - i; t++)
- Console.WriteLine(" ");
- for (int j = Matrix.GetLength(1) - i; j < Matrix.GetLength(1); j++)
- Console.WriteLine(Matrix[i, j] + " ");
- Console.WriteLine();
- }
- }
- public static int Max(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מחזירה את המספר המקסימלי מאיברי המערך
- int max = 0;
- for (int i = 0; i < Matrix.GetLength(0); i++)
- for (int j = 0; j < Matrix.GetLength(1); j++)
- if (Matrix[i, j] > max)
- max = Matrix[i, j];
- return max;
- }
- public static int Min(int[,] Matrix)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי
- //טענת יציאה: הפעולה מחזירה את המספר המינימלי מאיברי המערך
- int min = Matrix[0, 0];
- for (int i = 0; i < Matrix.GetLength(0); i++)
- for (int j = 0; j < Matrix.GetLength(1); j++)
- if (Matrix[i, j] < min)
- min = Matrix[i, j];
- return min;
- }
- public static void MatrixShow(int[,] Matrix)
- {
- //פעולה המציגה את איברי המטריצה
- int n = Matrix.GetLength(0); //מספר השורות במטריצה
- int m = Matrix.GetLength(1); //מספר העמודות במטריצה
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; i < m; j++)
- Console.WriteLine(Matrix[i, j] + "\t");
- Console.WriteLine();
- }
- }
- public static void MatrixFill(int[,] Matrix)
- {
- //הפעולה ממלאת את המטריצה במספרים רנדומליים 0 ו-1
- int n = Matrix.GetLength(0); //מספר השורות במטריצה
- int m = Matrix.GetLength(1); //מספר העמודות במטריצה
- Random rnd = new Random();
- for (int i = 0; i < n; i++)
- for (int j = 0; j < m; j++)
- Matrix[i, j] = rnd.Next(2);
- }
- public static bool ArrayBoundaries(int[,] Matrix, int Col, int Row)
- {
- //טענת כניסה: הפעולה מקבלת מערך דו ממדי שורה ועמודה
- //טענת יציאה: הפעולה מחזירה אמת אם השורה והעמודה לא חרגו מגבולות המערך אחרת הפעולה מחזירה שקר
- if (Col >= 0 && Row >= 0 && Col < Matrix.GetLength(0) && Row < Matrix.GetLength(1))
- return true;
- return false;
- }
- }
- }