Читайте также:
|
|
Текст консольного приложения:
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils;
var X: array of integer;
Y: array of integer;
i,j,K1,K2,N,S1,S2,D: integer;
SR1,SR2,SR: real;
begin
write('N=');
readln(N);
Write('D=');
readln(D);
setLength(x,N);
for i:=0 to N-1 do begin
write('X(',i,')=');
readln(x[i]);
end;
S1:=0;
K1:=0;
for i:=0 to N-1 do
if x[i]>0 then begin
S1:=S1+x[i];
INC(K1);
end;
if K1=0 then
Writeln(' pol. net')
else begin
SR1:=S1/K1;
writeln('SR1=',SR1)
end;
S2:=0;
K2:=0;
j:=0;
for i:=0 to N-1 do
if x[i]<0 then begin
S2:=S2+x[i];
INC(K2);
end;
if K2=0 then
Writeln(' otp. net')
else begin
SR2:=S2/K2;
writeln('SR2=',SR2);
end;
if (K1>0) and (K2>0) then
SR:=SR1+SR2;
for i:=0 to N-1 do
begin
if x[i]>D then
begin
j:=j+1;
setlength(y,j);
y[j-1]:=i;
end;
end;
writeln('N elementov>D');
For i:=0 To j-1 do
writeln('Y(',i,')=',Y[i]);
Writeln;
Writeln('srednee=',SR:6:2);
readln;
end.
Текст оконного приложения:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, ExtCtrls,Math;
Type
TForm1 = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
Panel3: TPanel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Edit4: TEdit;
Label4: TLabel;
StringGrid1: TStringGrid;
StringGrid2: TStringGrid;
Button5: TButton;
Label3: TLabel;
Label6: TLabel;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender:TObject);
begin
Panel2.Visible:=false;
Panel3.Visible:=false;
Edit1.setFocus;
end;
procedure TForm1.Button1Click(Sender: TObject);
var N,i,D:integer; x:array of integer;
begin
if (edit1.text=' ') or (edit2.Text=' ') then begin
Showmessage(' Не заполнены поля! '); Edit1.SetFocus;
exit;
end;
N:=strtoint(Edit1.Text);
D:=strtoint(Edit2.Text);
Panel1.Enabled:=false;
Panel2.Visible:=true;
Panel3.Visible:=false;
N:=StrtoInt(Edit1.text);
stringGrid1.ColCount:=N;
SetLength(x,N);
for i:=1 to N do
stringGrid1.Cells[i-1,0]:='x('+IntToStr(i)+')';
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
Panel1.Enabled:=True;
Panel2.Visible:=False;
Edit1.SetFocus;
end;
procedure TForm1.Button3Click(Sender: TObject);
var X: array of integer;
Y: array of integer;
i,j,K1,K2,N,S1,S2,D: integer;
SR1,SR2,SR: real;
begin
Panel2.Enabled:=false;
Panel3.Visible:=true;
N:=strtoint(Edit1.Text);
D:=strtoint(Edit2.Text);
setLength(x,N);
for i:=0 to N-1 do
x[i]:=strtoint(Stringgrid1.Cells[i,1]);
S1:=0;
K1:=0;
for i:=0 to N-1 do
if x[i]>0 then begin
S1:=S1+x[i];
INC(K1);
end;
if K1=0 then
Showmessage(' Положительных нет')
else
SR1:=S1/K1;
S2:=0;
K2:=0;
j:=0;
for i:=0 to N-1 do
if x[i]<0 then begin
S2:=S2+x[i];
INC(K2);
end;
if K2=0 then
Showmessage(' Отрицательных нет')
else
SR2:=S2/K2;
if (K1>0) and (K2>0) then
SR:=SR1+SR2;
Edit4.Text:=floattostr(sr);
for i:=0 to N-1 do
begin
if x[i]>D then
begin
j:=j+1;
setlength(Y,j);
Y[j-1]:=i;
end;
end;
stringGrid2.ColCount:=j;
SetLength(Y,j);
stringGrid2.Cells[i-1,0]:='Y('+IntToStr(i)+')';
For i:=0 To j-1 do begin
Stringgrid2.Cells[i,1]:=Inttostr(Y[i]+1);
stringGrid2.Cells[i,0]:='Y('+IntToStr(i)+')';
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
panel2.Visible:=false;
panel1.Visible:=true;
panel1.Enabled:=true;
panel2.Enabled:=true;
panel3.Visible:=false;
edit4.Text:=' ';
edit1.Text:=' ';
edit2.Text:=' ';
edit1.SetFocus;
end;
end.
Дата добавления: 2014-12-19; просмотров: 98 | Поможем написать вашу работу | Нарушение авторских прав |