1、delphi程序239页1题小时钟procedure TForm1.Timer1Timer(Sender: TObject);varxt,yt:integer;h,m,s,ms:word;begindecodetime(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+roun
2、d(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
3、(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);beginpaintbox1.Refresh;formpaint(sender);end;procedure TForm1.FormPaint(Sender: TObject);varxt,yt:integer;ax,ay,bx,by:integer;beginxt:=paintbox1.ClientWidth div 2;yt:=paintb
4、ox1.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)*
5、(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;typestudentrecord=recordxh,xm:string6;xb:boolean;yy,sx,dz:integer;end;implementation$R *.dfmprocedure TForm1.Button1Click(Sender: TObject);var t:studentrecord;f:file of stud
6、entrecord;size:integer;begint.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 thent.xb:=trueelset.xb:=false;assignfile(f,c:my documentsstu.dat);if fileexists(c:my documentsstu.dat) thenreset(f)elserewrite(f);siz
7、e:=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);beginclose;end;end.226页?var Form1: TForm1;typestudentrecord=recordxh,xm:string6;xb:boolean;yy,sx,dz:integer;end;implementation$R *.d
8、fmprocedure TForm1.FormCreate(Sender: TObject);var t:studentrecord;f:file of studentrecord;xingbie:string;beginassignfile(f,c:my documentsstu0.dat);reset(f);while not eof(f) dobeginread(f,t);if t.xb thenxingbie:=男elsexingbie:=女;listbox1.Items.Add(t.xh+ +t.xm+ +xingbie+ +inttostr(t.sx)+ +inttostr(t.y
9、y)+ +inttostr(t.dz);end;closefile(f);end;procedure TForm1.Button1Click(Sender: TObject);var t:studentrecord;f,f1:file of studentrecord;beginassignfile(f,c:my documentsstu.dat);reset(f);assignfile(f1,c:my documentsstu0.dat);rewrite(f1);while not eof(f) dobeginread(f,t);if(t.sx60)or(t.yy60)or(t.dz255
10、thenshowmessage(范围太大,请重新输入区间端点!)elsebeginsushu:=0.k;for i:=2 to n-1 dofor j:=n to m doif j mod i =0 then sushu:=sushu-j-n;for i:=n to m div 2 dofor j:= i+1 to m doif j mod i =0 then sushu:=sushu-j-n;s:=;s0:=;for i:=n to m doif i-n in sushu thenbeginif length(s0+ +inttostr(i)60 thenbegins:=s+s0+chr(1
11、3);s0:=;end;s0:=s0+ +inttostr(i);end;s0:=s0+ +inttostr(i);end;s:=s+s0;label1.caption:=s;groupbox1.Top:=(panel1.Top-groupbox1.height) div 2;end;procedure TForm1.FormCreate(Sender: TObject);begingroupbox1.Top:=(panel1.Top-groupbox1.height) div 2;end;procedure TForm1.Edit1KeyPress(Sender: TObject; var
12、Key: Char);var j:set of char;beginj:=0.9,#8;if not(key in j) then key:=#0;end;end.148页12题整除的数implementation$R *.dfmfunction d7(x:integer):boolean;beginif x mod 7=0 then d7:=trueelse d7:=false;end;function d17(x:integer):boolean;beginif x mod 17=0 then d17:=trueelse d17:=false;end;procedure TForm1.Fo
13、rmActivate(Sender: TObject);varn:integer;beginfor n:=1000 to 4000 doif d7(n)and d17(n) then memo1.Lines.Add(inttostr(n);end;end.148页17题求斐波那契数列问题implementation$R *.dfmfunction fib(n:integer):int64;begincase n of1,2:fib:=1;elsefib:=fib(n-1)+fib(n-2);end;end;procedure TForm1.Button1Click(Sender: TObjec
14、t);vark:integer;beginmemo1.lines.clear;for k:=1 to strtoint(edit1.text) domemo1.lines.add(format(%2d %3d,k,fib(k);end;end.120页10题,判断是否是闰年procedure TForm1.Button1Click(Sender: TObject);vary,m:integer;beginy:=strtoint(edit1.text);m:=strtoint(edit2.text);label3.Caption:=;if(y mod 4 = 0) and (y mod 100
15、0) or (y mod 400=0) thenlabel3.Caption:=edit1.text+年是闰年,elselabel3.Caption:=edit1.text+年不是闰年,;case m of3,4,5:Label3.Caption:=Label3.Caption+edit2.Text+月份是春天,;6,7,8:Label3.Caption:=Label3.Caption+edit2.Text+月份是夏天,;9,10,11:Label3.Caption:=Label3.Caption+edit2.Text+月份是秋天,;elseLabel3.Caption:=Label3.Cap
16、tion+edit2.Text+月份是冬天,;end;case m of1,3,5,7,8,10,12:Label3.Caption:=Label3.Caption+共有31天,;4,6,9,11:Label3.Caption:=Label3.Caption+共有30天,;elseif(y mod 4 = 0) and (y mod 100 0) or (y mod 400=0) thenLabel3.Caption:=Label3.Caption+共有29天,elseLabel3.Caption:=Label3.Caption+共有28天,;end;end;end.120页11题求和的pro
17、cedure TForm1.Button1Click(Sender: TObject);varn,k,j:integer;s:int64;beginn:=strtoint(edit1.text);j:=0;s:=0;for k:=1 to n dobeginj:=j+k;s:=s+j;end;panel2.Caption:=format(s = %d,s);edit1.setfocus;end;procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);var b:boolean;beginb:=(key#8)and(key#5
18、7);if b then key:=#0;end;end.120页12题男人,女人,小孩各有多少人procedure TForm1.Button1Click(Sender: TObject);varx,y,z:integer;p:string;beginmemo1.clear;for x:=0 to 16 dofor y:=0 to 24 dobeginz:=30-x-y;if 3*x+2*y+z/1=50 thenbeginp:=format(%3d %3d %3d,x,y,z);memo1.lines.add(p);end;end;end;end.98页2题求长方体的表面积procedur
19、e TForm1.Button1Click(Sender: TObject);vars,l,k,h:double;begin l:=strtofloat(edit1.text); k:=strtofloat(edit2.text); h:=strtofloat(edit3.text); s:=2*l*k+2*k*h+2*l*h; label1.Caption:=floattostr(s);end;end.98页5题计算圆的面积和周长procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);varr:real;b:boolean
20、;beginb:=(key#8)and(key.)and(key#13)and(key#57);if b then key:=#0;if key =#13 thenbeginif edit1.text= then edit1.text:=0;r:=strtofloat(edit1.text);if radiobutton1.Checked thenlabel1.Caption:=format(圆的面积为: %f,pi*r*r);if radiobutton2.Checked thenlabel1.Caption:=format(圆的周长为: %f,2*pi*r);if radiobutton3
21、.Checked thenlabel1.Caption:=format(圆的面积为: %f+chr(13)+ 周长为: %f,pi*r*r,2*pi*r);edit1.SelectAll;end;end;procedure TForm1.RadioButton1Click(Sender: TObject);varsender0:tobject;key:char;beginsender0:=edit1;key:=#13;form1.edit1keypress(sender0,key);end;procedure TForm1.RadioButton2Click(Sender: TObject);
22、varsender0:tobject;key:char;beginsender0:=edit1;key:=#13;form1.edit1keypress(sender0,key);end;procedure TForm1.RadioButton3Click(Sender: TObject);varsender0:tobject;key:char;beginsender0:=edit1;key:=#13;form1.edit1keypress(sender0,key);end;end.98页6题统计奇数和偶数的个数procedure TForm1.Button1Click(Sender: TOb
23、ject);vark,j,n:word;begink:=0;n:=combobox1.items.count;for j:=1to n doif strtoint(combobox1.itemsj-1) mod 2 = 0 thenk:=k+1;label1.caption:=format(共有: +#13+%d个偶数,+#13+%d个奇数。,k,n-k);end;procedure TForm1.Button2Click(Sender: TObject);begincombobox1.items.clear;end;procedure TForm1.ComboBox1KeyPress(Sen
24、der: TObject; var Key: Char);beginif (key =#13)and(combobox1.text) then /按键后接收输入的选项begincombobox1.items.insert(0,combobox1.text); /按键后移去选项combobox1.selstart:=0;combobox1.text:=;end;if key = #27 thenif combobox1.itemindex-1 thencombobox1.items.Delete(combobox1.itemindex);end;end.98页8题设置倒计时的时间,并进行倒计时p
25、rocedure TForm1.Timer1Timer(Sender: TObject);varm,n,s,h:integer;begintimer1.Tag:=timer1.Tag-1;m:=timer1.Tag;if m0 thenbegintimer1.enabled:=false;showmessage(预定的时间到了!);edit1.Text:=0;endelsebegins:=m;n:=s div 60;s:=s mod 60;h:=n div 60;n:=n mod 60;maskedit1.text:=format(%d:%d:%d,h,n,s);if n strtoint(edit1.text) then edit1.Text:=inttostr(n);end;end;end.
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1