用c语言编写的计算器源代码_第1页
用c语言编写的计算器源代码_第2页
用c语言编写的计算器源代码_第3页
用c语言编写的计算器源代码_第4页
用c语言编写的计算器源代码_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、可编辑作品:科学计算器 作者:欧宗龙编写环境:vc+6.0语言:c#include stdafx.h#include #include #include #include resource.h#include MainDlg.h#include #include #define PI 3.141593BOOL A_Op=FALSE;BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) switch(uMsg) HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDia

2、log); HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose); return FALSE;BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam) return TRUE;void TrimNumber(char a)/判断并删除小数点后无用的零for(unsigned i=0;i=i;j-)if(aj=0)aj=0;else if(aj=.)aj=0;else break;double Operate(

3、char Operator,double n1,double n2) /判断符号,进行相应的运算 if(Operator=0)if(Operator=+)n2+=n1;if(Operator=-)n2=n1-n2;if(Operator=*)n2*=n1;if(Operator=/)n2=n1/n2;if(Operator=)n2=pow(n1,n2);returnn2;/void IntBinary(char a,int n) if(n1)IntBinary(a,n/2); sprintf(a,%s%i,a,n%2);void decimal(char a,double m) if(m0.0

4、00001) m=m*2; sprintf(a,%s%d,a,(long)m); decimal(a,m-(long)m); void Binary(char a,double Num)char DecP256=;double x,y;double *iptr=&y;x=modf(Num,iptr);decimal(DecP,x);IntBinary(a,(int)y);strcat(a,.);strcat(a,DecP);/void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)static DELTIMES=

5、0;static char str256;static char Operator=0;static double RNum3; switch(id) case IDC_BUTTONN1:/数字1if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,1); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONN2:/数字2if(A_Op)Se

6、tDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,2); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONN3:/数字3if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,3); SetDlgItemText(

7、hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONN4:/数字4if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,4); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONN5:/数字5if(A_Op)SetDlgItemText(hwnd,IDC_ED

8、IT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,5); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONN6:/数字6if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,6); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1

9、=atof(str);A_Op=FALSE;break;case IDC_BUTTONN7:/数字7if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,7); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONN8:/数字8if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(

10、hwnd,IDC_EDIT,str,sizeof(str);strcat(str,8); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONN9:/数字9if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,9); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;br

11、eak;case IDC_BUTTONN0:/数字0if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);strcat(str,0); SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE;break;case IDC_BUTTONDEL:/小数点.delif(A_Op)SetDlgItemText(hwnd,IDC_EDIT,NULL);GetDlgItemText(hwnd,IDC_EDIT,str,s

12、izeof(str);if(DELTIMES=0) strcat(str,.);DELTIMES+; SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=FALSE;break;case IDC_BUTTONADD: /加法运算RNum1=atof(str);RNum0=RNum1;RNum1=RNum2;RNum2=Operate(Operator,RNum1,RNum0);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator=+;DELTIMES=0;A_O

13、p=TRUE;break;case IDC_BUTTONSUB: /减法运算RNum1=atof(str);RNum0=RNum1;RNum1=RNum2;RNum2=Operate(Operator,RNum1,RNum0);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);DELTIMES=0;A_Op=TRUE;Operator=-;break;case IDC_BUTTONMUL: /乘法运算RNum1=atof(str);RNum0=RNum1;RNum1=RNum2;RNum2=Opera

14、te(Operator,RNum1,RNum0);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator=*;DELTIMES=0;A_Op=TRUE;break;case IDC_BUTTONDIV: /除法运算RNum1=atof(str);RNum0=RNum1;RNum1=RNum2;RNum2=Operate(Operator,RNum1,RNum0);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_ED

15、IT,str);Operator=/;DELTIMES=0;A_Op=TRUE;break;case IDC_BUTTONXY:/x的y次方GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum1=atof(str);RNum0=RNum1;RNum1=RNum2;RNum2=Operate(Operator,RNum1,RNum0);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator=;DELTIMES=0;break;case IDC_B

16、UTTONPI: /圆周率PI,弧度GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);if(atof(str)!=0)RNum2=atof(str)*PI;sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);elsesprintf(str,%f,PI);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONSQRT: /开根号GetDlgItemText(hwnd,IDC_EDIT,str

17、,sizeof(str);RNum2=sqrt(atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONSIN: /三角函数sin函数GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=sin(atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;b

18、reak;case IDC_BUTTONCOS:/三角函数cos函数GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=cos(atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONTAN:/三角函数tan函数GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=tan(atof(str);sprintf(str,%f,RNum

19、2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONSQ: /平方GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=atof(str)*atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONCUBE:/三次方GetDlgItemText(hwnd,IDC_ED

20、IT,str,sizeof(str);RNum2=atof(str)*atof(str)*atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONEX:/e的x次方GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=exp(atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,s

21、tr);A_Op=TRUE;break;case IDC_BUTTON10X:/10的x次方GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=pow(10,atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONLN: /ln x GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=log(atof(str);sprintf(

22、str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONLOG10: /log10 GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str);RNum2=log10(atof(str);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;break;case IDC_BUTTONBINARY: /十进制转换为二进制 char a256=;GetDlgItemText(hwnd,IDC_EDIT,str,siz

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论