Thema: Delphi Mittelwert von Myarray

Einzelnen Beitrag anzeigen

Bericender

Registriert seit: 10. Sep 2008
22 Beiträge
 
#12

Re: Mittelwert von Myarray

  Alt 10. Sep 2008, 19:36
unit uZufall;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;

type
TMyarray = Array [1..2,1..5] Of Integer;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Edit3: TEdit;
StringGrid1: TStringGrid;
Memo1: TMemo;
Edit1: TEdit;
Edit2: TEdit;
Edit4: TEdit;
procedure FormCreate(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;

var
Form1: TForm1;
MyArray: TMyarray;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption := 'neu';
Button2.Caption := 'memo';
Button3.Caption := 'grid';
Button4.Caption := 'edit';
Button5.Caption := 'MWZeile';
Button6.Caption := 'MWKomplett';
Button7.Caption := 'close';
StringGrid1.ColCount := 4;
StringGrid1.RowCount := 2;
Memo1.Clear;
Edit1.Visible := false;
Edit2.Visible := false;
Edit3.Visible := false;
Edit4.Visible := false;
Stringgrid1.Visible :=false;
Memo1.Visible := false;
end;

procedure fuellen;
var z,sp:integer;
begin
randomize;
for z:=1 to 4 do
for sp:=1 to high(Myarray)do
myarray[sp,z]:=random(101)
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
fuellen;
end;

procedure TForm1.Button2Click(Sender: TObject);
var a1,a2 : string; sp : integer;
begin
memo1.Visible := true;
a1 := '';
for sp:=1 to 4 do
a1 := a1+ ' '+inttostr(myarray[1,sp]);
memo1.lines.add (a1);

a2 := '';
for sp:=1 to 4 do
a2 := a2+ ' '+inttostr(myarray[2,sp]);
memo1.lines.add (a2);
end;

procedure TForm1.Button3Click(Sender: TObject);
var row,col : integer;
begin
stringgrid1.Visible:= true;
for row:= 0 to 2 do
for col:= 0 to 4 do
stringgrid1.cells[col,row]:=inttostr(myarray[row+1,col+1])
end;

procedure TForm1.Button4Click(Sender: Tobject);
var a1,a2 : string; sp : integer;
begin
edit3.Visible:=true;
Edit1.Visible:= true;
a1 := '';
for sp:=1 to 4 do
a1 := a1+ ' '+inttostr(myarray[1,sp]);
edit3.text := a1;

a2:= '';
for sp:=1 to 4 do
a2 := a2+ ' '+inttostr(myarray[2,sp]);
edit1.text := a2;
end;


procedure TForm1.Button7Click(Sender: TObject);
begin
close
end;


procedure TForm1.Button6Click(Sender: TObject);
var
i,summe:integer; mitte:real;
begin
edit2.Visible:=true;
summe := 0;
for
i := Low(Myarray) to High(Myarray) do
summe := Summe + Myarray[i];
mitte := summe / 4;
end;
edit2.Text:= inttostr(summe);

end.
  Mit Zitat antworten Zitat