Pascal之(二维数组)
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Pascal之(⼆维数组)⼆维数组
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DBCtrls;
type
queue = array[1..4, 1..20] of real;
TForm1 = class(TForm)
lbl1: TLabel;
lbl2: TLabel;
lbl3: TLabel;
lbl4: TLabel;
lbl5: TLabel;
btn1: TButton;
edt1: TEdit;
edt2: TEdit;
edt3: TEdit;
edt4: TEdit;
dblst1: TDBListBox;
lbl6: TLabel;
btn2: TButton;
btn3: TButton;
labresult: TLabel;
procedure btn2Click(Sender: TObject);
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
function AVG(queue1: queue; m, n: integer): real;
{ Public declarations }
end;
var
Form1: TForm1;
i: integer;
score: queue;
implementation
{$R *.dfm}
function TForm1.AVG(queue1: queue; m, n: integer): real;
var
k: integer;
sum: real;
begin
sum := 0;
for k := 1to n do
sum := sum + queue1[m][k];
Result := sum / n;
end;
procedure TForm1.btn2Click(Sender: TObject);
var
engave,mathave,vfpave,dataave:real; // 分别存放四门功课的平均成绩
begin
engave:=AVG(score,1,i); // 调⽤函数aver,求i个学⽣英语成绩的平均值
mathave:=AVG(score,2,i); // 调⽤函数aver,求i个学⽣数学成绩的平均值
vfpave:=AVG(score,3,i); // 调⽤函数aver,求i个学⽣vfp成绩的平均值
dataave:=AVG(score,4,i); // 调⽤函数aver,求i个学⽣数据结构的平均值
// 计算结果显⽰在labresult上
labresult.caption:='各科的平均成绩是:'+chr(13)+chr(13);
labresult.caption:=labresult.caption+' 英语:'+floattostr(engave);
labresult.caption:=labresult.caption+' ; '+' 数学:'+floattostr(mathave);
labresult.caption:=labresult.caption+' ; '+' VFP:'+floattostr(vfpave);
labresult.caption:=labresult.caption+';'+' 数据结构:'+floattostr(dataave);
end;
procedure TForm1.btn1Click(Sender: TObject);
var
str1: string;
begin
i:=i+1; // 每输⼊⼀学⽣信息i加1
score[1][i]:=strtofloat(edt1.Text); // score数组的第1⾏存放英语成绩
score[2][i]:=strtofloat(edt2.Text); // score数组的第2⾏存放数学成绩
score[3][i]:=strtofloat(edt3.Text); // score数组的第3⾏存放vfp成绩 score[4][i]:=strtofloat(edt4.Text); // score数组的第4⾏存放数据结构 str1:=edt1.Text+''+edt2.Text +''+edt3.Text+'' +edt4.Text;
dblst1.Items.add(str1) ; // 将第i个学⽣的各门成绩添加到scorelist列表中 edt1.Text:=''; //清空⽤于输⼊成绩的各⽂本框
edt2.Text:='';
edt3.Text:='';
edt4.Text:='';
edt1.SetFocus; // 光标定位在engedit⽂本框上,等待下次输⼊end;
end.。