Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project7;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- type
- matrixInteger = Array of array of integer;
- const
- SenseMessage = 'Данная программа находит сумму элементов, расположенных в заштрихованной части матрицы';
- InputMessage = 'Пожалуйста, введите имя файла, из которого будут считываться данные';
- OutputMessage = 'Сумма элементов, расположенных в заштрихованной части матрицы';
- MistakeFoundMessage = 'Ошибка! Файл с таким именем не найден. Повторите опытку.';
- MistakeOpenMessage = 'Ошибка! Невозможно открыть данный файл. Пожалуйста, повторите попытку';
- InputExample = 'Например, "C:\Users\Ольга\Desktop\LabWork\Unit2\Lab 4\input.txt"';
- OutputExample = 'Например, "C:\Users\Ольга\Desktop\LabWork\Unit2\Lab 4\output.txt"';
- function LoadMatrixFromFile(var InF: TextFile) : matrixInteger;
- var I, J, N: Integer;
- NNMatrix: matrixInteger;
- begin
- Read(InF, N);
- SetLength(NNMatrix, N, N);
- for I := 0 to N - 1 do
- for J := 0 to N - 1 do
- Read(InF, NNMatrix [I][J]);
- LoadMatrixFromFile := NNMatrix;
- end;
- function IsElementInArea(I,J,N: Integer) : Boolean;
- begin
- if J < N / 2 then
- if (I > J + 1) and (I < N - J) then
- Result := True
- else
- Result := False;
- end;
- function CalculateSum(var OutF : TextFile; NNMatrix : matrixInteger; N: integer) : Integer;
- var Sum, I, J : Integer;
- begin
- Sum := 0;
- for J := 0 to N div 2 do
- for I := J to N - J - 1 do
- begin
- writeln(NNMatrix[I][J]);
- Sum := Sum + NNMatrix[I][J];
- end;
- WriteLn('---------------------------------');
- for I := 0 to N - 1 do
- begin
- for J := 0 to N - 1 do
- if IsElementInArea(I,J,N) then
- Write(NNMatrix[I][J]);
- WriteLn;
- end;
- WriteLn('---------------------------------');
- WriteLn(OutF,Sum);
- Result := Sum;
- end;
- procedure Main();
- var InF, OutF : TextFile;
- NNMatrix : matrixInteger;
- N, i, j : integer;
- begin
- AssignFile(InF, 'D:\University\ola\input.txt');
- AssignFile(OutF, 'D:\University\ola\output.txt');
- Reset(InF);
- Rewrite(OutF);
- NNMatrix := LoadMatrixFromFile(InF);
- N := length(NNMatrix);
- WriteLn(CalculateSum(OutF,NNMatrix,N));
- Close(InF);
- Close(OutF);
- Readln;
- end;
- begin
- Main();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement