Цитата(kasir @ 25.5.2007, 23:34 ) | где считается Rras |
у меня тоже такой вопрос!
Цитата(kasir @ 25.5.2007, 23:34 ) | по возрастанию и по убыванию |
как можно на одной кнопку обе сортировки реализовать?!
Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Grids;
type TForm1 = class(TForm) StringGrid1: TStringGrid; Button1: TButton; Label1: TLabel; Button2: TButton; Label2: TLabel; Button3: TButton; Label3: TLabel; Button4: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); var t: TextFile; s: string; i,j: integer; begin StringGrid1.RowCount:=11; AssignFile(t,'1.txt'); Reset(t); while not eof(t) do begin for i:=1 to 11 do begin for j:=0 to 2 do begin ReadLn(t,s); StringGrid1.Cells[j,i]:=s; end; end; end; end;
procedure TForm1.Button2Click(Sender: TObject); var aa,ab,bb,h,o,ac,bc,cc,x,y,p,u: real; // âîò îòñþäà i,j: integer; begin u:=0; aa:=0; o:=0; ab:=0; for i:=1 to 10 do begin u:=strtofloat(StringGrid1.Cells[1,i]); o:=strtofloat(StringGrid1.Cells[2,i]); aa:=aa+u*u; ab:=ab+u; ac:=ac-u*o; bb:=1; bc:=bc-o; end; /// aa*x+ab*y+ac=0 ab*x+bb*y+bc=0 x:=((bc*ab)-(ac*bb))/((aa*bb)-(ab*ab)) ; y:=(-aa*x-ac)/ab ; //äî ñþäà íóæíî çàñóíóòü â îòäåëüíóþ ïðîöåäóðó à òóò ÷òîá âû÷èñëÿëîñü òîëüêî åå âûçîâîì label1.Caption:='y=' +floattostr(y)+' x=' +floattostr(x) ; label2.Caption:='aa=' +floattostr(aa)+' ab=' +floattostr(ab)+' ac=' +floattostr(ac) +' bb=' +floattostr(bb)+' bc=' +floattostr(bc)+' cc=' +floattostr(cc); for i:=1 to 10 do begin // âû÷èñëåíèå ðàñ÷. ñîïðîò. À ÝÒÎ ×ÒÎÁ ÂÛ×ÈÑËßËÎÑÜ ÊÀÊ ÎÒÄÅËÜÍÀß ÔÓÍÊÖÈß è òóò òîëüêî åå âûçîâ o:=strtofloat(StringGrid1.Cells[1,i]); u:=x*o+y; StringGrid1.Cells[3,i]:=floattostr(u); end; for i:=1 to 10 do begin //âû÷èñëåíèå îòíîñèòüåëüíîé ïîãðåøíîñòè o:=strtofloat(StringGrid1.Cells[3,i]); h:=strtofloat(StringGrid1.Cells[2,i]); u:=sqr((o-h)/h); StringGrid1.Cells[4,i]:=floattostr(u); end; end;
procedure TForm1.FormCreate(Sender: TObject); begin StringGrid1.Cells[0,0]:='¹'; StringGrid1.Cells[1,0]:='T'; StringGrid1.Cells[2,0]:='R'; StringGrid1.Cells[3,0]:='R ðàñ÷'; StringGrid1.Cells[4,0]:='R îòí. ïîãð.'; end;
procedure TForm1.Button3Click(Sender: TObject); var ss,s1: string; a,b,j,i,k: integer; label L1,l2; begin a:=0; b:=0; for i:=1 to 10 do begin a:=0; ss:=StringGrid1.Cells[3,i]; for j:=1 to 5 do begin if ss[j]=',' then goto l1 else a:=a+1 ; end; L1: b:=0; b:=a+3; s1:=''; for k:=1 to b do s1:=s1+ss[k]; StringGrid1.Cells[3,i]:=s1; label3.Caption:=StringGrid1.Cells[3,i]; end; ////////////////////////// for i:=1 to 10 do begin a:=0; ss:=StringGrid1.Cells[4,i]; for j:=1 to 5 do begin if ss[j]=',' then goto l2 else a:=a+1 ; end; L2: b:=0; b:=a+5; s1:=''; for k:=1 to b do s1:=s1+ss[k]; StringGrid1.Cells[4,i]:=s1; end; end;
procedure TForm1.Button4Click(Sender: TObject); var arr:array [1..11,1..3] of integer; arr2:array [1..11] of integer; ii, j, i, h:Integer; begin y for i:=1 to 11 do for j:=0 to 2 do arr[i,j]:=StringGrid1.Cells[j,i]; for i:=2 to 11 do for j:=2 to 10 do if(arr[j-1,1]>arr[j-1,1])then//сортировка по 1му столбцу begin for h:=1 to 11 do begin arr2[h]:=arr[j-1,h]; arr[j-1,h]:=arr[j,h]; a[j,h]:=arr2[h]; end; end; for i:=1 to 11 do for j:=0 to 2 do StringGrid1.Cells[j,i]:=arr[i,j]; end;
end.
|
без входных данных сложновато проверить! |