| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1278 人关注过本帖
标题:[求助]编写函数Vmax()求出数组元素中最大值
取消只看楼主 加入收藏
ershiyi
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2006-3-15
收藏
 问题点数:0 回复次数:1 
[求助]编写函数Vmax()求出数组元素中最大值

我选修课是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编辑过]

搜索更多相关主题的帖子: 最大值 Vmax 函数 元素 编写 
2006-05-14 21:34
ershiyi
Rank: 1
等 级:新手上路
帖 子:56
专家分:0
注 册:2006-3-15
收藏
得分:0 

怎么没有人回我的帖子呢?
看来还是要靠自己啊!



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];
for i:=1 to 10 do
if a[i]>x then
x:=a[i];
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-05-17 17:00
快速回复:[求助]编写函数Vmax()求出数组元素中最大值
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024507 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved