完整的delphi程序设计教程课后习题答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
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(sin((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(sin(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(sin(s/60*2*pi)*180),
yt-round(cos(s/60*2*pi)*180));
end;
end.
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*10,yt-ay*10);
paintbox1.canvas.lineTo(xt+bx*10,yt-by*10);
end;
end.
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:file of studentrecord;
size:integer;
begin
t.xh:=edit1.Text;
t.xm:=edit2.Text;
t.sx:=strtoint(edit3.Text);
t.yy:=strtoint(edit4.Text);
t.dz:=strtoint(edit5.Text);
if radiobutton1.Checked then
t.xb:=true
else
t.xb:=false;
assignfile(f,'c:\my documents\stu.dat');
if fileexists('c:\my documents\stu.dat') then
reset(f)
else
rewrite(f);
size:=filesize(f);
seek(f,size);
write(f,t);
closefile(f);
edit1.Text:='';
edit2.Text:='';
edit3.Text:='';
edit4.Text:='';
edit5.Text:='';
end;
procedure TForm1.Button2Click(Sender: TObject); begin
close;
end;
end.
226页8题保存获得奖学金者
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);