Calc.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:6k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <math.h>
- #include "Calc.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- float temp1;
- float temp2;
- int flag;
- int append;
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button1->Caption;
- //单击1按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- Form1->Edit1->Clear();
- //清除文本框中的内容
- temp1=0;
- temp2=0;
- flag=0;
- append=0;
- //变量赋初值
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button2->Caption;
- //单击2按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button3->Caption;
- //单击3按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button4Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button4->Caption;
- //单击4按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button5Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button5->Caption;
- //单击5按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button6Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button6->Caption;
- //单击6按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button7Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button7->Caption;
- //单击7按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button8Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button8->Caption;
- //单击8按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button9Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button9->Caption;
- //单击9按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button10Click(TObject *Sender)
- {
- if (append!=0) Form1->Edit1->Clear();
- Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button10->Caption;
- //单击0按钮
- append=0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button13Click(TObject *Sender)
- {
- flag=1;
- //设置加法标志
- if (Form1->Edit1->Text!="")
- temp1=StrToFloat(Form1->Edit1->Text);
- //为变量temp1赋值
- //Form1->Edit1->Clear();
- //清空文本框
- append=1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button14Click(TObject *Sender)
- {
- flag=2;
- //设置减法标志
- if (Form1->Edit1->Text!="")
- temp1=StrToFloat(Form1->Edit1->Text);
- //为变量temp1赋值
- //Form1->Edit1->Clear();
- //清空文本框
- append=1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button15Click(TObject *Sender)
- {
- flag=3;
- //设置乘法标志变量值
- if (Form1->Edit1->Text!="")
- temp1=StrToFloat(Form1->Edit1->Text);
- //为变量temp1赋值
- //Form1->Edit1->Clear();
- //清空文本框
- append=1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button16Click(TObject *Sender)
- {
- flag=4;
- //设置除法标志
- if (Form1->Edit1->Text!="")
- temp1=StrToFloat(Form1->Edit1->Text);
- //为变量temp1赋值
- //Form1->Edit1->Clear();
- //清空文本框
- append=1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button11Click(TObject *Sender)
- {
- switch (flag)
- {
- case 1: temp2=StrToFloat(Edit1->Text)+StrToFloat(temp1);
- //进行加法运算
- break;
- case 2: temp2=StrToFloat(temp1)-StrToFloat(Edit1->Text);
- //进行减法运算
- break;
- case 3: temp2=StrToFloat(Edit1->Text)*StrToFloat(temp1);
- //进行乘法运算
- break;
- case 4: temp2=StrToFloat(temp1)/StrToFloat(Edit1->Text);
- //进行除法运算
- }
- Edit1->Text=FloatToStr(temp2);
- //显示运算结果
- append=1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button12Click(TObject *Sender)
- {
- Form1->Edit1->Clear();
- //清除文本框中的内容
- temp1=0;
- temp2=0;
- flag=0;
- //变量赋初值
- }
- //---------------------------------------------------------------------------