Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- System.SysUtils;
- const
- ErrorMessage = 'Error! Incorrect input (N should be natural number from 1 to 2147483647)';
- InputFileName = 'input.txt';
- OutputFileName = 'output.txt';
- FileCompositionError = 'Error! Your file is composed incorrectly';
- ReadFileError = 'Error! Flie contains invalid data';
- type
- TDots = array of array [0..2] of Integer;
- procedure Calculate(var Dots : TDots);
- var
- Counter, i, j, LastIndex : Integer;
- OutputFile : TextFile;
- begin
- Counter := 0;
- LastIndex := High(Dots);
- Assign(OutputFile, OutputFileName);
- Rewrite(OutputFile);
- Writeln('Next dots are in 1-st quarter:');
- Writeln(OutputFile, 'Next dots are in 1-st quarter:');
- for i := 0 to LastIndex do
- if (Dots[i][0] >= 0) and (Dots[i][1] >= 0) then
- begin
- Counter := Counter + 1;
- Writeln('(', Dots[i][0], ' , ', Dots[i][1], ') ');
- Writeln(OutputFile, '(', Dots[i][0], ' , ', Dots[i][1], ') ');
- end;
- Writeln(' = ', Counter, ' in genereal');
- Writeln(OutputFile, ' = ', Counter, ' in genereal');
- CloseFile(OutputFile);
- end;
- procedure InputOnlyDots(var Dots : TDots);
- var
- Counter, i : Integer;
- IsCorrect : Boolean;
- InputFile : TextFile;
- Name, Input : string;
- begin
- i := 0;
- Writeln('Enter file name');
- Readln(Name);
- while not FileExists(Name) do
- begin
- Writeln('No such file. Input file name again');
- Readln(Name);
- end;
- IsCorrect := True;
- try
- AssignFile(InputFile, InputFileName);
- Reset(InputFile);
- while not EoF(InputFile) and IsCorrect do
- begin
- SetLength(Dots, i + 1);
- Read(InputFile, Dots[i][0]);
- if EoLN(InputFile) then
- IsCorrect := False;
- Read(InputFile, Dots[i][1]);
- if not EoLN(InputFile) then
- IsCorrect := False;
- //Write('(', Dots[i][0], ' ', Dots[i][1], '), ');
- Inc(i);
- end;
- if not IsCorrect then
- Writeln(FileCompositionError);
- except
- Writeln(ReadFileError);
- end;
- CloseFile(InputFile);
- end;
- procedure Main();
- var
- Dots : TDots;
- begin
- Writeln('This program can calculate how many dots are in the 1-st quarter');
- InputOnlyDots(Dots);
- Calculate(Dots);
- Readln;
- end;
- begin
- Main();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement