Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project125;
- {$APPTYPE CONSOLE}
- uses
- SysUtils;
- const
- Rows = 31;
- Columns = 9;
- MinNumber = -32768;
- MaxNumber = 32767;
- type
- Matrix = array [1 .. Rows, 1 .. Columns] of integer;
- function CheckInputFile(var FileName: string): string;
- var
- IsCorrect: Boolean;
- UserFile: TextFile;
- begin
- IsCorrect := False;
- repeat
- try
- Write('Please, Enter the Name of File with Input Data in Format name.txt: ');
- ReadLn(FileName);
- AssignFile(UserFile, FileName);
- Reset(UserFile);
- if FileExists(FileName) then
- begin
- if Eof(UserFile) then
- WriteLn('This File Is Empty. So That:');
- CheckInputFile := FileName;
- IsCorrect := True;
- end;
- except
- on E:EInOutError do
- begin
- IsCorrect := False;
- WriteLn('This File with Such Name Does Not Exist. Please, Try Again.');
- end;
- end;
- until IsCorrect;
- CloseFile(UserFile);
- end;
- function ReadMatrix(var UserFile: TextFile; var Matr: Matrix): Boolean;
- var
- i, j: Integer;
- Error: String;
- IsValidMatrix: Boolean;
- begin
- Reset(UserFile);
- IsValidMatrix := True;
- Error := ' ';
- for i := 1 to Rows do
- begin
- for j := 1 to Columns do
- //begin
- try
- Read(UserFile, Matr[i, j]);
- if (Matr[i, j] > MaxNumber) or (Matr[i, j] < MinNumber) then
- begin
- Error := Error + '[' + IntToStr(i) + ', ' + IntToStr(j) + '] ';
- IsValidMatrix := False;
- end;
- except
- Error := Error + '[' + IntToStr(i) + ', ' + IntToStr(j) + '] ';
- IsValidMatrix := False;
- end;
- //end;
- ReadLn(UserFile);
- end;
- if not IsValidMatrix then
- begin
- Write('Element Musr Be In the Range from ', MinNumber, ' to ', MaxNumber, '. Wrong Elements Are:');
- Writeln(Error);
- end;
- ReadMatrix := IsValidMatrix;
- CloseFile(UserFile);
- end;
- procedure GoodGreatMarks(var UserFile: TextFile; var Matr: Matrix; var GoodRes, GreatRes: Integer);
- var i, j: Integer;
- FileName: string;
- IsValidInput: Boolean;
- begin
- IsValidInput := False;
- repeat
- //repeat
- FileName := CheckInputFile(FileName);
- //until IsValidInput;
- AssignFile(UserFile, FileName);
- IsValidInput := ReadMatrix(UserFile, Matr);
- until IsValidInput;
- Reset(UserFile);
- GoodRes := 0;
- GreatRes := 0;
- for i := 1 to Rows do
- for j := 1 to Columns do
- begin
- Read(UserFile, Matr[i, j]);
- if (Matr[i, j] > 5) then
- begin
- if (Matr[i, j] > 8) then
- begin
- ReadLn(UserFile);
- inc(GreatRes);
- end;
- ReadLn(UserFile);
- inc(GoodRes);
- end;
- ReadLn(UserFile);
- end;
- WriteLn('Amount of Students with Good Results: ', GoodRes);
- WriteLn('Amount of Students with Great Results: ', GreatRes);
- CloseFile(UserFile);
- end;
- procedure OutputToFile(var OutFile: TextFile; var GoodRes, GreatRes: Integer);
- var
- OutFileName: string;
- IsCorrect: Boolean;
- begin
- IsCorrect := False;
- repeat
- Write('Please, Enter the Name of Output File in Format name.txt: ');
- ReadLn(OutFileName);
- if FileExists(OutFileName) then
- IsCorrect := True
- else
- begin
- IsCorrect := False;
- WriteLn('This File with Such Name Does Not Exist. Please, Try Again.');
- end;
- until IsCorrect;
- AssignFile(OutFile, OutFileName);
- Append(OutFile);
- WriteLn(OutFile, 'Amount of Students with Good Results: ', GoodRes);
- WriteLn(OutFile, 'Amount of Students with Great Results: ', GreatRes);
- CloseFile(OutFile);
- end;
- procedure Main();
- var
- Matr: Matrix;
- UserFile: TextFile;
- OutFile: TextFile;
- GoodRes, GreatRes: Integer;
- begin
- GoodGreatMarks(UserFile, Matr, GoodRes, GreatRes);
- OutputToFile(OutFile, GoodRes, GreatRes);
- end;
- begin
- Main();
- ReadLn;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement