用c语言编写的计算器源代码.doc
《用c语言编写的计算器源代码.doc》由会员分享,可在线阅读,更多相关《用c语言编写的计算器源代码.doc(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、如有侵权,请联系网站删除,仅供学习与交流用c语言编写的计算器源代码【精品文档】第 10 页作品:科学计算器 作者:欧宗龙编写环境: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) HAND
2、LE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog); 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;el
3、se if(aj=.)aj=0;else break;double Operate(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
4、%2);void decimal(char a,double m) if(m0.000001) 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 hw
5、ndCtl, UINT codeNotify)static DELTIMES=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
6、;break;case IDC_BUTTONN2:/数字2if(A_Op)SetDlgItemText(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,siz
7、eof(str);strcat(str,3); SetDlgItemText(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
8、:/数字5if(A_Op)SetDlgItemText(hwnd,IDC_EDIT,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);
9、SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=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)SetDlgItemT
10、ext(hwnd,IDC_EDIT,NULL);GetDlgItemText(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_
11、EDIT,str);RNum1=atof(str);A_Op=FALSE;break;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,N
12、ULL);GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(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,
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 编写 计算器 源代码
限制150内