Calc.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:6k
源码类别:

Delphi/CppBuilder

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include <math.h>
  5. #include "Calc.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma resource "*.dfm"
  9. TForm1 *Form1;
  10. float temp1;
  11. float temp2;
  12. int flag;
  13. int append;
  14. //---------------------------------------------------------------------------
  15. __fastcall TForm1::TForm1(TComponent* Owner)
  16.         : TForm(Owner)
  17. {
  18. }
  19. //---------------------------------------------------------------------------
  20. void __fastcall TForm1::Button1Click(TObject *Sender)
  21. {
  22. if (append!=0) Form1->Edit1->Clear();
  23.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button1->Caption;
  24.  //单击1按钮
  25.  append=0;
  26. }
  27. //---------------------------------------------------------------------------
  28. void __fastcall TForm1::FormCreate(TObject *Sender)
  29. {
  30.  Form1->Edit1->Clear();
  31.  //清除文本框中的内容
  32.  temp1=0;
  33.  temp2=0;
  34.  flag=0;
  35.  append=0;
  36.  //变量赋初值
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TForm1::Button2Click(TObject *Sender)
  40. {
  41. if (append!=0) Form1->Edit1->Clear();
  42.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button2->Caption;
  43.  //单击2按钮
  44.  append=0;
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::Button3Click(TObject *Sender)
  48. {
  49. if (append!=0) Form1->Edit1->Clear();
  50.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button3->Caption;
  51.  //单击3按钮
  52.  append=0;
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::Button4Click(TObject *Sender)
  56. {
  57. if (append!=0) Form1->Edit1->Clear();
  58.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button4->Caption;
  59.  //单击4按钮
  60.  append=0;
  61. }
  62. //---------------------------------------------------------------------------
  63. void __fastcall TForm1::Button5Click(TObject *Sender)
  64. {
  65. if (append!=0) Form1->Edit1->Clear();
  66.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button5->Caption;
  67.  //单击5按钮
  68.  append=0;
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TForm1::Button6Click(TObject *Sender)
  72. {
  73. if (append!=0) Form1->Edit1->Clear();
  74.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button6->Caption;
  75.  //单击6按钮
  76.  append=0;
  77. }
  78. //---------------------------------------------------------------------------
  79. void __fastcall TForm1::Button7Click(TObject *Sender)
  80. {
  81. if (append!=0) Form1->Edit1->Clear();
  82.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button7->Caption;
  83.  //单击7按钮
  84.  append=0;
  85. }
  86. //---------------------------------------------------------------------------
  87. void __fastcall TForm1::Button8Click(TObject *Sender)
  88. {
  89. if (append!=0) Form1->Edit1->Clear();
  90.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button8->Caption;
  91.  //单击8按钮
  92.  append=0;
  93. }
  94. //---------------------------------------------------------------------------
  95. void __fastcall TForm1::Button9Click(TObject *Sender)
  96. {
  97. if (append!=0) Form1->Edit1->Clear();
  98.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button9->Caption;
  99.  //单击9按钮
  100.  append=0;
  101. }
  102. //---------------------------------------------------------------------------
  103. void __fastcall TForm1::Button10Click(TObject *Sender)
  104. {
  105. if (append!=0) Form1->Edit1->Clear();
  106.  Form1->Edit1->Text=Form1->Edit1->Text+Form1->Button10->Caption;
  107.  //单击0按钮
  108.  append=0;
  109. }
  110. //---------------------------------------------------------------------------
  111. void __fastcall TForm1::Button13Click(TObject *Sender)
  112. {
  113. flag=1;
  114. //设置加法标志
  115. if (Form1->Edit1->Text!="")
  116. temp1=StrToFloat(Form1->Edit1->Text);
  117. //为变量temp1赋值
  118. //Form1->Edit1->Clear();
  119. //清空文本框
  120. append=1;
  121. }
  122. //---------------------------------------------------------------------------
  123. void __fastcall TForm1::Button14Click(TObject *Sender)
  124. {
  125. flag=2;
  126. //设置减法标志
  127. if (Form1->Edit1->Text!="")
  128. temp1=StrToFloat(Form1->Edit1->Text);
  129. //为变量temp1赋值
  130. //Form1->Edit1->Clear();
  131. //清空文本框
  132. append=1;
  133. }
  134. //---------------------------------------------------------------------------
  135. void __fastcall TForm1::Button15Click(TObject *Sender)
  136. {
  137. flag=3;
  138. //设置乘法标志变量值
  139. if (Form1->Edit1->Text!="")
  140. temp1=StrToFloat(Form1->Edit1->Text);
  141. //为变量temp1赋值
  142. //Form1->Edit1->Clear();
  143. //清空文本框
  144. append=1;
  145. }
  146. //---------------------------------------------------------------------------
  147. void __fastcall TForm1::Button16Click(TObject *Sender)
  148. {
  149. flag=4;
  150. //设置除法标志
  151. if (Form1->Edit1->Text!="")
  152. temp1=StrToFloat(Form1->Edit1->Text);
  153. //为变量temp1赋值
  154. //Form1->Edit1->Clear();
  155. //清空文本框
  156. append=1;
  157. }
  158. //---------------------------------------------------------------------------
  159. void __fastcall TForm1::Button11Click(TObject *Sender)
  160. {
  161.  switch (flag)
  162.  {
  163.      case 1: temp2=StrToFloat(Edit1->Text)+StrToFloat(temp1);
  164.              //进行加法运算
  165.              break;
  166.      case 2: temp2=StrToFloat(temp1)-StrToFloat(Edit1->Text);
  167.              //进行减法运算
  168.              break;
  169.      case 3: temp2=StrToFloat(Edit1->Text)*StrToFloat(temp1);
  170.              //进行乘法运算
  171.              break;
  172.      case 4: temp2=StrToFloat(temp1)/StrToFloat(Edit1->Text);
  173.              //进行除法运算
  174.  }
  175.  Edit1->Text=FloatToStr(temp2);
  176.  //显示运算结果
  177.  append=1;
  178. }
  179. //---------------------------------------------------------------------------
  180. void __fastcall TForm1::Button12Click(TObject *Sender)
  181. {
  182.  Form1->Edit1->Clear();
  183.  //清除文本框中的内容
  184.  temp1=0;
  185.  temp2=0;
  186.  flag=0;
  187.  //变量赋初值
  188. }
  189. //---------------------------------------------------------------------------