Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  7. Dialogs, Math;
  8.  
  9. type
  10. TForm1 = class(TForm)
  11. procedure freqDevCatcher(sender: TObject; var data: array of integer);
  12. //function freqDevCatcher(sender: TObject);
  13. private
  14. { Private declarations }
  15. public
  16. { Public declarations }
  17. end;
  18.  
  19. var
  20. Form1: TForm1;
  21. data: array of integer;
  22. myFile, freqFile: TextFile;
  23.  
  24. Const
  25. freq = 50;
  26. devPerc = 0.1;
  27.  
  28. implementation
  29.  
  30. {$R *.dfm}
  31.  
  32. SetLength(data, 10);
  33. l:=Length(data);
  34.  
  35. procedure Fill(sender: TObject);
  36. begin
  37. data[0]:= 50;
  38. data[1]:= 55;
  39. data[2]:= 54;
  40. data[3]:= 56;
  41. data[4]:= 57;
  42. data[5]:= 55;
  43. data[6]:= 53;
  44. data[7]:= 52;
  45. data[8]:= 48;
  46. data[9]:= 53;
  47. end;
  48. {AssignFile(myFile, 'C:\Users\admin\Desktop\Roitech 2019\math\Test.txt');
  49. SetLength(data, 100);
  50. for i:= 0 to 99 do
  51. data[i]:=RandomRange(40,60);
  52. ReWrite(myFile);
  53. for i:= 0 to 99 do
  54. WriteLn(myFile, data[i]);
  55. CloseFile(myFile);}
  56.  
  57.  
  58. procedure freqDevCatcher(sender: TObject; var data: array of integer; freq: integer;
  59. devPerc: real; const l: integer);
  60. var max, i, a, b, counter: Integer;
  61.  
  62. begin
  63. AssignFile(freqFile, 'C:\Users\admin\Desktop\Roitech 2019\math\Frequency.txt')
  64. b, a, i, counter:= 0;
  65. max:=data[0];
  66. while i < l do
  67. begin
  68. i:= i+1;
  69.  
  70. if (data[i] <= freq - freq*devPerc) //do by abs
  71. or (data[i] >= freq + freq*devPerc) then
  72. begin
  73. a:= i;
  74. b:= i;
  75. b:= b+1;
  76. {if b>=l do //length
  77. break;}
  78. while counter < 2 do
  79. begin
  80. if (data[b] >= freq - freq*devPerc) //do by abs
  81. and (data[b] <= freq + freq*devPerc) then
  82. begin
  83. b:= b+1;
  84. counter:= counter+1;
  85. end;
  86. else
  87. b:= b+1;
  88. counter:= 0;
  89. end;
  90. end;
  91. i:= b;
  92.  
  93. for i:= a to b do
  94. begin
  95. if data[i]>max then
  96. max:= data[i];
  97. end;
  98. ReWrite(myFile);
  99. WriteLn(freqFile, a, b, max);
  100. CloseFile(freqFile);
  101. end;
  102. end;
  103.  
  104.  
  105.  
  106. end;
  107. end.
  108.  
  109. Здравствуйте, Юрий! Насчёт ABS я думал сразу, но не совсем понял, как его сюда прикрутить, в ближайшее время постараюсь разобраться. Ещё добавлю дату и время, и чуть-чуть не понимаю, как передать величину динамического массива в качестве параметра, поэтому записал его пока туда. Плюс из Вашего примера с числами немного не понял, Вы брали, что "52" уже плохо, как я понял, но не было ни одного числа ниже 50, поэтому хотел уточнить, нужно ли рассматривать в алгоритме числа ниже 50, или ограничиться верхней планкой?
  110.  
  111. С уважением,
  112. Масаев Валерий
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement