Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, Math;
- type
- TForm1 = class(TForm)
- procedure freqDevCatcher(sender: TObject; var data: array of integer);
- //function freqDevCatcher(sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- data: array of integer;
- myFile, freqFile: TextFile;
- Const
- freq = 50;
- devPerc = 0.1;
- implementation
- {$R *.dfm}
- SetLength(data, 10);
- l:=Length(data);
- procedure Fill(sender: TObject);
- begin
- data[0]:= 50;
- data[1]:= 55;
- data[2]:= 54;
- data[3]:= 56;
- data[4]:= 57;
- data[5]:= 55;
- data[6]:= 53;
- data[7]:= 52;
- data[8]:= 48;
- data[9]:= 53;
- end;
- {AssignFile(myFile, 'C:\Users\admin\Desktop\Roitech 2019\math\Test.txt');
- SetLength(data, 100);
- for i:= 0 to 99 do
- data[i]:=RandomRange(40,60);
- ReWrite(myFile);
- for i:= 0 to 99 do
- WriteLn(myFile, data[i]);
- CloseFile(myFile);}
- procedure freqDevCatcher(sender: TObject; var data: array of integer; freq: integer;
- devPerc: real; const l: integer);
- var max, i, a, b, counter: Integer;
- begin
- AssignFile(freqFile, 'C:\Users\admin\Desktop\Roitech 2019\math\Frequency.txt')
- b, a, i, counter:= 0;
- max:=data[0];
- while i < l do
- begin
- i:= i+1;
- if (data[i] <= freq - freq*devPerc) //do by abs
- or (data[i] >= freq + freq*devPerc) then
- begin
- a:= i;
- b:= i;
- b:= b+1;
- {if b>=l do //length
- break;}
- while counter < 2 do
- begin
- if (data[b] >= freq - freq*devPerc) //do by abs
- and (data[b] <= freq + freq*devPerc) then
- begin
- b:= b+1;
- counter:= counter+1;
- end;
- else
- b:= b+1;
- counter:= 0;
- end;
- end;
- i:= b;
- for i:= a to b do
- begin
- if data[i]>max then
- max:= data[i];
- end;
- ReWrite(myFile);
- WriteLn(freqFile, a, b, max);
- CloseFile(freqFile);
- end;
- end;
- end;
- end.
- Здравствуйте, Юрий! Насчёт ABS я думал сразу, но не совсем понял, как его сюда прикрутить, в ближайшее время постараюсь разобраться. Ещё добавлю дату и время, и чуть-чуть не понимаю, как передать величину динамического массива в качестве параметра, поэтому записал его пока туда. Плюс из Вашего примера с числами немного не понял, Вы брали, что "52" уже плохо, как я понял, но не было ни одного числа ниже 50, поэтому хотел уточнить, нужно ли рассматривать в алгоритме числа ниже 50, или ограничиться верхней планкой?
- С уважением,
- Масаев Валерий
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement