Программирование векторных и матричных операций, страница 3

             Sub_Matrix(Matrix_A,Matrix_B, MatrixRes_1, Matrix_Size);

             File_Output := 'SubMatrix.txt';

             Print_Matrix_To_File(MatrixRes_1, File_Output, Matrix_Size);

             Print_Matrix_ON_Screen(MatrixRes_1, Matrix_Size);

             ReadLn;

           end;

      '8': begin

             ClrScr;

             Mul_Matrix(Matrix_A,Matrix_B, MatrixRes_1, Matrix_Size);

             File_Output := 'MulMatrix.txt';

             Print_Matrix_To_File(MatrixRes_1, File_Output, Matrix_Size);

             Print_Matrix_ON_Screen(MatrixRes_1, Matrix_Size);

             ReadLn;

           end;

      '9': Ch:='9';

      '*': begin

             ClrScr;

             {A - B = r1}

             Sub_Matrix(Matrix_A,Matrix_B,MatrixRes_1,Matrix_Size);

             {A + B = r2}

             Add_Matrix(Matrix_A,Matrix_B,MatrixRes_2,Matrix_Size);

             {r1 * r2 = r1}

             Mul_Matrix(MatrixRes_1,MatrixRes_2,MatrixRes_1,Matrix_Size);

             {A * B = r2}

             Mul_Matrix(Matrix_A,Matrix_B,MatrixRes_2,Matrix_Size);

             {Coef * R2 = r2}

             Mul_Matrix_On_Coef(MatrixRes_2,2,MatrixRes_2,Matrix_Size);

             {R1 - R2 = R1}

             Sub_Matrix(MatrixRes_1,MatrixRes_2,MatrixRes_1,Matrix_Size);

             File_Output := 'FUNCTION.txt';

             Print_Matrix_To_File(MatrixRes_1, File_Output, Matrix_Size);

             Print_Matrix_ON_Screen(MatrixRes_1, Matrix_Size);

             ReadLn;

           end;

    end;

  Until(CH='9');

END.

Текстмодуля (U_Matrix):

UNIT U_Matrix;

{****--------*****--------****}

           INTERFACE {Объявление раздела модуля: INTERFACE - ИНТЕРФЕЙС}

{****--------*****--------****}

{Объявление записи числа}

uses crt, U_Vector;

const

  Matrix_Size=3;

type

  Size_Type_Matrix = 1..Matrix_Size;

  MatrixArray = array[Size_Type_Matrix,Size_Type_Matrix] of integer;

procedure Take_Matrix_From_File(var Matrix:MatrixArray; File_Name:string; Size:integer);

procedure Take_Matrix_From_Keyboard(var Matrix:MatrixArray; Size:integer);

procedure Mul_Matrix(First_Matrix,Second_Matrix:MatrixArray;

                     var Matrix_Of_Resalt:MatrixArray; Size:integer);

procedure Add_Matrix(First_Matrix,Second_Matrix:MatrixArray;

                     var Matrix_Of_Resalt:MatrixArray; Size:integer);

procedure Sub_Matrix(First_Matrix,Second_Matrix:MatrixArray;

                     var Matrix_Of_Resalt:MatrixArray; Size:integer);

procedure Mul_Matrix_On_Coef(Matrix:MatrixArray; Coefficient:integer;

                             var Matrix_Of_Resalt:MatrixArray; Size:integer);

procedure Mul_Matrix_On_Vector(Matrix:MatrixArray; Vector: VectorArray;

                               var Matrix_Of_Resalt:MatrixArray; Size:integer);

procedure Print_Matrix_To_File(Matrix:MatrixArray; File_Name:string;Size:integer);

procedure Print_Matrix_ON_Screen(Matrix:MatrixArray; Size:integer);

{****------****------****}

      IMPLEMENTATION {Объявление раздела модуля: IMPLEMENTATION - РЕАЛИЗАЦИЯ}

{****------****------****}

{===============================================================}

{Считывает формирует из файла}

procedure Take_Matrix_From_File;

var

  File_On_Disk:text;

  i,j:integer;

begin

  assign(File_On_Disk,File_Name);

  reset(File_On_Disk);

  for i:=1 to Size do

    begin

      for j:=1 to Size do

        read(File_On_Disk,Matrix[i,j]);

      readln(File_On_Disk);

    end;

  close(File_On_Disk);

end;

{===============================================================}

{Считывает матрицу с клавиатуры}

procedure Take_Matrix_From_Keyboard;

var i,j:integer;

begin

  ClrScr;

  for i:=1 to Size do

    for j:=1 to Size do

      Begin

        GoToXY(j*20-16,i*3);

        Write('Matrix[',i,',',j,']=');  readLn(Matrix[i,j]);