Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- System.SysUtils, Math;
- const
- FileCompositionError = 'Error! Your file is composed incorrectly. ';
- ReadFileError = 'Error! Flie contains invalid data. ';
- NoSuchFileError = 'Error! No such file. ';
- type
- TDots = array of array [0..1] of Integer;
- function EnterInputFileName() : string;
- var
- Name : string;
- begin
- Writeln('Enter input file name');
- Readln(Name);
- while not FileExists(Name) do
- begin
- Writeln(NoSuchFileError, 'Input file name again');
- Readln(Name);
- end;
- EnterInputFileName := Name;
- end;
- function EnterOutputFileName() : string;
- var
- Name : string;
- begin
- Writeln('Enter output file name');
- Readln(Name);
- EnterOutputFileName := Name;
- end;
- function IsFileValid(var Dots : TDots; var InputFile : TextFile) : Boolean;
- var
- IsValid : Boolean;
- //Dots : TDots;
- i : Integer;
- begin
- i := 0;
- IsValid := True;
- while not EoF(InputFile) and IsValid do
- begin
- SetLength(Dots, i + 1);
- Read(InputFile, Dots[i][0]);
- if EoLN(InputFile) then
- IsValid := False;
- Read(InputFile, Dots[i][1]);
- if not EoLN(InputFile) then
- IsValid := False;
- Inc(i);
- end;
- IsFileValid := IsValid;
- end;
- procedure InputDots(var InputFile : TextFile; var Dots : TDots);
- var
- i : Integer;
- Name, Input : string;
- begin
- Reset(InputFile);
- i := 0;
- while not EoF(InputFile) do
- begin
- SetLength(Dots, i + 1);
- Read(InputFile, Dots[i][0]);
- Read(InputFile, Dots[i][1]);
- Inc(i);
- end;
- end;
- function GetAmount(var Dots : TDots) : Integer;
- var
- Counter, i, j, LastIndex : Integer;
- begin
- Counter := 0;
- LastIndex := High(Dots);
- for i := 0 to LastIndex do
- if (Dots[i][0] >= 0) and (Dots[i][1] >= 0) then
- Counter := Counter + 1;
- GetAmount := Counter;
- end;
- procedure OutputAnswer(Answer : Integer; OutputFileName : string);
- var
- OutputFile : TextFile;
- begin
- AssignFile(OutputFile, OutputFileName);
- Rewrite(OutputFile);
- Writeln(Format('There are %d dots in the 1-st quarter', [Answer]));
- Writeln(OutputFile, Format('There are %d dots in the 1-st quarter', [Answer]));
- CloseFile(OutputFile);
- end;
- procedure Main();
- var
- Dots : TDots;
- //Dots2 : TDots;
- InputFileName, OutputFileName : string;
- InputFile, OutputFile : TextFile;
- begin
- Writeln('This program can calculate how many dots are in the 1-st quarter');
- try
- InputFileName := EnterInputFileName();
- AssignFile(InputFile, InputFileName);
- Reset(InputFile);
- if IsFileValid(Dots, InputFile) then
- begin
- //InputDots(InputFile, Dots);
- OutputFileName := EnterOutputFileName();
- OutputAnswer(GetAmount(Dots), OutputFileName);
- end
- else
- Writeln(FileCompositionError);
- except
- Writeln(ReadFileError);
- end;
- CloseFile(InputFile);
- Readln;
- end;
- begin
- Main();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement