`
zendj
  • 浏览: 116014 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

简单计算器

阅读更多

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons,Math;//Math是数学运算单元

type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
SpeedButton1: TSpeedButton;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
SpeedButton7: TSpeedButton;
StaticText1: TStaticText;
procedure SpeedButton1Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
Statictext1.Caption := TSpeedButton(Sender).Caption;
end;

procedure TForm1.SpeedButton7Click(Sender: TObject);
begin
if Trim(StaticText1.Caption) = '+' then
Edit3.Text := FloatToStr(StrToFloat(Edit1.Text)+
StrToFloat(Edit2.Text));
if Trim(StaticText1.Caption) = '-' then
Edit3.Text := FloatToStr(StrToFloat(Edit1.Text)-
StrToFloat(Edit2.Text));
if Trim(StaticText1.Caption) = '*' then
Edit3.Text := FloatToStr(StrToFloat(Edit1.Text)*
StrToFloat(Edit2.Text));
if Trim(StaticText1.Caption) = '/' then
Edit3.Text := FloatToStr(StrToFloat(Edit1.Text)/
StrToFloat(Edit2.Text));
if Trim(StaticText1.Caption) = 'Pow' then
Edit3.Text := FloatToStr(Power(StrToFloat(Edit1.Text),
StrToFloat(Edit2.Text)));
if Trim(StaticText1.Caption) = 'Sqrt' then
Edit3.Text := FloatToStr(Sqrt(StrToFloat(Edit1.Text)));
end;

end.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics