unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
function outsquare(r: integer): real;
function insquare(r: integer): real;
var
Form1: TForm1;
implementation
{$R *.dfm}
function outsquare(r: integer): real; //外切正四边形的面积
begin
outsquare := 2*r*2*r;
end;
function insquare(r: integer): real; //内接正四边形的面积
begin
insquare := 2*r*r;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
radius: integer; //圆的半径
begin
radius := strtoint(Edit1.Text); //字符串转换为整数
Edit2.Text := floattostr(insquare(radius)); //编辑框2为内接正四边形
Edit3.Text := floattostr(outsquare(radius)); //编辑框3为外切正四边形
end;
end.
编辑框2和3的ReadOnly属性为True