c简单计算器代码Word文档下载推荐.docx
《c简单计算器代码Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《c简单计算器代码Word文档下载推荐.docx(20页珍藏版)》请在冰点文库上搜索。
BOOLMain_OnInitDialog(HWNDhwnd,HWNDhwndFocus,LPARAMlParam)
returnTRUE;
voidMain_OnCommand(HWNDhwnd,intid,HWNDhwndCtl,UINTcodeNotify)
switch(id)
caseIDC_OK:
{
//inta=1,i,b,l;
//doublen1,n2,n3;
//intc=3;
TCHARdo_make;
doublea,b,c;
TCHARnum1[300],numa[10],numb[10];
GetDlgItemText(hwnd,IDC_TEXT,num1,sizeof(num));
//MessageBox(hwnd,num1,"
开始读出"
MB_OK);
intlen=strlen(num1);
inti,k=0,n=0,m=0;
TCHARcm[2];
intz=10;
for(i=0;
i<
=len;
i++){
if(m==0){
if(isdigit(num1[i])||num[i]=='
.'
||i==0){
numa[k++]=num1[i];
sprintf(cm,"
%c"
num[i]);
}else{
do_make=num1[i];
m=1;
}
numb[n++]=num1[i];
switch(do_make){
case'
+'
:
{
a=atof(numa);
b=atof(numb);
c=a+b;
gcvt(c,z,numa);
SetDlgItemText(hwnd,IDC_TEXT,numa);
}
break;
case'
-'
c=a-b;
*'
c=a*b;
/'
c=a/b;
#'
ltoa(a,numa,b);
$'
{
a=atoi(numa);
b=atoi(numb);
c=pow(a,b);
}
break;
&
'
inta,b;
c=a&
b;
itoa(c,numa,10);
|'
c=a|b;
^'
c=a^b;
~'
c=pow(a,1.0/b);
}
/*
n1=atof(num1);
n2=atof(num2);
l=strlen(num1);
b=0;
l;
if(i>
=1){
if(strcmp(num1+i,"
."
)==0){
b=1;
if(!
isdigit(num1[i])){
if(b==1)
a=0;
if(a){
b=0;
if(strcmp(num2+i,"
isdigit(num2[i])){
if(!
a){
MessageBox(hwnd,TEXT("
你输入了非法数字!
"
),TEXT("
错误"
),MB_OK|MB_ICONSTOP);
else{
n3=n1+n2;
//ltoa()
//ltoa(n3,num3,16);
//wsprintf(num3,"
%f"
n3);
//MessageBox(hwnd,num3,num3,MB_OK);
gcvt(n3,c,num3);
SetDlgItemText(hwnd,IDC_NUM3,num3);
}*/
break;
caseIDC_NUM0:
GetDlgItemText(hwnd,IDC_TEXT,num,sizeof(num));
wsprintf(num,"
%s0"
num);
SetDlgItemText(hwnd,IDC_TEXT,num);
break;
caseIDC_NUM1:
%s1"
caseIDC_NUM2:
%s2"
caseIDC_NUM3:
%s3"
caseIDC_NUM4:
%s4"
caseIDC_NUM5:
%s5"
caseIDC_NUM6:
%s6"
caseIDC_NUM7:
%s7"
caseIDC_NUM8:
%s8"
caseIDC_NUM9:
%s9"
caseIDC_SUM:
inti=strlen(num);
if(num[i-1]=='
){
break;
%s+"
caseIDC_JIAN:
%s-"
caseIDC_SHEN:
%s*"
caseIDC_CHU:
%s/"
caseIDC_XIAO:
inti=strlen(num),j;
inty=0;
||!
isdigit(num[i-1])){
for(j=0;
j<
i;
j++){
if(num[j]=='
)
y=1;
if(num[j]!
='
!
isdigit(num[j]))
y=0;
if(y){
%s."
caseIDC_CLSE:
SetDlgItemText(hwnd,IDC_TEXT,"
);
caseIDC_BACK:
{
GetDlgItemText(hwnd,IDC_TEXT,num,sizeof(num));
inti,len;
len=strlen(num);
num[len-1]='
\0'
;
SetDlgItemText(hwnd,IDC_TEXT,num);
caseIDC_CHANGE:
%s#"
caseIDC_PING:
%s$"
caseIDC_BING:
%s&
caseIDC_HUO:
%s|"
caseIDC_YI:
%s^"
caseIDC_GENG:
%s~"
caseIDC_BAS:
doublen;
n=atof(num);
n=abs(n);
gcvt(n,10,num);
caseIDC_XIANG:
if(n<
=0){
n=n*(-1.0);
caseIDC_SIN:
n=sin(n*(3.1415926/180.0));
gcvt(n,2,num);
caseIDC_COS:
n=cos(n*(3.1415926/180.0));
caseIDC_TAN:
n=tan(n*(3.1415926/180.0));
caseIDC_ASIN:
n=asin(n)*(180.0/3.1415926);
caseIDC_ACOS:
n=acos(n)*(180.0/3.1415926);
caseIDC_ATAN:
GetDlgItemText(hwnd,IDC_TEXT,num,sizeof(