Урок на Делфи 74. Среднее арифмитическое значение
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,math;
type
TForm1 = class(TForm)
Button1: TButton;
ListBox1: TListBox;
Label1: TLabel;
Label2: TLabel;
Button2: TButton;
Label3: TLabel;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i,q:integer;
w:real;
begin
q:=0;
for I := 0 to ListBox1.Count-1 do
begin
q:=StrToInt(ListBox1.Items[i])+q;
end;
w:=q/ListBox1.Count;
Label2.Caption:=IntToStr(q)+'/'+IntToStr(ListBox1.Count);
Label1.Caption:='. . '+FloatToStr(w);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
m:array of Single;
i:integer;
otvet:Double;
begin
SetLength(m,ListBox1.Count);
for I := 0 to ListBox1.Count-1 do
begin
m[i]:=StrToInt(ListBox1.Items[i]);
Memo1.Lines.Add(ListBox1.Items[i]);
end;
otvet:=Mean(m);
Label3.Caption:='. . '+FloatToStr(otvet);
end;
end.