Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project2;
- {$APPTYPE CONSOLE}
- uses
- System.SysUtils;
- type
- TArray = array of Integer;
- const
- EnterError = 'Error! N should be natutal number from 28 to 31';
- FileError = 'Error! Check file name and file data';
- InputFileName = 'input.txt';
- MaxDays = 31;
- MinDays = 28;
- procedure InputN(var N : Integer);
- var
- IsCorrect : Boolean;
- Input : string;
- begin
- IsCorrect := False;
- repeat
- try
- Writeln('Enter N - the number of days');
- Readln(Input);
- N := StrToInt(Input);
- if(N < MinDays) or (N > MaxDays) then
- Writeln(EnterError)
- else
- IsCorrect := True
- except
- on E : EConvertError do
- Writeln(EnterError);
- end;
- until IsCorrect;
- end;
- procedure InputFromFile(N : Integer; var Days : TArray);
- var
- InputFile : TextFile;
- i, LastIndex : Integer;
- Name : string;
- IsValidName : Boolean;
- begin
- repeat
- Writeln('Enter name of file with your measurements: ');
- Readln(Name);
- IsValidName := False;
- if FileExists(Name) then
- try
- AssignFile(InputFile, Name);
- Reset(InputFile);
- SetLength(Days, N);
- LastIndex := N - 1;
- for i := 0 to LastIndex do
- Read(InputFile, Days[i]);
- for i := 0 to LastIndex do
- Write(Days[i], ' ');
- IsValidName := True;
- finally
- CloseFile(InputFile);
- end
- else
- Writeln(FileError);
- until IsValidName;
- end;
- procedure Output(Amount : Integer);
- begin
- Writeln('');
- if FileExists(InputFileName) then
- Writeln('There are ', Amount, ' days with < 0 degrees');
- end;
- function GetAmountOfColdDays(var Days : TArray) : Integer;
- var
- Counter, i, LastIndex : Integer;
- begin
- Counter := 0;
- LastIndex := High(Days);
- for i := 0 to LastIndex do
- if Days[i] < 0 then
- Inc(Counter);
- GetAmountOfColdDays := Counter;
- end;
- procedure Main();
- var
- N : Integer;
- Days : TArray;
- begin
- Writeln('This program can cal how many times temperature was below 0 degrees');
- InputN(N);
- InputFromFile(N, Days);
- Output(GetAmountOfColdDays(Days));
- Readln;
- end;
- begin
- Main();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement