C语言写的仿WINDOWS 界面计算器源码

资讯 驱动中国 若水 2,352 次阅读 0 条评论
分享 Q

case 26:   /*清除当前显示的值(Del键)*/
                        Resetbuf();

 

num1=0;
                        strcpy(txtscreen.caption,strbuf);
                        TextBox(txtscreen);
                        break;
                    case 27:   /*清除所有的值,包括存储的,已经运算了的(ESC键)*/
                        Resetbuf();
                        num1=num2=0;
                        ctnflag=FALSE;
                        operatoror=0;
                        runflag=FALSE;
                        errorflag=FALSE;

                        strcpy(txtscreen.caption,"0.");
                        TextBox(txtscreen);

                        break;
                    case 0:
                        Unload();
                        break;
             }
         if(errorflag==FALSE)
             {  if(atof(txtscreen.caption)==0)
                        strcpy(txtscreen.caption,"0");
                    if(strchr(txtscreen.caption,'.')==NULL)
                        strcat(txtscreen.caption,".");
             }
         TextBox(txtscreen); /*显示txtscreen结构变量的值*/
    }

void DoubleRun() /*四则运算*/
    {  switch(operatoror)
             {      case 13: num2+=num1;break;  /*加*/
                    case 14: num2-=num1;break; /*减*/
                    case 15: num2*=num1;break; /*乘*/
                    case 16: if(num1==0)     /*除*/
                                         errorflag=TRUE;
                                     else
                                         num2/=num1;#p#分页标题#e#
                                     break;
             }
         if(errorflag)
             strcpy(txtscreen.caption,"Can't divide by zero!");
         else
             sprintf(txtscreen.caption,"%G",num2);
    }

void SingleRun(int key) /*单运算*/
    {  switch(key)
             {  case 17:  /*求开方*/
                        if(num1<0)
                             errorflag=TRUE;
                        else
                             num1=sqrt(num1);
                        break;
                    case 18:  /*求百分比*/
                             num1/=100;
                        break;
                    case 19: /*求倒数*/
                        if(num1==0)
                             errorflag=TRUE;
                        else
                             num1=1/num1;
                        break;
                }
         if(errorflag==TRUE)
             if(num1<0)
                 strcpy(txtscreen.caption,"Can't blower than zero!");
             else
                 strcpy(txtscreen.caption,"Can't equal to zero!");
         else
             sprintf(txtscreen.caption,"%G",num1);
    }

void StoreSet(int key)  /*记忆存储操作*/
   {  switch(key)
             {  case 21:   /*保存清除*/
                        store=0;
                        lblstore.caption[0]=0;
                        break;
                case 22:  /*取出保存的值*/
                        num1=store;
                        sprintf(txtscreen.caption,"%G",store);#p#分页标题#e#
                        runflag=FALSE;
                        if(ctnflag==FALSE) operatoror=0;
                        break;
                case 23:  /*保存当前数字*/
                        store=num1;
                        strcpy(lblstore.caption,"M");
                        break;
               case 24:  /*保存值与当前数字相加*/
                        store+=num1;
                        strcpy(lblstore.caption,"M");
                        break;
            }
         Label(lblstore);
    }

版权声明:本文由驱动中国整理发布,转载需注明出处与原文链接。如有疑问请联系 editor@qudong.com
本文价值 成为第一个评分的人
登录后为本文打分
网友评论0 条评论
正在回复 的评论取消
评论加载中…
🔐

登录后参与互动

评论、点赞均可赚积分
连续签到、邀请好友也有奖励 🎁

电脑端: 微信扫码登录 微信内: 一键登录

微信扫一扫

打开微信「扫一扫」,分享本文到朋友圈或好友