资源预览内容
第1页 / 共13页
第2页 / 共13页
第3页 / 共13页
第4页 / 共13页
第5页 / 共13页
第6页 / 共13页
第7页 / 共13页
第8页 / 共13页
第9页 / 共13页
第10页 / 共13页
亲,该文档总共13页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
作品:科学计算器 作者:欧宗龙编写环境:VC+6.0 语言:c#include stdafx.h#include vstdio.h#include vwindows.h#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 IParam) switch(uMsg)HANDLE_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 IParam) 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(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=A) n2=pow(n1,n2);return n2;/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.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 hwndCtl, UINT codeNotify)static DELTIMES=0;static char str256;static char Operator=0;static double RNum3; switch(id)case IDC_BUTTONN1:/数 字 1 if(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_BUTT0NN2:数字 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_BUTT0NN3:数字 3if(A_Op) SetDlgItemText(hwnd,IDC_EDIT,NULL); GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str); strcat(str,3);SetDlgItemText(hwnd,IDC_EDIT,str); RNum1=atof(str);A_Op=FALSE; break;case IDC_BUTT0NN4:数字 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_BUTT0NN5:数字 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_BUTT0NN6:数字 6if(A_Op) SetDlgItemText(hwnd,IDC_EDIT,NULL); GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str); strcat(str,6);SetDlgItemText(hwnd,IDC_EDIT,str);RNum1=atof(str);A_Op=FALSE; break;case IDC_BUTT0NN7:数字 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_BUTT0NN8:数字 8if(A_Op)SetDlgItemText(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_BUTT0NN9:数字 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;break;case IDC_BUTTONNO:数字 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,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,IDC_EDIT,str);Operator=+;DELTIMES=0;A_Op=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=Operate(Operator,RNum1,RNum0);sprintf(str,%f,RNum2);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Op
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号