完整的delphi程序设计教程课后习题答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
1.239页1题小时钟
procedure
TForm1.Timer1Timer(Sender: TObject);
var
xt,yt:integer;
h,m,s,ms:word;
begin
decodetime(time,h,m,s,ms);
xt:=paintbox1.clientwidth div 2; yt:=paintbox1.clientheight div 2; paintbox1.refresh;
paintbox1.canvas.moveto(xt,yt); paintbox1.canvas.pen.width:=3; paintbox1.canvas.lineto(xt+round(s in((60*h+m)/(12*60)*2*pi)*100), yt-round(cos((60*h+m)/(12*60)*2 *pi)*100));
paintbox1.canvas.moveto(xt,yt); paintbox1.canvas.pen.width:=2; paintbox1.canvas.lineto(xt+round(s in(m/60*2*pi)*140),
yt-round(cos(m/60*2*pi)*140)); paintbox1.canvas.moveto(xt,yt); paintbox1.canvas.pen.width:=1; paintbox1.canvas.lineto(xt+round(s in(s/60*2*pi)*180),
yt-round(cos(s/60*2*pi)*180)); end;
end.
2.239页3题求两点间的距离procedure
TForm1.Button1Click(Sender: TObject);
begin
paintbox1.Refresh;
formpaint(sender);
end;
procedure
TForm1.FormPaint(Sender: TObject);
var
xt,yt:integer;
ax,ay,bx,by:integer;
begin
xt:=paintbox1.ClientWidth div 2; yt:=paintbox1.Clientheight div 2; paintbox1.canvas.MoveTo(xt,0);
paintbox1.canvas.lineTo(xt,2*yt);
paintbox1.canvas.MoveTo(0,yt);
paintbox1.canvas.lineTo(2*xt,yt);
ax:=strtoint(edit1.text);
ay:=strtoint(edit2.text);
bx:=strtoint(edit3.text);
by:=strtoint(edit4.text);
edit5.Text:=floattostr(sqrt((ax-bx)*
(ax-bx)+(ay-by)*(ay-by)));
paintbox1.canvas.MoveTo(xt+ax*1
0,yt-ay*10);
paintbox1.canvas.lineTo(xt+bx*10,
yt-by*10);
end;
end.
3.226页5题输入学生成绩
var
Form1: TForm1;
type
studentrecord=record
xh,xm:string[6];
xb:boolean;
yy,sx,dz:integer;
end;
implementation
{$R *.dfm}
procedure
TForm1.Button1Click(Sender:
TObject);
var t:studentrecord;
f,f1:file of studentrecord;
p1,p2:boolean;
begin
assignfile(f,'c:\my
documents\stu.dat');
reset(f);
assignfile(f1,'c:\my
documents\stu1.dat');
rewrite(f1);
while not eof(f) do
begin
read(f,t);
p1:=(t.sx>=85)and(t.yy>=85)and(t.
dz>=85);
p2:=t.sx+t.yy+t.dz>=270;
if p1 or p2 then
write(f1,t);
end;
closefile(f);
closefile(f1);
end;
procedure
TForm1.FormCreate(Sender:
TObject);
var t:studentrecord;
f:file of studentrecord;
xingbie:string;
begin
assignfile(f,'c:\my
documents\stu.dat');
reset(f);
while not eof(f) do
begin
read(f,t);
if t.xb then
xingbie:='男'
else
xingbie:='女';
listbox1.Items.Add(t.xh+' '+t.xm+'
'+xingbie+' '+inttostr(t.sx)+
' '+inttostr(t.yy)+' '+inttostr(t.dz));
end;
closefile(f);
end;
procedure
TForm1.Button2Click(Sender:
TObject);
begin
close;
end;
end.
4.226页8题保存获得奖学金者
var
Form1: TForm1;
type
studentrecord=record
xh,xm:string[6];
xb:boolean;
yy,sx,dz:integer;
end;
implementation
{$R *.dfm}
procedure