#include<graphics.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
#include<math.h>
#define F1 59
#define F2 60
#define F3 61
#define F4 62
#define F9 67
#define ESC 27
#define BK_SPACE 8
#define ENTER 13
#define EQ 61
typedef struct node{
double number;
struct node*next;
}NODE;
void screen(void);
void recover(void);
char plus(double a,char c[]);
char chengfa(double a,char c[]);
char minus(double a,char c[]);
char chufa(double a,char c[]);
char others(char a[],char b[]);
char store(char a[],char b[]);
void main()
{
screen();
}
char store(char a[],char b[]){ /*单个储存功能函数*/
double c,t,str1[20];
switch(a[0]){
case 'z':
b[0]='\0'; /*mr显示*/
recover();
moveto(416,140);
outtext(str1);
strcpy(b,str1);
break;
case 'c':
b[0]='\0'; /*mc清除出储存的东西*/
recover();
moveto(416,140);
str1[0]='\0';
setfillstyle(1,7);
bar(206,198,229,213);
break;
case 'x':
a[0]='\0'; /*ms储存*/
recover();
moveto(416,140);
c=atof(b);
b[0]='\0';
recover();
gcvt(c,10,str1);
outtextxy(223,211,"M");
break;
case 'v':
b[strlen(b)-1]='\0'; /*m+与屏幕上的数相加*/
recover();
moveto(416,140);
t=atof(b);
b[0]='\0';
c=c+t;
gcvt(c,10,b);
outtext(b);
break;
}
}
char others(char a[],char b[]){ /*其他计算函数*/
double num,num1,t;
char str1[32];
if(a[0]==ESC){ /*ESC*/
recover();
b[0]='\0';
moveto(416,140);
}
if(a[0]==F9){
b[strlen(b)-1]='\0';
num=atof(b);
num=-num;
b[0]='\0';
gcvt(num,10,b);
recover();
moveto(416,140);
outtext(b);
}
if(a[0]==BK_SPACE){ /*退格健*/
recover();
t=strlen(b);
b[t-2]='\0';
moveto(416,140);
outtext(b);
}
if(a[0]=='@') /*开方*/
{
b[strlen(b)-1]='\0';
num=atof(b);
recover();
moveto(416,140);
outtext(b);
num=sqrt(num);
gcvt(num,10,str1);
moveto(416,140);
b[0]='\0';
strncpy(b,str1,20);
recover();
outtext(b);
}
if(a[0]=='r'){ /*1/X*/
b[strlen(b)-1]='\0';
recover();
moveto(416,140);
outtext(b);
num=atof(b);
num=1/num;
gcvt(num,10,str1);
recover();
moveto(416,140);
b[0]='\0';
strncpy(b,str1,20);
recover();
outtext(b);
}
}
void recover(void){ /*清除文本内容函数*/
setfillstyle(1,15);
bar(205,123,425,144);
rectangle(205,123,425,144);
setfillstyle(1,15);
bar(426,123,430,144);
bar(200,123,204,144);
}
char chufa(double a,char c[]){ /*除法计算函数*/
char ch1[2];
double b;
c[0]='\0';
ch1[1]='\0';
while(1){
ch1[0]=getch();
if(ch1[0]=='q')
{c[0]='\0';break;}
outtext(ch1);
recover();
strcat(c,ch1);
moveto(416,140);
outtext(c);
others(ch1,c);
if(strlen(c)>20){break;}
if(ch1[0]==EQ){
c[strlen(c)-1]='\0';
b=atof(c);
c[0]='\0';
a=a/b;
gcvt(a,10,c);
moveto(416,140);
recover();
outtext(c);
c[0]='\0';
gcvt(a,10,c);
break;}
}
return c[32];
}
char minus(double a,char c[]){ /*减法计算函数*/
char ch1[2];
double b;
c[0]='\0';
ch1[1]='\0';
while(1){
ch1[0]=getch();
if(ch1[0]=='q')
{c[0]='\0';break;}
outtext(ch1);
recover();
strcat(c,ch1);
moveto(416,140);
outtext(c);
others(ch1,c);
if(strlen(c)>20){break;}
if(ch1[0]==EQ){
c[strlen(c)-1]='\0';
b=atof(c);
c[0]='\0';
a=a-b;
gcvt(a,10,c);
moveto(416,140);
recover();
outtext(c);
c[0]='\0';
gcvt(a,10,c);
break;}
}
return c[32];
}
char plus(double a,char c[]){ /*加法计算函数*/
char ch1[2];
double b;
c[0]='\0';
ch1[1]='\0';
while(1){
ch1[0]=getch();
if(ch1[0]=='q')
break;
outtext(ch1);
recover();
strcat(c,ch1);
moveto(416,140);
outtext(c);
others(ch1,c);
if(strlen(c)>20){break;}
if(ch1[0]==EQ){
c[strlen(c)-1]='\0';
b=atof(c);
c[0]='\0';
a=a+b;
gcvt(a,10,c);
moveto(416,140);
recover();
outtext(c);
c[0]='\0';
gcvt(a,10,c);
break;}
}
return c[32];
}
char chengfa(double a,char c[]){ /*乘法计算函数*/
char ch1[2];
double b;
c[0]='\0';
ch1[1]='\0';
while(1){
ch1[0]=getch();
if(ch1[0]=='q')
{c[0]='\0';break;}
outtext(ch1);
recover();
strcat(c,ch1);
moveto(416,140);
outtext(c);
others(ch1,c);
if(strlen(c)>20){break;}
if(ch1[0]==EQ){
c[strlen(c)-1]='\0';
b=atof(c);
c[0]='\0';
a=a*b;
gcvt(a,10,c);
moveto(416,140);
recover();
outtext(c);
c[0]='\0';
gcvt(a,10,c);
break;}
}
return c[32];
}
void screen(void){
FILE*fp;
NODE*head=NULL;
NODE*p,*pre,*pap,*o; /*计算器界面函数*/
int n=0;
int i,j,u,x=205,y=147;
int a,b,c,d;
double num,num1,t;
char op;
char str3[32];
char str2[32];
char str1[32];
char str[32];
char strcopy[21];
char ch[2];
int driver=DETECT;
int mode=0;
initgraph(&driver,&mode,"");
setlinestyle(0,0,3);
setcolor(1);
rectangle(199,101,431,331); /*边框*/
setfillstyle(1,15);
bar(200,100,430,330); /*背景*/
setfillstyle(1,1);
bar(200,100,430,117); /*蓝条*/
setcolor(15);
setfillstyle(1,4);
rectangle(413,102,427,115);
bar(413,102,427,115); /*关闭按钮*/
line(416,105,424,112); /* X */
line(424,105,416,112);
outtextxy(202,104,"07070318 guanhaitao");
setcolor(8);
setlinestyle(0,0,1);
setfillstyle(1,15);
bar(205,123,425,144);
rectangle(205,123,425,144);/*文本框*/
setfillstyle(1,7);
bar(205,172,235,189);
bar(245,172,275,189);
bar(235,197,295,214);
bar(300,197,360,214);
bar(365,197,425,214);
bar(205,197,230,214);
bar(285,172,425,189);
setcolor(1);
setlinestyle(0,0,2);
rectangle(205,172,235,189); /*s*/
rectangle(245,172,275,189); /*l*/
rectangle(205,197,230,214); /*短框*/
rectangle(285,172,425,189); /*长框*/
rectangle(235,197,295,214); /*bkspace*/
rectangle(300,197,360,214); /*CE*/
rectangle(365,197,425,214); /*C*/
for(i=0;i<4;i++){ /*ML MLD MLN MLR*/
setfillstyle(1,7);
bar(x,y,x+45,y+17);
rectangle(x,y,x+45,y+17);
x+=58;
}
a=205;b=222;c=235;d=239; /*Mc MR MS M+ 1234565.....*/
for(j=1;j<=4;j++){
for(i=1;i<=6;i++){
setcolor(1);
setfillstyle(1,7);
bar(a,b,c,d);
rectangle(a,b,c,d);
a+=38;
c+=38;
}
a=205;c=235;b+=25;d+=25;
}
setcolor(0);
outtextxy(237,203,"Bkspace"); /*字符*/
outtextxy(324,203,"CE");
outtextxy(394,203,"C");
outtextxy(258,178,"L");
outtextxy(218,178,"S");
outtextxy(221,152,"ML");
outtextxy(277,152,"MLD");
outtextxy(335,152,"MLN");
outtextxy(393,152,"MLR");
outtextxy(214,228,"MC");
outtextxy(214,253,"MR");
outtextxy(214,278,"MS");
outtextxy(214,301,"M+");
outtextxy(255,228,"7");
outtextxy(255,253,"4");
outtextxy(255,278,"1");
outtextxy(255,301,"0");
outtextxy(294,228,"8");
outtextxy(294,253,"5");
outtextxy(294,278,"2");
outtextxy(284,301,"+/-");
outtextxy(332,228,"9");
outtextxy(332,253,"6");
outtextxy(332,278,"3");
outtextxy(331,299,".");
outtextxy(369,228,"/");
outtextxy(369