我选修课是dephi快要期末考试了,这是平时作业要交的
但还没有按要求做完,请各位帮忙该一下,小弟在此多谢了.
实验内容
一 数组
1 定义一个大小为10的数组
2 利用Edit组件为数组赋值
二 过程与函数
1 编写函数Vmax()求出数组元素中最大值
2 编写函数Vsort()对数组排序
Edit
数1┎ 数6┎ 最大值
2┎ 7┎
3┎ 8┎ 排序
4┎ 9┎
5┎ 10┎ 退出
我做的是这样的
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Arr=array[1..10] of integer;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
Edit10: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Button1: TButton;
Button2: TButton;
Label11: TLabel;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
A:arr;
implementation
{$R *.dfm}
function umax(a:arr):string;
var i,x:integer;
begin
x:=a[1];
result:=inttostr(x);
end;
function usort(a:arr):string;
var
i,j,x:integer;
str:string;
begin
for i:=1 to 9 do
for j:=i+1 to 10 do
if a[i]<a[j] then
begin
x:=a[i];
a[i]:=a[j];
a[j]:=x;
end;
str:='';
for i:=1 to 10 do
str:=str + inttostr(a[i]) + ',' ;
result:=str;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
a[1] :=strtoint(edit1.text);
a[2] :=strtoint(edit2.text);
a[3] :=strtoint(edit3.text);
a[4] :=strtoint(edit4.text);
a[5] :=strtoint(edit5.text);
a[6] :=strtoint(edit6.text);
a[7] :=strtoint(edit7.text);
a[8] :=strtoint(edit8.text);
a[9] :=strtoint(edit9.text);
a[10] :=strtoint(edit10.text);
label11.Caption:='';
for i:=1 to 10 do
label11.Caption:=label11.Caption + inttostr(a[i]) + ',' ;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
close;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
label11.Caption:=umax(a);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
label11.Caption:=usort(a);
end;
end.
[此贴子已经被作者于2006-5-14 21:40:55编辑过]