Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project3;
- {$APPTYPE CONSOLE}
- {$R *.res}
- uses
- System.SysUtils;
- type
- stringMatrix = array [0..29, 0..10] of String;
- const
- InputMessage =
- 'Пожалуйста, введите имя файла, из которого будут считываться данные.';
- OutputMessage =
- 'Пожалуйста, введите имя файла, в который желаете записать результат.';
- MistakeFoundMessage =
- 'Ошибка! Файл с таким именем не найден. Повторите попытку.';
- MistakeOpenMessage =
- 'Ошибка! Невозможно открыть данный файл. Пожалуйста, проверьте файл и повторите попытку.';
- {function RandomNum(var i, j: integer);
- var
- InFile: TextFile;
- FileName: String;
- begin
- for I := 1 to 30 do
- begin
- FileName := '';
- FileName := IntToStr(random(10) + 1);
- for J := 1 to 9 do
- FileName := Str + ', ' + IntToStr(random(10) + 1);
- WriteLn(InFile, FileName);
- end;
- end}
- function CountNegativeMarks(var Marks : array of String) : String;
- var
- c, I, J, Answer: integer;
- begin
- Answer := 0;
- for I := 0 to 9 do
- if (Marks[I] = '1') or (Marks[I] = '2') or (Marks[I] = '3') then
- inc(Answer);
- Result := IntToStr(Answer);
- end;
- procedure LoadMatrixFromFile (var Students: stringMatrix);
- var
- InputIsNotCorrect: Boolean;
- InFile: TextFile;
- Reader: String;
- J, I: integer;
- begin
- repeat
- InputIsNotCorrect := True;
- WriteLn(InputMessage + #13#10 + 'Например, "C:\Users\Ольга\Desktop\LabWork\Unit 2\Lab 3\input.txt"');
- ReadLn(Reader);
- if FileExists(Reader) then
- begin
- try
- AssignFile(InFile, Reader);
- Reset(InFile);
- except
- WriteLn(MistakeOpenMessage);
- InputIsNotCorrect := False;
- end;
- if InputIsNotCorrect then
- try
- for I := 0 to 29 do
- begin
- ReadLn(InFile, Reader);
- for J := 0 to 9 do
- begin
- Students[I][J] := Copy(Reader, 1, pos(', ', Reader) - 1);
- delete(Reader, 1, pos(', ', Reader) + 1);
- end;
- Students[I][9] := Reader;
- end;
- except
- WriteLn('Ошибка! Файл содержит неверные данные. Пожалуйста, проверьте файл и повторите попытку.');
- InputIsNotCorrect := False;
- end;
- CloseFile(InFile);
- end
- else
- begin
- WriteLn(MistakeFoundMessage);
- InputIsNotCorrect := False;
- end;
- until InputIsNotCorrect;
- end;
- procedure SaveMatrixToFile (Students: stringMatrix);
- var
- OutputIsNotCorrect: Boolean;
- OutFile: TextFile;
- Reader: String;
- I, J : integer;
- begin
- repeat
- OutputIsNotCorrect := True;
- WriteLn(OutputMessage + #13#10 + 'Например, "C:\Users\Ольга\Desktop\LabWork\Unit 2\Lab 3\output.txt"');
- ReadLn(Reader);
- if FileExists(Reader) then
- begin
- try
- AssignFile(OutFile, Reader);
- Rewrite(OutFile);
- except
- WriteLn(MistakeOpenMessage);
- OutputIsNotCorrect := False;
- end;
- if OutputIsNotCorrect then
- begin
- for I := 0 to 29 do
- Students[I][10] := CountNegativeMarks(Students[I]);
- for I := 0 to 29 do
- begin
- Write(OutFile,'Студент №', i + 1,': ');
- Write('Студент №', i + 1,': ');
- for J := 0 to 8 do
- begin
- Write(OutFile, Students[I][J], ', ');
- Write(Students[I][J], ', ');
- end;
- WriteLn(OutFile, Students[I][9], ' : негативных оценок = ', Students[I][10]);
- WriteLn(Students[I][9], ' : негативных оценок = ', Students[I][10]);
- end;
- CloseFile(OutFile);
- end;
- end
- else
- begin
- OutputIsNotCorrect := False;
- WriteLn(MistakeFoundMessage);
- end;
- until OutputIsNotCorrect;
- end;
- procedure Main();
- var
- P, Answer: integer;
- Students : stringMatrix;
- begin
- LoadMatrixFromFile(Students);
- SaveMatrixToFile(Students);
- ReadLn;
- end;
- begin
- Main()
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement