| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1270 人关注过本帖, 1 人收藏
标题:基于图形化处理的C计算器 分享!
取消只看楼主 加入收藏
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
结帖率:89.13%
收藏(1)
 问题点数:0 回复次数:4 
基于图形化处理的C计算器 分享!
请在TC下运行。
程序代码:
#include <stdlib.h>
#include <math.h>
#include <graphics.h>
#include <stdio.h>
#include <process.h>
#define EXCAPE 27
#define ENTER 13
main(){
  int press,i,x,y,x1,y1,ch_z=0;
  int dian=0;
  char ch='0';   /*input + - * /  */
  char emp[80],sum[80],*e,*s;
  double yuan=0.000000000000;
  void init(void);
  void clear_z(char *u);
  double strtoflt(char *p);
  int getkey();
  int gd=DETECT, gm;
  initgraph(&gd, &gm, "");
  e=emp;
  s=sum;
  init();
  x = (getmaxx() / 2) - 120;
  y = (getmaxy() / 2) - 150;
  x1 = (getmaxx() / 2) + 120;
  y1 = (getmaxy() / 2) + 150;
  while(1){
    press = getkey();
    switch(press){
      case EXCAPE:
    exit(0);
      case 47:
    bar (x + 10, y + 80 + 10, x + 60 - 10, y + 80 + 60 - 10);
    delay(8000);
    init();
    if (ch!='0'){
      switch(ch){
        case '/':
          if (strtoflt(emp)==0.0){
        ch='0';
        ch_z=0;
        dian=0;
        emp[0]='\0';
        sum[0]='\0';
        e=emp;
        s=sum;
        outtextxy(x+30,y+40,"error!!!!!");
        break;
          }
          yuan = strtoflt(sum) / strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          break;
        case '*':
          yuan = strtoflt(sum) * strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          break;
        case '+':
          yuan = strtoflt(sum) + strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          break;
        case '-':
          if (strtoflt(sum)>=strtoflt(emp)){
        yuan = strtoflt(sum) - strtoflt(emp);
        sprintf(sum,"%0.10f",yuan);
          }
          else{
        yuan=strtoflt(emp)-strtoflt(sum);
        sprintf(sum,"-%0.10f",yuan);
          }
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
      }
    }
        else{
      if (ch_z==0){
        outtextxy(x+30,y+40,emp);
        stpcpy(sum,emp);

      }
      else{
        outtextxy(x+30,y+40,sum);

      }
    }
    ch='/';
    ch_z=0;
    emp[0]='\0';
    e=emp;
    dian=0;
    break;
      case 42:
    bar (x + 60 + 10, y + 80 + 10, x + 60 * 2 - 10, y + 80 + 60 - 10);
    delay(8000);
    init();
        if (ch!='0'){
      switch(ch){
        case '/':
          yuan = strtoflt(sum) / strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '*':
          yuan = strtoflt(sum) * strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '+':
          yuan = strtoflt(sum) + strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '-':
          if (strtoflt(sum)>=strtoflt(emp)){
        yuan = strtoflt(sum) - strtoflt(emp);
        sprintf(sum,"%0.10f",yuan);
          }
          else{
        yuan=strtoflt(emp)-strtoflt(sum);
        sprintf(sum,"-%0.10f",yuan);
          }
              clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
      }
    }
        else{
      if (ch_z==0){
        outtextxy(x+30,y+40,emp);
        stpcpy(sum,emp);
        e=emp;
      }
      else
        outtextxy(x+30,y+40,sum);
    }
    ch='*';
    ch_z=0;
        dian=0;
    break;
      case 45:
    bar (x + 60 * 2 + 10, y + 80 + 10, x + 60 * 3 - 10, y + 80 + 60 - 10);
    delay(8000);
    init();
        if (ch!='0'){
      switch(ch){
        case '/':
          yuan = strtoflt(sum) / strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '*':
          yuan = strtoflt(sum) * strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '+':
          yuan = strtoflt(sum) + strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '-':
          if (strtoflt(sum)>=strtoflt(emp)){
        yuan = strtoflt(sum) - strtoflt(emp);
        sprintf(sum,"%0.10f",yuan);
          }
          else{
        yuan=strtoflt(emp)-strtoflt(sum);
        sprintf(sum,"-%0.10f",yuan);
          }
              clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
      }
    }
        else{
      if (ch_z==0){
        outtextxy(x+30,y+40,emp);
        stpcpy(sum,emp);
        e=emp;
      }
      else
        outtextxy(x+30,y+40,sum);
    }
    ch='-';
    ch_z=0;
        dian=0;
    break;
      case 43:
    bar (x + 60 * 3 + 10, y + 80 + 10, x + 60 * 4 - 10, y + 80 + 60 - 10);
    delay(8000);
    init();
        if (ch!='0'){
      switch(ch){
        case '/':
          yuan = strtoflt(sum) / strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '*':
          yuan = strtoflt(sum) * strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '+':
          yuan = strtoflt(sum) + strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
          clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
        case '-':
          if (strtoflt(sum)>=strtoflt(emp)){
        yuan = strtoflt(sum) - strtoflt(emp);
        sprintf(sum,"%0.10f",yuan);
          }
          else{
        yuan=strtoflt(emp)-strtoflt(sum);
        sprintf(sum,"-%0.10f",yuan);
          }
              clear_z(sum);
          outtextxy(x+30,y+40,sum);
          emp[0]='\0';
          e=emp;
          break;
      }
    }
        else{
      if (ch_z==0){
        outtextxy(x+30,y+40,emp);
        stpcpy(sum,emp);
        e=emp;
      }
      else
        outtextxy(x+30,y+40,sum);
    }
    ch='+';
    ch_z=0;
        dian=0;
    break;
      case 49:
    bar (x + 10, y + 80 + 53 + 10, x + 60 - 10, y + 80 + 53 * 2 - 4);
    delay(8000);
    init();
    for (i=0;i<=79;i++){
      if (emp[i]=='\0')
        break;
    }
    if (ch_z==0){
      *e='1';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 50:
    bar (x + 60 + 10, y + 80 + 53 + 10, x + 60 * 2 - 10, y + 80 + 53 * 2 - 4);
    delay(8000);
    init();
        for (i=0;i<=79;i++){
      if (emp[i]=='\0')
        break;
    }
        if (ch_z==0){
      *e='2';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 51:
    bar (x + 60 * 2 + 10, y + 80 + 53 + 10, x + 60 * 3 - 10, y + 80 + 53 * 2 - 4);
    delay(8000);
    init();
        for (i=0;i<=79;i++){
      if (emp[i]=='\0')
        break;
    }
        if (ch_z==0){
      *e='3';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case ENTER:
    bar (x + 60 * 3 + 10, y + 80 + 53 + 10, x + 60 * 4 - 10, y + 80 + 53 * 2 - 4);
    delay(8000);
    init();
      if (ch!='0'){
        switch(ch){
          case '/':
        yuan = strtoflt(sum) / strtoflt(emp);
        sprintf(sum,"%0.10f",yuan);
        clear_z(sum);
        outtextxy(x+30,y+40,sum);
        emp[0]='\0';
        e=emp;
        break;
          case '*':
        yuan = strtoflt(sum) * strtoflt(emp);
        sprintf(sum,"%0.10f",yuan);
        clear_z(sum);
        outtextxy(x+30,y+40,sum);
        emp[0]='\0';
        e=emp;
        break;
          case '+':
        yuan = strtoflt(sum) + strtoflt(emp);
        sprintf(sum,"%0.10f",yuan);
        clear_z(sum);
        outtextxy(x+30,y+40,sum);
        emp[0]='\0';
        e=emp;
        break;
          case '-':
        if (strtoflt(sum)>=strtoflt(emp)){
          yuan = strtoflt(sum) - strtoflt(emp);
          sprintf(sum,"%0.10f",yuan);
        }
        else{
          yuan=strtoflt(emp)-strtoflt(sum);
          sprintf(sum,"-%0.10f",yuan);
        }
        clear_z(sum);
        outtextxy(x+30,y+40,sum);
        emp[0]='\0';
        e=emp;
        break;
        }
      }
      else{
        if (ch_z==0){
          outtextxy(x+30,y+40,emp);
          stpcpy(sum,emp);
          e=emp;
        }
        else{
          outtextxy(x+30,y+40,sum);
        }
      }
    ch='0';
    ch_z=1;
        dian=0;
    break;
      case 52:
    bar (x + 10, y + 80 + 53 * 2 + 10, x + 60 - 10, y + 80 + 53 * 3 - 4);
    delay(8000);
    init();
    if (ch_z==0){
      *e='4';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 53:
    bar (x + 60 + 10, y + 80 + 53 * 2 + 10, x + 60 * 2 - 10, y + 80 + 53 * 3 - 4);
    delay(8000);
    init();
        if (ch_z==0){
      *e='5';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 54:
    bar (x + 60 * 2 +10, y + 80 + 53 * 2 + 10, x + 60 * 3 - 10, y + 80 + 53 * 3 - 4);
    delay(8000);
    init();
        if (ch_z==0){
      *e='6';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 46:
    bar (x + 60 * 3 + 10, y + 80 + 53 * 2 + 10, x + 60 * 4 - 10, y + 80 + 53 * 3 - 4);
    delay(8000);
    init();
    if (dian==0){
      if (ch_z==0){
        *e='.';e++;*e='\0';
        outtextxy(x+30,y+40,emp);
      }
      else{
        outtextxy(x+30,y+40,sum);
      }
    }
    else{
      if (ch_z==0)
        outtextxy(x+30,y+40,emp);
      else
        outtextxy(x+30,y+40,sum);
    }
    dian=1;
    break;
      case 55:
    bar (x + 10, y + 80 + 53 * 3 + 10, x + 60 - 10, y + 80 + 53 * 4 - 4);
    delay(8000);
    init();
        if (ch_z==0){
      *e='7';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 56:
    bar (x + 60 + 10, y + 80 + 53 * 3 + 10, x + 60 * 2 -10, y + 80 + 53 * 4 - 4);
    delay(8000);
    init();
        if (ch_z==0){
      *e='8';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 57:
    bar (x + 60 * 2 + 10, y + 80 + 53 * 3 + 10, x + 60 * 3 - 10, y + 80 + 53 * 4 - 4);
    delay(8000);
    init();
    if (ch_z==0){
      *e='9';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 48:
    bar (x + 60 * 3 + 10, y + 80 + 53 * 3 + 10, x + 60 * 4 - 10, y + 80 + 53 * 4 - 4);
    delay(8000);
    init();
    if (ch_z==0){
      *e='0';e++;*e='\0';
      outtextxy(x+30,y+40,emp);
    }
    else{
      outtextxy(x+30,y+40,sum);
    }
    break;
      case 32:
    emp[0]='\0';
    sum[0]='\0';
    e=emp;
    s=sum;
    ch='0';
    ch_z=0;
    dian=0;
    init();
    break;
      case 8:
    delay(8000);
    for(i=0;i<=79;i++){
      if (emp[i]=='\0')
        break;
    }
    if (i==0)
      break;
    if (i!=79&&i!=0){
      i--;
      emp[i]='\0';
      e=&emp[i];
    }
    init();
    outtextxy(x+30,y+40,emp);
    break;
    }
  }
}
/*---------------------------------------------------------------------*/
void init(void){
  int x, y, x1, y1, i, j;
  char emp;
  x = (getmaxx() / 2) - 120;
  y = (getmaxy() / 2) - 150;
  x1 = (getmaxx() / 2) + 120;
  y1 = (getmaxy() / 2) + 150;
  cleardevice();
  setbkcolor(3);
  setfillstyle(1, 15);
  setcolor(15);
  settextstyle(1,0,1);
  rectangle (x, y, x1, y1);
  rectangle (x - 7, y - 7, x1 + 7, y1 + 7);
  rectangle (x + 10, y + 10, x1 - 10, y + 80 - 10);
  line (x, y + 80, x1, y + 80);
  y = y + 80;
  for (j = 1; j <= 4; j++){
    x = (getmaxx() / 2) - 120;
    for (i = 1; i <= 4; i++){
      /* bar (x + 10, y + 10, x + 60 - 10, y + 60 - 10);*/
      rectangle(x + 10, y + 10, x + 60 - 10, y + 60 - 10);
      if (j == 1){
    if (i == 1)
      outtextxy(x + 20, y + 20, "/");
    if (i == 2)
      outtextxy(x + 25, y + 20, "*");
    if (i == 3)
      outtextxy(x + 27, y + 20, "-");
    if (i == 4)
      outtextxy(x + 25, y + 20, "+");
      }
      if (j == 2){
    if (i == 1)
      outtextxy(x + 25, y + 20, "1");
    if (i == 2)
      outtextxy(x + 25, y + 20, "2");
    if (i == 3)
      outtextxy(x + 25, y + 20, "3");
    if (i == 4)
      outtextxy(x + 25, y + 20, "=");
      }
      if (j == 3){
    if (i == 1)
      outtextxy(x + 25, y + 20, "4");
    if (i == 2)
      outtextxy(x + 25, y + 20, "5");
    if (i == 3)
      outtextxy(x + 25, y + 20, "6");
    if (i == 4)
      outtextxy(x + 25, y + 20, ".");
      }
      if (j == 4){
    if (i == 1)
      outtextxy(x + 25, y + 20, "7");
    if (i == 2)
      outtextxy(x + 25, y + 20, "8");
    if (i == 3)
      outtextxy(x + 25, y + 20, "9");
    if (i == 4)
      outtextxy(x + 25, y + 20, "0");
      }
      x = x + 60;
    }
    y = y + 53;
  }
}
/*---------------------------------------------------------------------*/
int getkey(){
  char lowbyte;
  int press;
  while(bioskey(1)==0);
  press = bioskey(0);
  press = press&0xff? press&0xff: press>>8;

  return(press);

}
double strtoflt(char *p)
{
  double rtl=0.000000000000;
  double pnt=0.000000000000;
  double t = 10;
  int ispoint = 0;
  while (*p!='\0'||*p!='.'){
    if(*p<'0'||*p>'9')
      break;
    rtl*=10;
    rtl+=*p-'0';
    p++;
  }
  if (*p=='.'){
    ispoint=1;
    p++;
  }
  while(ispoint&&*p!='\0'){
    pnt+=(double)(*p-'0')/t;
    t*=10;
    p++;
  }
  rtl+=pnt;
  return (rtl);
}
/*-----------------------------------------------------------------------*/
void clear_z(char u[]){
  int i;
  for(i=strlen(u)-1;i>=0;i--){
    if (u[i]!='0')
      break;
  }
  if (u[i]=='.'){
    u[i]='\0';
  }
  else{
    i++;
    u[i]='\0';
  }
}

搜索更多相关主题的帖子: 计算器 图形 
2012-07-18 10:34
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
麻烦版主给我录个视频发我邮箱吧。这样我看的更直观一些。谢谢你了。

我的电脑上有WIN—TC、VC6和code::blocks

下面是一个很不错的录屏工具提供给你,我封装的,可惜杀软会误杀。
ps:我没有挑衅别人的想法,你们误会误会了,我邮箱:691464072@  网上视频找了不少,都找不到。

Screen2Exe.zip (315.44 KB)

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2012-07-18 11:37
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2012-07-18 12:02
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
以下是引用hellovfp在2012-7-18 12:09:49的发言:

看了一下你的视频,真是汗,打开dsw文件,不是打开rc文件,你可以这样办:
运行VC,然后打开资源浏览器,将test目录下,那个唯一的dsw文件拖放到VC中,既可打开整个工程。然后就可以编译了。

按你这个方法,成功了,谢谢!

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2012-07-18 12:23
yuma
Rank: 12Rank: 12Rank: 12
来 自:银河系
等 级:贵宾
威 望:37
帖 子:1934
专家分:3012
注 册:2009-12-22
收藏
得分:0 
回复 5楼 hellovfp
这个工程为何我用VC6就无法编译,用code blocks就能编译。

而那个test工程,VC6和code blocks都能编译呢?

心生万象,万象皆程序!
本人计算机知识网:http://bbs.为防伸手党,本站已停止会员注册。
2012-07-18 13:41
快速回复:基于图形化处理的C计算器 分享!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031752 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved