Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.97 KB | None | 0 0
  1. Program laba2_3;
  2. Uses
  3.   System.SysUtils;
  4. Type
  5.   TMatrixLine = array [1..40] of real;
  6.   Matr = array[1..40] of TMatrixLine;
  7.  
  8. Procedure ReadFile(Var InputFile : Text; Var Matrix: Matr; Var Size: Byte);
  9. Var
  10.   i, j: Byte;
  11.   NameOfFile: String ;
  12.   CorrectFile: Boolean;
  13. Begin
  14.   Repeat
  15.     Writeln('Введите имя файла, с которого хотите считать информацию: ');
  16.     Readln(NameOfFile);
  17.     NameOfFile := NameOfFile + '.txt';
  18.     CorrectFile := True;
  19.     Try
  20.     Assign(InputFile,NameOfFile);
  21.     Reset(InputFile);
  22.     except
  23.       CorrectFile := False;
  24.       Writeln('Не удалось найти файл ',NameOfFile);
  25.     End;
  26.   Until CorrectFile;
  27.   Read(InputFile,Size);
  28.   For i := 1 to Size do
  29.     For j := 1 to Size+1 do
  30.       Read(InputFile,Matrix[i,j]);
  31.   Writeln('Исходная матрица коэффициентов и свободных членов уравнения: ');
  32.   For i := 1 to Size do
  33.     Begin
  34.       For j := 1 to Size+1 do
  35.         Write(Matrix[i,j]:7:2);
  36.         Writeln;
  37.     End;
  38.   Writeln;
  39.   Close(InputFile);
  40. End;
  41.  
  42.  
  43. Procedure Sort(Matrix: Matr; Size: integer);
  44. Var
  45.   i,j: Byte;
  46.   BufferLine : TMatrixLine;
  47. Begin
  48.   while (i <= Size + 1) do
  49.   Begin
  50.     If((Matrix[i][1]) > (Matrix[i-1][1])) then
  51.     Begin
  52.       BufferLine := Matrix[i-1];
  53.       Matrix[i-1] := Matrix[i];
  54.       Matrix[i] := BufferLine;
  55.       i := 1;
  56.     End;
  57.       i := i + 1;
  58.   End;
  59.  
  60.   Writeln('Полученная треугольная матрица: ');
  61.   For i := 1 to Size do
  62.   Begin
  63.     for j := 1 to Size + 1 do
  64.       Write(Matrix[i,j]:7:2);
  65.       Writeln;
  66.   End;
  67. End;
  68.  
  69.  //For k:=1 to Size do
  70.   //   Begin
  71.     //   For j:=k+1 to Size+1 do
  72.       //    Begin
  73.         //    Temp:=Matrix[j,k]/Matrix[k,k];
  74.           //  writeln(temp);
  75.             //For i:=k to Size do
  76.               // Begin
  77.                 // Matrix[j,i]:=Matrix[j,i]-Temp*Matrix[k,i];
  78.                //End;
  79.          // End;
  80.      //End;
  81.  
  82.  
  83.  
  84. Procedure OutputInFile(Var OutputFile: Text;Var Matrix: Matr;Size:Byte);
  85. Var
  86.   i,j: Byte;
  87.   NameOfFile: String;
  88. Begin
  89.   Writeln('Введите имя файла для записи: ');
  90.   Readln(NameOfFile);
  91.   NameOfFile := NameOfFile + '.txt';
  92.   Assign(OutputFile,NameOfFile);
  93.   Rewrite(OutputFile);
  94. Writeln(OutputFile,'Полученная треугольная матрица: ');
  95. for i := 1 to Size do
  96.   Begin
  97.     for j := 1 to Size+1 do
  98.       Write(OutputFile,Matrix[i,j]:6:2);
  99.       Writeln(OutputFile);
  100.   End;
  101. Close(OutputFile);
  102. End;
  103. Var
  104.   Matrix: Matr;
  105.   Size,i,j: Byte;
  106.   InputFile, OutputFile: Text;
  107. Begin
  108.   Writeln('Данная программа выполняет "прямой ход" в решении',
  109.               'системы линейных алгебраических  уравнений методом Гаусса');
  110.   Writeln;
  111.   ReadFile(InputFile,Matrix,Size);
  112.   Sort(Matrix,Size);
  113.   OutputInFile(OutputFile,Matrix,Size);
  114.   Readln;
  115. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement