可以用鼠标操作的C语言计算器源码

合集下载

C++语言编程计算器源代码

C++语言编程计算器源代码

//计算器,函数#include <iostream>#include <string>#include <ctime>#include <conio.h>#include <cstdlib>#include <cmath>#include <vector>#include <cctype>using namespace std;double simple (string s);//简单运算bool check (char c);//检查是否为数值doublecou (double m,doublen,int c);//用于计算两个数的运算string cut (string str);//括号截取double senior (string str,double x);//高级函数计算double count (string st);//括号运算boolbr_l (char c);boolbr_r (char c);string al (string st);//特殊值与符号处理string abs_cut (string st);//绝对值处理intnum;string s;vector <double> b;//存储高级符号内值int main (){ cout<<"\n\t\t本软件由松哥独家制造\n\n"; while (true){ int i=0,j=0;num=0;string s1;b.clear ();cout<<"输入:"; cin>>s1;string s2(s1);if (s=="#") break;cout<<"输出:"<<s2<<"="<<count (s1)<<endl;} cout<<"\n\t\t感谢您的支持!!!!";}double simple (string st){ int i=0,j=0,k=0;vector <double> p;//存储读入的数字vector <int> q;//存储读入运算符while (st[i]!='\0'&&st[i]!='='){double sum=0;while (!check (st[i])) i++;while (check (st[i])){if (st[i]>64&&st[i]<91){sum=b[st[i]-65];i++;break;}if (st[i]!='.') sum=sum*10+(st[i++]-48);else {i++;double su=0,m=1;while (check (st[i])){m*=10.0;su=su*10+(st[i++]-48);}sum=sum+su/m;}}p.push_back (sum); }if (st[0]=='-') p[0]=-p[0];for (i=1;st[i]!='\0';i++){switch (st[i]){case '=':break;case '^': q.push_back (1);break;case '/': q.push_back (-3);break;case '*': q.push_back (3);break;case '+': q.push_back (4);break;case '-' :q.push_back (-4) ;break;default :if (!check (st[i])) {cout<<"含未知符号"<<st[i]<<"!\n"; return 0;}}}i=p.size (),j=q.size ();if (j==1) return cou (p[0],p[1],q[0]);else while (i!=1)for (int k=0;k<j;k++) {if (k==j-1&&abs (q[k])<abs (q[k-1])){p[k]=cou (p[k],p[k+1],q[k]); i--;j--; for (k;k<q.size ()-1;k++) {p[k+1]=p[k+2];q[k]=q[k+1];}p.pop_back ();q.pop_back ();break;}else if (abs (q[k])<=abs (q[k+1])) {p[k]=cou (p[k],p[k+1],q[k]); i--;j--;for (k;k<q.size ()-1;k++) {p[k+1]=p[k+2];q[k]=q[k+1];}p.pop_back ();q.pop_back ();if (j==1) break; } }return p[0];}bool check (char c){if (c>='0'&&c<='9'||c=='.'||c>64&&c<85) return true;else return false;}doublecou (double m,doublen,int c) {switch (c){case 1:return pow (m,n);case 3:return (m*n);case -3:return (m/n);case 4:return (m+n);case -4:return (m-n);default :cout<<c<<"无法计算!\n";} }string cut (string str){int i=0,m=0,n=0,r=0;string se;for (int j=0;j<str.size ();j++){if (br_l (str[j])) {m=j;i++;}if (br_r (str[j])) {n=j;if (n!=0) break;}}if (i==0) return str;if (m>0&&isalpha (str[m-1]))for (int k=m-1;;k--)if (k<0||!isalpha (str[k])) {k++;se=str.substr (k,m-k);int l=n-m+1;s=str.substr (m+1,l-2);b.push_back (senior (se,simple (s)));num++;l=n-k+1;str.replace (k,l,1,(char) (64+num)); returnstr;}int l=n-m+1;s=str.substr (m+1,l-2);b.push_back (simple (s));num++;str.replace (m,l,1,(char) (64+num)); returnstr;}double count (string st){ st=al (st);st=abs_cut (st);while (true){int r=0;st=cut (st);for (int i=0;i<st.size ();i++)if (br_r (st[i])) r++;if (r==0) break;}return simple (st);}boolbr_l (char c) {if (c=='('||c=='['||c=='{') return true;else return false;}boolbr_r (char c) {if (c==')'||c==']'||c=='}')return true;else return false;}string al (string st){inti,j=0;double m=0,n=1;for (i=0;i<st.size ();i++){if (st[i]=='e') {num++;st.replace (i,1,1,(char)(64+num));b.push_back (pow (2,1/log (2)));}if (st[i]=='p') {num++;st.replace (i,2,1,(char)(64+num));b.push_back (3.141593);}if (st[i]=='!'){j=i-1;while (j>0) {j--;if (st[j]=='.'){cout<<"只能计算整数的阶乘!!!\n";return "0";}if (st[j]<48||st[j]>57) {j++;break;}}for (int k=j;k<i;k++)m=m*10+(st[k]-48);for (m;m>1;m--) n*=m; num++;st.replace (j,i-j+1,1,(char)(64+num));b.push_back (n);}}i=st.find ("π");if (i<st.size ()) {num++;st.replace (i,2,1,(char)(64+num));b.push_back (acos (-1.0));}i=st.find ("∞");if (i<st.size ()) {num++;st.replace (i,3,1,(char)(64+num));b.push_back (DBL_MAX);}returnst;}stringabs_cut (string st){ inti;vector<int> m;for (i=0;i<st.size ();i++)if (st[i]=='|') m.push_back (i);i=m.size ()/2;if (i==0) return st;i--;string s=st.substr (m[i]+1,m[i+1]-m[i]-1);b.push_back (fabs (count (s)));num++;st.replace (m[i],m[i+1]-m[i]+1,1,(char) (64+num));if (i!=0) st=abs_cut (st);returnst;}double senior (string str,double x){ int i=0;string s[]={"acos","asin","atan","cos","cosh","sin", "sinh","tan","tanh","ln","log","no"};for (i;i<12;i++) if (str==s[i]) break;switch (i){case 0:return acos (x);case 1:return asin (x);case 2:return atan (x);case 3:return cos (x);case 4:return cosh (x);case 5:return sin (x);case 6:return sinh (x);case 7:return tan (x);case 8:return tanh (x);case 9:return log (x);case 10:return log10 (x);default :cout<<str<<"函数尚未收录\n"; return x;}}。

简单计算器c语言源码

简单计算器c语言源码

#include <stdio.h>#include <string.h>#include <ctype.h>#include <math.h>//expression evaluate#define iMUL 0#define iDIV 1#define iADD 2#define iSUB 3#define iCap 4//#define LtKH 5//#define RtKH 6#define MaxSize 100void iPush(float);float iPop();float StaOperand[MaxSize];int iTop=-1;//char Srcexp[MaxSize];char Capaexp[MaxSize];char RevPolishexp[MaxSize];float NumCapaTab[26];char validexp[]="*/+-()";char NumSets[]="0123456789";char StackSymb[MaxSize];int operands;//void NumsToCapas(char [], int , char [], float []);int CheckExpress(char);int PriorChar(char,char);int GetOperator(char [], char);void counterPolishexp(char INexp[], int slen, char Outexp[]); float CalcRevPolishexp(char [], float [], char [], int);void main(){char ch;char s;int bl=1;while(bl==1){int ilen;float iResult=0.0;printf("输入计算表达式(最后以=号结束):\n");memset(StackSymb,0,MaxSize);memset(NumCapaTab,0,26); //A--NO.1, B--NO.2, etc.gets(Srcexp);ilen=strlen(Srcexp);NumsToCapas(Srcexp,ilen,Capaexp,NumCapaTab);ilen=strlen(Capaexp);counterPolishexp(Capaexp,ilen,RevPolishexp);ilen=strlen(RevPolishexp);iResult=CalcRevPolishexp(validexp, NumCapaTab, RevPolishexp,ilen);printf("\n计算结果:\n%.6f\n",iResult);printf("是否继续运算?(Y/N)\n");ch=getchar();s=getchar();//接受回车if(ch=='y'||ch=='Y'){bl=1;}else{bl=0;}}}void iPush(float value){if(iTop<MaxSize) StaOperand[++iTop]=value;}float iPop(){if(iTop>-1)return StaOperand[iTop--];return -1.0;}void NumsToCapas(char Srcexp[], int slen, char Capaexp[], float NumCapaTab[]) {char ch;int i, j, k, flg=0;int sign;float val=0.0,power=10.0;i=0; j=0; k=0;while (i<slen){ch=Srcexp[i];if (i==0){sign=(ch=='-')?-1:1;if(ch=='+'||ch=='-'){ch=Srcexp[++i];flg=1;}}if (isdigit(ch)){val=ch-'0';while (isdigit(ch=Srcexp[++i])) {val=val*10.0+ch-'0';}if (ch=='.'){while(isdigit(ch=Srcexp[++i])) {val=val+(ch-'0')/power; power*=10;}} //end ifif(flg){val*=sign;flg=0;}} //end if//write Capaexp array// write NO.j to arrayif(val){Capaexp[k++]='A'+j; Capaexp[k++]=ch;NumCapaTab[j++]=val; //A--0, B--1,and C, etc.}else{Capaexp[k++]=ch;}val=0.0;power=10.0;//i++;}Capaexp[k]='\0';operands=j;}float CalcRevPolishexp(char validexp[], float NumCapaTab[], char RevPolishexp[], int slen) {float sval=0.0, op1,op2;int i, rt;char ch;//recursive stacki=0;while((ch=RevPolishexp[i]) && i<slen){switch(rt=GetOperator(validexp, ch)){case iMUL: op2=iPop(); op1=iPop();sval=op1*op2;iPush(sval);break;case iDIV: op2=iPop(); op1=iPop();if(!fabs(op2)){printf("overflow\n");iPush(0);break;}sval=op1/op2;iPush(sval);break;case iADD: op2=iPop(); op1=iPop();sval=op1+op2;iPush(sval);break;case iSUB: op2=iPop(); op1=iPop();sval=op1-op2;iPush(sval);break;case iCap: iPush(NumCapaTab[ch-'A']); break;default: ;}++i;}while(iTop>-1){sval=iPop();}return sval;}int GetOperator(char validexp[],char oper) {int oplen,i=0;oplen=strlen(validexp);if (!oplen) return -1;if(isalpha(oper)) return 4;while(i<oplen && validexp[i]!=oper) ++i;if(i==oplen || i>=4) return -1;return i;}int CheckExpress(char ch){int i=0;char cc;while((cc=validexp[i]) && ch!=cc) ++i;if (!cc)return 0;return 1;}int PriorChar(char curch, char stach){//栈外优先级高于(>)栈顶优先级时,才入栈//否则(<=),一律出栈if (curch==stach) return 0; //等于时应该出栈else if (curch=='*' || curch=='/'){if(stach!='*' && stach!='/')return 1;}else if (curch=='+' || curch=='-'){if (stach=='(' || stach==')')return 1;}else if (curch=='('){if (stach==')')return 1;}return 0;}void counterPolishexp(char INexp[], int slen, char Outexp[]) {int i, j, k,pr;char t;i=0;j=k=0;while (INexp[i]!='=' && i<slen){if (INexp[i]=='(')StackSymb[k++]=INexp[i];//iPush(*(INexp+i));else if(INexp[i]==')'){//if((t=iPop())!=-1)while((t=StackSymb[k-1])!='('){Outexp[j++]=t;k--;}k--;}else if (CheckExpress(INexp[i])) // is oparator{// printf("operator %c k=%d\n",INexp[i],k);while (k){// iPush(*(INexp+i));if(pr=PriorChar(INexp[i],StackSymb[k-1])) break;else{//if ((t=iPop())!=-1)t=StackSymb[k-1]; k--;Outexp[j++]=t;}} //end whileStackSymb[k++]=INexp[i]; //common process }else //if() 变量名{// printf("operand %c k=%d\n",INexp[i],k); Outexp[j++]=INexp[i];}i++; //}while (k){t=StackSymb[k-1]; k--;Outexp[j++]=t;}Outexp[j]='\0';}。

C语言鼠标操作方法及源码

C语言鼠标操作方法及源码

C语言鼠标操作方法及源码(转载)鼠标的操作是使用dos中断功能,中断号:33h下面给几个操作鼠标的示例,后面有更详细的中断功能说明及代码。

显示鼠标:union REGS regs;regs.x.ax=1;int86(0x33,&regs,&regs);检查是否被按下:union REGS regs;regs.x.ax=6;int86(0x33,&regs,&regs);返回值在bx寄存器中;在实际编程中一般要使用循环不断的检验是否被按下!检验鼠标位置:union REGS regs;regs.x.ax=3;int86(0x33,&regs,&regs);返回值:x坐标在regs.h.cxy坐标在regs.h.dx/*下面是各值对鼠标的设置功能*/(1)、功能00H功能描述:初始化鼠标,该操作只需要执行一次入口参数:AX=00H出口参数:AX=0000H——不支持鼠标功能,FFFFH——支持鼠标功能BX=鼠标按钮个数(在支持鼠标功能时)在支持鼠标功能的情况下,鼠标还被设置如下参数:1 、鼠标指针放在屏幕中央2 、如果当前鼠标指针是显示的,则操作后,鼠标指针被隐藏3 、鼠标指针的显示页为04 ——、根据屏幕的显示模式显示鼠标指针:文本反向显示矩形块,图形尖头形状5 、水平象素比=8:8,垂直象素比=16:86 、设置水平和垂直的显示边界为当前显示模式的最大边界7 、允许光笔仿真8 、双速门槛值=64(2)、功能01H功能描述:显示鼠标指针,通常在鼠标初始化后,用此功能显示其指针入口参数:AX =01H出口参数:无(3)、功能02H功能描述:隐藏鼠标指针,一般在程序结束时,调用此功能入口参数:AX=02H出口参数:无(4)、功能03H功能描述:读取鼠标位置及其按钮状态入口参数:AX=03H出口参数:BX =按键状态:位0=1——按下左键位1=1——按下右键位2=1——按下中键——其它位保留,内部使用CX =水平位置DX =垂直位置(5)、功能04H功能描述:设置鼠标指针位置入口参数:AX=04H,CX=水平位置,DX =垂直位置出口参数:无(6)、功能05H功能描述:读取鼠标按键信息入口参数:AX=05H,BX=指定的按键:0—左键,1—右键,2—中键出口参数:AX=按键状态,参见功能3H中BX的说明BX=按键次数CX=水平位置(最后按键时)DX=垂直位置(最后按键时)(7)、功能06H功能描述:读取鼠标按钮释放信息入口参数:AX=06H,BX=指定的按键:0—左键,1—右键,2—中键出口参数:AX=按键状态,参见功能3H中BX的说明BX=释放的次数CX=水平位置(最后释放时)DX=垂直位置(最后释放时) (8)、功能07H功能描述:设置鼠标水平边界入口参数:AX=07HCX=最小水平位置DX =最大水平位置出口参数:无,鼠标有可能因新区域变小而自动移进新区域内(9)、功能08H功能描述:设置鼠标垂直边界入口参数:AX=08HCX=最小垂直位置DX =最大垂直位置出口参数:无,鼠标有可能因新区域变小而自动移进新区域内(10)、功能09H功能描述:设置图形鼠标形状入口参数:AX=09HBX=指针的水平位置CX=指针的垂直位置ES:DX=16×16 位光标的映象地址参数说明:(BX,CX)是鼠标的指针在16×16点阵中的位置,(0,0)是左上角;ES:DX指向的存储单元内存放16×16点阵的位映象隐码,紧跟其后的是16×16点阵的光标掩码。

计算器(c 语言)实现源代码

计算器(c  语言)实现源代码

计算器(c++语言)实现源代码.txt如果真诚是一种伤害,请选择谎言;如果谎言是一种伤害,请选择沉默;如果沉默是一种伤害,请选择离开。

#include <iostream>using namespace std;#define STACK_INIT_SIZE 100#define STACKINCREMENT 10//-----------------------------------------------------------------------------------------------class Stack1{//定义字符栈public:char * base;char * top;int stacksize;Stack1();int GetTop(char &e);//取栈顶元素int Push(char e);//压栈int Pop(char &e);//跳栈};Stack1::Stack1(){base=(char *)malloc(STACK_INIT_SIZE*sizeof(char));top=base;stacksize=STACK_INIT_SIZE;}int Stack1::GetTop(char &e){if (top==base) return -1;else {e=*(top-1);return 0;}}int Stack1::Push(char e){char *new_base=0;if(top-base>=stacksize){new_base=(char *)realloc(base,(stacksize+STACKINCREMENT)*sizeof(char));if(!new_base) return -2;else{base=new_base;top=base+stacksize;stacksize+=STACKINCREMENT;}}*top++=e;return 0;}int Stack1::Pop(char &e){if(top==base) return -1;e=*--top;return 0;}//----------------------------------------------------------------------------------------------class Stack2{//定义数字栈public:double * base;double * top;int stacksize;Stack2();int GetTop(double &e);//取栈顶元素int Push(double e);//压栈int Pop(double &e);//跳栈};Stack2::Stack2(){base=(double *)malloc(STACK_INIT_SIZE*sizeof(double));top=base;stacksize=STACK_INIT_SIZE;}int Stack2::GetTop(double &e){if (top==base) return -1;e=*(top-1);return 0;}int Stack2::Push(double e){double *new_base=0;if(top-base>=stacksize){new_base=(double*)realloc(base,(stacksize+STACKINCREMENT)*sizeof(double));if(!new_base) return -2;else{new_base=base;top=base+stacksize;stacksize+=STACKINCREMENT;}}*top++=e;return 0;}int Stack2::Pop(double &e){if(top==base) return -1;e=*--top;return 0;}//------------------------------------------------------------------------------------------------class Calculator{private:bool IsOperand(char ch);//判断ch是否是操作数bool IsOperator(char ch);//判断ch是否是操作符char Precede(char op1,char op2);//判断两个操作符优先级的高低double Operate(double left,char op,double right);//执行运算left op right int Translate(char op);//将操作符映射到行、列游标public:void Run();//执行表达式求值运算};bool Calculator::IsOperand(char ch){if(ch>47&&ch<58) return true;else return false;}bool Calculator::IsOperator(char ch){if(ch>39&&ch<44||ch==45||ch==47||ch==61) return true;else return false;}char Calculator::Precede(char op1,char op2){int op10,op20;op10=op20=0;op10=Translate(op1);op20=Translate(op2);charOP[7][7]={'>','>','<','<','<','>','>','>','>','<','<','<','>','>','>','>','>','> ','<','>','>','>','>','>','>','<','>','>','<','<','<','<','<','=','e','>','>','> ','>','e','>','>','<','<','<','<','<','e','='};return OP[op10][op20];//将操作符优先级表映射到二维数组}double Calculator::Operate(double left,char op,double right){ switch(op){case '+':return (left+right);break;case '-':return (left-right);break;case '*':return (left*right);break;case '/':return (left/right);break;}}int Calculator::Translate(char op){switch(op){case '+':return 0;break;case '-':return 1;break;case '*':return 2;break;case '/':return 3;break;case '(':return 4;break;case ')':return 5;break;case '=':return 6;break;}}void Calculator::Run(){Stack1 OPTR;Stack2 OPND;char c;//用于临时存放输入的操作数或操作符char c0;//用于存放操作符栈顶的操作符char x;//用于存放弹出相同操作符后返回的操作符double a=0,b=0;double r=0;//用于存放运算结果int flag=0;//标记异常OPTR.Push('=');OPTR.GetTop(c0);cout<<"输入格式例如“3+4/(3-1)=”"<<endl;c=getchar();while(c!='='||c0!='='){if(IsOperand(c)) {OPND.Push(c-48);c=getchar();}else if(IsOperator(c)){switch(Precede(c0,c)){case '<':OPTR.Push(c);OPTR.GetTop(c0);c=getchar();break;case '=':OPTR.Pop(x);OPTR.GetTop(c0);c=getchar();break;case '>':OPTR.Pop(c0);OPND.Pop(b);OPND.Pop(a);OPND.Push(Operate(a,c0,b));OPTR.GetTop(c0);break;default:cout<<"输入有误!"<<endl;flag=-1;break;}}else {cout<<"未输入等于号“=”!"<<endl;flag=-1;break;}if (flag==-1) {break;}}if (flag!=-1){OPND.GetTop(r);cout<<"结果为:"<<r<<endl;}}void main (){Calculator C;C.Run();}。

计算器编程c语言

计算器编程c语言

计算器编程 c语言用C语言设计计算器程序源代码#include <dos.h> /*DOS接口函数*/#include <math.h> /*数学函数的定义*/#include <conio.h> /*屏幕操作函数*/函数*/#include <stdio.h> /*I/O#include <stdlib.h> /*库函数*/变量长度参数表*/#include <stdarg.h> /*图形函数*/#include <graphics.h> /*字符串函数*/#include <string.h> /*字符操作函数*/#include <ctype.h> /*#define UP 0x48 /*光标上移键*/#define DOWN 0x50 /*光标下移键*/#define LEFT 0x4b /*光标左移键*/#define RIGHT 0x4d /*光标右移键*/#define ENTER 0x0d /*回车键*/void *rar; /*全局变量,保存光标图象*/使用调色板信息*/struct palettetype palette; /*int GraphDriver; /* 图形设备驱动*/int GraphMode; /* 图形模式值*/int ErrorCode; /* 错误代码*/int MaxColors; /* 可用颜色的最大数值*/int MaxX, MaxY; /* 屏幕的最大分辨率*/double AspectRatio; /* 屏幕的像素比*/void drawboder(void); /*画边框函数*/初始化函数*/void initialize(void); /*计算器计算函数*/void computer(void); /*改变文本样式函数*/ void changetextstyle(int font, int direction, int charsize); /*窗口函数*/void mwindow(char *header); /*/*获取特殊键函数*/int specialkey(void) ;设置箭头光标函数*//*int arrow();/*主函数*/int main(){设置系统进入图形模式 */initialize();/*运行计算器 */computer(); /*系统关闭图形模式返回文本模式*/closegraph();/*/*结束程序*/return(0);}/* 设置系统进入图形模式 */void initialize(void){int xasp, yasp; /* 用于读x和y方向纵横比*/GraphDriver = DETECT; /* 自动检测显示器*/initgraph( &GraphDriver, &GraphMode, "" );/*初始化图形系统*/ErrorCode = graphresult(); /*读初始化结果*/如果初始化时出现错误*/if( ErrorCode != grOk ) /*{printf("Graphics System Error: %s\n",显示错误代码*/grapherrormsg( ErrorCode ) ); /*退出*/exit( 1 ); /*}getpalette( &palette ); /* 读面板信息*/MaxColors = getmaxcolor() + 1; /* 读取颜色的最大值*/MaxX = getmaxx(); /* 读屏幕尺寸 */MaxY = getmaxy(); /* 读屏幕尺寸 */getaspectratio( &xasp, &yasp ); /* 拷贝纵横比到变量中*/计算纵横比值*/ AspectRatio = (double)xasp/(double)yasp;/*}/*计算器函数*/void computer(void){定义视口类型变量*/struct viewporttype vp; /*int color, height, width;int x, y,x0,y0, i, j,v,m,n,act,flag=1;操作数和计算结果变量*/float num1=0,num2=0,result; /*char cnum[5],str2[20]={""},c,temp[20]={""};定义字符串在按钮图形上显示的符号 char str1[]="1230.456+-789*/Qc=^%";/**/mwindow( "Calculator" ); /*显示主窗口 */设置灰颜色值*//*color = 7;getviewsettings( &vp ); /* 读取当前窗口的大小*/width=(vp.right+1)/10; /* 设置按钮宽度 */设置按钮高度 */height=(vp.bottom-10)/10 ; /*/*设置x的坐标值*/x = width /2;设置y的坐标值*/y = height/2; /*setfillstyle(SOLID_FILL, color+3);bar( x+width*2, y, x+7*width, y+height );/*画一个二维矩形条显示运算数和结果*/setcolor( color+3 ); /*设置淡绿颜色边框线*/rectangle( x+width*2, y, x+7*width, y+height );/*画一个矩形边框线*/设置颜色为红色*/setcolor(RED); /*输出字符串"0."*/outtextxy(x+3*width,y+height/2,"0."); /*/*设置x的坐标值*/x =2*width-width/2;设置y的坐标值*/y =2*height+height/2; /*画按钮*/for( j=0 ; j<4 ; ++j ) /*{for( i=0 ; i<5 ; ++i ){setfillstyle(SOLID_FILL, color);setcolor(RED);bar( x, y, x+width, y+height ); /*画一个矩形条*/rectangle( x, y, x+width, y+height );sprintf(str2,"%c",str1[j*5+i]);/*将字符保存到str2中*/outtextxy( x+(width/2), y+height/2, str2);移动列坐标*/x =x+width+ (width / 2) ;/*}y +=(height/2)*3; /* 移动行坐标*/x =2*width-width/2; /*复位列坐标*/}x0=2*width;y0=3*height;x=x0;y=y0;gotoxy(x,y); /*移动光标到x,y位置*/显示光标*/arrow(); /*putimage(x,y,rar,XOR_PUT);m=0;n=0;设置str2为空串*/strcpy(str2,""); /*当压下Alt+x键结束程序,否则执行下面的循环while((v=specialkey())!=45) /**/{当压下键不是回车时*/while((v=specialkey())!=ENTER) /*{putimage(x,y,rar,XOR_PUT); /*显示光标图象*/if(v==RIGHT) /*右移箭头时新位置计算*/if(x>=x0+6*width)如果右移,移到尾,则移动到最左边字符位置*//*{x=x0;m=0;}else{x=x+width+width/2;m++;否则,右移到下一个字符位置*/} /*if(v==LEFT) /*左移箭头时新位置计算*/if(x<=x0){x=x0+6*width;m=4;} /*如果移到头,再左移,则移动到最右边字符位置*/else{x=x-width-width/2;m--;} /*否则,左移到前一个字符位置*/if(v==UP) /*上移箭头时新位置计算*/if(y<=y0){y=y0+4*height+height/2;n=3;} /*如果移到头,再上移,则移动到最下边字符位置*/else{y=y-height-height/2;n--;} /*否则,移到上边一个字符位置*/if(v==DOWN) /*下移箭头时新位置计算*/if(y>=7*height){ y=y0;n=0;} /*如果移到尾,再下移,则移动到最上边字符位置*/else{y=y+height+height/2;n++;} /*否则,移到下边一个字符位置*/putimage(x,y,rar,XOR_PUT); /*在新的位置显示光标箭头*/ }将字符保存到变量c中*/c=str1[n*5+m]; /*判断是否是数字或小数点*/if(isdigit(c)||c=='.') /*{如果标志为-1,表明为负数*/if(flag==-1) /*{将负号连接到字符串中*/strcpy(str2,"-"); /*flag=1;} /*将标志值恢复为1*/将字符保存到字符串变量temp中*/ sprintf(temp,"%c",c); /*将temp中的字符串连接到str2中*/strcat(str2,temp); /*setfillstyle(SOLID_FILL,color+3);bar(2*width+width/2,height/2,15*width/2,3*height/2);显示字符串*/outtextxy(5*width,height,str2); /*}if(c=='+'){将第一个操作数转换为浮点数*/num1=atof(str2); /*将str2清空*/strcpy(str2,""); /*做计算加法标志值*/act=1; /*setfillstyle(SOLID_FILL,color+3);bar(2*width+width/2,height/2,15*width/2,3*height/2);显示字符串*/outtextxy(5*width,height,"0."); /*}if(c=='-'){如果str2为空,说明是负号,而不是减号*/ if(strcmp(str2,"")==0) /*设置负数标志*/flag=-1; /*else{将第二个操作数转换为浮点数*/num1=atof(str2); /*将str2清空*/strcpy(str2,""); /*act=2; /*做计算减法标志值*/setfillstyle(SOLID_FILL,color+3);画矩形*/ bar(2*width+width/2,height/2,15*width/2,3*height/2); /*显示字符串*/outtextxy(5*width,height,"0."); /*}}if(c=='*'){将第二个操作数转换为浮点数*/num1=atof(str2); /*strcpy(str2,""); /*将str2清空*/做计算乘法标志值*/act=3; /*setfillstyle(SOLID_FILL,color+3); bar(2*width+width/2,height/2,15*width /2,3*height/2);显示字符串*/outtextxy(5*width,height,"0."); /*}if(c=='/'){将第二个操作数转换为浮点数*/num1=atof(str2); /*strcpy(str2,""); /*将str2清空*/做计算除法标志值*/act=4; /*setfillstyle(SOLID_FILL,color+3);bar(2*width+width/2,height/2,15*width/2,3*height/2);outtextxy(5*width,height,"0."); /*显示字符串*/}if(c=='^'){将第二个操作数转换为浮点数*/num1=atof(str2); /*将str2清空*/strcpy(str2,""); /*做计算乘方标志值*/act=5; /*设置用淡绿色实体填充*/ setfillstyle(SOLID_FILL,color+3); /*画矩形*/ bar(2*width+width/2,height/2,15*width/2,3*height/2); /*显示字符串*/outtextxy(5*width,height,"0."); /*}if(c=='%'){将第二个操作数转换为浮点数*/num1=atof(str2); /*strcpy(str2,""); /*将str2清空*/做计算模运算乘方标志值*/act=6; /*setfillstyle(SOLID_FILL,color+3); /*设置用淡绿色实体填充*/画矩形*/ bar(2*width+width/2,height/2,15*width/2,3*height/2); /*显示字符串*/outtextxy(5*width,height,"0."); /*}if(c=='='){将第二个操作数转换为浮点数*/num2=atof(str2); /*根据运算符号计算*/switch(act) /*{case 1:result=num1+num2;break; /*做加法*/case 2:result=num1-num2;break; /*做减法*/case 3:result=num1*num2;break; /*做乘法*/case 4:result=num1/num2;break; /*做除法*/case 5:result=pow(num1,num2);break; /*做x的y次方*/case 6:result=fmod(num1,num2);break; /*做模运算*/ }设置用淡绿色实体填充*/ setfillstyle(SOLID_FILL,color+3); /*覆盖结果区*/ bar(2*width+width/2,height/2,15*width/2,3*height/2); /*将结果保存到temp中*/sprintf(temp,"%f",result); /*outtextxy(5*width,height,temp); /*显示结果*/}if(c=='c'){num1=0; /*将两个操作数复位0,符号标志为1*/num2=0;flag=1;strcpy(str2,""); /*将str2清空*/设置用淡绿色实体填充*/ setfillstyle(SOLID_FILL,color+3); /*覆盖结果区*/ bar(2*width+width/2,height/2,15*width/2,3*height/2); /*显示字符串*/outtextxy(5*width,height,"0."); /*}如果选择了q回车,结束计算程序*/if(c=='Q')exit(0); /*}putimage(x,y,rar,XOR_PUT); /*在退出之前消去光标箭头*/返回*/return; /*}/*窗口函数*/void mwindow( char *header ){int height;cleardevice(); /* 清除图形屏幕 */setcolor( MaxColors - 1 ); /* 设置当前颜色为白色*//* 设置视口大小 */ setviewport( 20, 20, MaxX/2, MaxY/2, 1 );height = textheight( "H" ); /* 读取基本文本大小 */settextstyle( DEFAULT_FONT, HORIZ_DIR, 1 );/*设置文本样式*/settextjustify( CENTER_TEXT, TOP_TEXT );/*设置字符排列方式*/输出标题*/outtextxy( MaxX/4, 2, header ); /*setviewport( 20,20+height+4, MaxX/2+4, MaxY/2+20, 1 ); /*设置视口大小*/ 画边框*/drawboder(); /*}画边框*/void drawboder(void) /*{定义视口类型变量*/struct viewporttype vp; /*setcolor( MaxColors - 1 ); /*设置当前颜色为白色 */setlinestyle( SOLID_LINE, 0, NORM_WIDTH );/*设置画线方式*/将当前视口信息装入vp所指的结构中*/getviewsettings( &vp );/*画矩形边框*/rectangle( 0, 0, vp.right-vp.left, vp.bottom-vp.top ); /*}/*设计鼠标图形函数*/int arrow(){int size;定义多边形坐标*/int raw[]={4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4}; /*设置填充模式*/setfillstyle(SOLID_FILL,2); /*/*画出一光标箭头*/fillpoly(8,raw);测试图象大小*/size=imagesize(4,4,16,16); /*分配内存区域*/rar=malloc(size); /*存放光标箭头图象*/getimage(4,4,16,16,rar); /*putimage(4,4,rar,XOR_PUT); /*消去光标箭头图象*/return 0;}/*按键函数*/int specialkey(void){int key;等待键盘输入*/while(bioskey(1)==0); /*key=bioskey(0); /*键盘输入*/只取特殊键的扫描值,其余为0*/ key=key&0xff? key&0xff:key>>8; /*return(key); /*返回键值*/}。

C语言鼠标操作方法及源码

C语言鼠标操作方法及源码

C语言鼠标操作方法及源码C语言不是直接支持鼠标操作的,因为C语言是一种面向过程的编程语言,主要用于系统级编程和应用程序开发。

而鼠标操作通常是通过操作系统提供的图形界面库来实现的,如Windows中的WinAPI或Linux中的X窗口系统等。

在C语言中,可以使用图形界面库或API来实现鼠标操作。

以下是一个使用WinAPI实现鼠标操作的例子:```c#include <windows.h>LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)switch (uMsg)case WM_MOUSEMOVE:int xPos = LOWORD(lParam);int yPos = HIWORD(lParam);//处理鼠标移动事件printf("鼠标移动到坐标 (%d, %d)\n", xPos, yPos);break;}case WM_LBUTTONDOWN:int xPos = LOWORD(lParam);int yPos = HIWORD(lParam);//处理鼠标左键按下事件printf("鼠标左键按下,坐标 (%d, %d)\n", xPos, yPos); break;}case WM_LBUTTONUP:int xPos = LOWORD(lParam);int yPos = HIWORD(lParam);//处理鼠标左键松开事件printf("鼠标左键松开,坐标 (%d, %d)\n", xPos, yPos); break;}//其他鼠标事件的处理...}return DefWindowProc(hwnd, uMsg, wParam, lParam);int main//创建窗口HWND hwnd;WNDCLASS wc = {0};wc.lpfnWndProc = WindowProc;wc.hInstance = GetModuleHandle(NULL);wc.lpszClassName = TEXT("MyWindowClass");RegisterClass(&wc);hwnd = CreateWindowEx(0, TEXT("MyWindowClass"), TEXT("C语言鼠标操作示例"), WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL, NULL,wc.hInstance, NULL);ShowWindow(hwnd, SW_SHOWDEFAULT);}//消息循环MSG msg;while (GetMessage(&msg, NULL, 0, 0))TranslateMessage(&msg);DispatchMessage(&msg);}return 0;```以上代码演示了一个简单的C语言程序,通过使用WinAPI,实现了基本的鼠标操作。

C++语言编程计算器源代码

C++语言编程计算器源代码

//计算器,函数#include <iostream>#include <string>#include <ctime>#include <conio.h>#include <cstdlib>#include <cmath>#include <vector>#include <cctype>using namespace std;double simple (string s);//简单运算bool check (char c);//检查是否为数值doublecou (double m,doublen,int c);//用于计算两个数的运算string cut (string str);//括号截取double senior (string str,double x);//高级函数计算double count (string st);//括号运算boolbr_l (char c);boolbr_r (char c);string al (string st);//特殊值与符号处理string abs_cut (string st);//绝对值处理intnum;string s;vector <double> b;//存储高级符号内值int main (){ cout<<"\n\t\t本软件由松哥独家制造\n\n"; while (true){ int i=0,j=0;num=0;string s1;b.clear ();cout<<"输入:"; cin>>s1;string s2(s1);if (s=="#") break;cout<<"输出:"<<s2<<"="<<count (s1)<<endl;} cout<<"\n\t\t感谢您的支持!!!!";}double simple (string st){ int i=0,j=0,k=0;vector <double> p;//存储读入的数字vector <int> q;//存储读入运算符while (st[i]!='\0'&&st[i]!='='){double sum=0;while (!check (st[i])) i++;while (check (st[i])){if (st[i]>64&&st[i]<91){sum=b[st[i]-65];i++;break;}if (st[i]!='.') sum=sum*10+(st[i++]-48);else {i++;double su=0,m=1;while (check (st[i])){m*=10.0;su=su*10+(st[i++]-48);}sum=sum+su/m;}}p.push_back (sum); }if (st[0]=='-') p[0]=-p[0];for (i=1;st[i]!='\0';i++){switch (st[i]){case '=':break;case '^': q.push_back (1);break;case '/': q.push_back (-3);break;case '*': q.push_back (3);break;case '+': q.push_back (4);break;case '-' :q.push_back (-4) ;break;default :if (!check (st[i])) {cout<<"含未知符号"<<st[i]<<"!\n"; return 0;}}}i=p.size (),j=q.size ();if (j==1) return cou (p[0],p[1],q[0]);else while (i!=1)for (int k=0;k<j;k++) {if (k==j-1&&abs (q[k])<abs (q[k-1])){p[k]=cou (p[k],p[k+1],q[k]); i--;j--; for (k;k<q.size ()-1;k++) {p[k+1]=p[k+2];q[k]=q[k+1];}p.pop_back ();q.pop_back ();break;}else if (abs (q[k])<=abs (q[k+1])) {p[k]=cou (p[k],p[k+1],q[k]); i--;j--;for (k;k<q.size ()-1;k++) {p[k+1]=p[k+2];q[k]=q[k+1];}p.pop_back ();q.pop_back ();if (j==1) break; } }return p[0];}bool check (char c){if (c>='0'&&c<='9'||c=='.'||c>64&&c<85) return true;else return false;}doublecou (double m,doublen,int c) {switch (c){case 1:return pow (m,n);case 3:return (m*n);case -3:return (m/n);case 4:return (m+n);case -4:return (m-n);default :cout<<c<<"无法计算!\n";} }string cut (string str){int i=0,m=0,n=0,r=0;string se;for (int j=0;j<str.size ();j++){if (br_l (str[j])) {m=j;i++;}if (br_r (str[j])) {n=j;if (n!=0) break;}}if (i==0) return str;if (m>0&&isalpha (str[m-1]))for (int k=m-1;;k--)if (k<0||!isalpha (str[k])) {k++;se=str.substr (k,m-k);int l=n-m+1;s=str.substr (m+1,l-2);b.push_back (senior (se,simple (s)));num++;l=n-k+1;str.replace (k,l,1,(char) (64+num)); returnstr;}int l=n-m+1;s=str.substr (m+1,l-2);b.push_back (simple (s));num++;str.replace (m,l,1,(char) (64+num)); returnstr;}double count (string st){ st=al (st);st=abs_cut (st);while (true){int r=0;st=cut (st);for (int i=0;i<st.size ();i++)if (br_r (st[i])) r++;if (r==0) break;}return simple (st);}boolbr_l (char c) {if (c=='('||c=='['||c=='{') return true;else return false;}boolbr_r (char c) {if (c==')'||c==']'||c=='}')return true;else return false;}string al (string st){inti,j=0;double m=0,n=1;for (i=0;i<st.size ();i++){if (st[i]=='e') {num++;st.replace (i,1,1,(char)(64+num));b.push_back (pow (2,1/log (2)));}if (st[i]=='p') {num++;st.replace (i,2,1,(char)(64+num));b.push_back (3.141593);}if (st[i]=='!'){j=i-1;while (j>0) {j--;if (st[j]=='.'){cout<<"只能计算整数的阶乘!!!\n";return "0";}if (st[j]<48||st[j]>57) {j++;break;}}for (int k=j;k<i;k++)m=m*10+(st[k]-48);for (m;m>1;m--) n*=m; num++;st.replace (j,i-j+1,1,(char)(64+num));b.push_back (n);}}i=st.find ("π");if (i<st.size ()) {num++;st.replace (i,2,1,(char)(64+num));b.push_back (acos (-1.0));}i=st.find ("∞");if (i<st.size ()) {num++;st.replace (i,3,1,(char)(64+num));b.push_back (DBL_MAX);}returnst;}stringabs_cut (string st){ inti;vector<int> m;for (i=0;i<st.size ();i++)if (st[i]=='|') m.push_back (i);i=m.size ()/2;if (i==0) return st;i--;string s=st.substr (m[i]+1,m[i+1]-m[i]-1);b.push_back (fabs (count (s)));num++;st.replace (m[i],m[i+1]-m[i]+1,1,(char) (64+num));if (i!=0) st=abs_cut (st);returnst;}double senior (string str,double x){ int i=0;string s[]={"acos","asin","atan","cos","cosh","sin", "sinh","tan","tanh","ln","log","no"};for (i;i<12;i++) if (str==s[i]) break;switch (i){case 0:return acos (x);case 1:return asin (x);case 2:return atan (x);case 3:return cos (x);case 4:return cosh (x);case 5:return sin (x);case 6:return sinh (x);case 7:return tan (x);case 8:return tanh (x);case 9:return log (x);case 10:return log10 (x);default :cout<<str<<"函数尚未收录\n"; return x;}}。

用c语言编写的计算器源代码

用c语言编写的计算器源代码

作品:科学计算器作者:欧宗龙编写环境:vc++6.0语言:c#include "stdafx.h"#include <stdio.h>#include <windows.h>#include <windowsx.h>#include "resource.h"#include "MainDlg.h"#include <math.h>#include <string.h>#define PI 3.141593BOOL A_Op=FALSE;BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch(uMsg){HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);HANDLE_MSG(hWnd, WM_MAND, Main_Onmand);HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);}return FALSE;}BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam){return TRUE;}void TrimNumber(char a[])//判断并删除小数点后无用的零for(unsigned i=0;i<strlen(a);i++){if(a[i]=='.'){for(unsigned j=strlen(a)-1;j>=i;j--){if(a[j]=='0'){a[j]='\0';}else if(a[j]=='.'){a[j]='\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=='^'){n2=pow(n1,n2);}return n2;}////////////////////////////////////////////////void IntBinary(char a[],int n){if(n>1)IntBinary(a,n/2);sprintf(a,"%s%i",a,n%2);}void decimal(char a[],double m){if(m>0.000001){m=m*2;sprintf(a,"%s%d",a,(long)m);decimal(a,m-(long)m);}}void Binary(char a[],double Num){char DecP[256]="";double x,y;double *iptr=&y;x=modf(Num,iptr);decimal(DecP,x);IntBinary(a,(int)y);strcat(a,".");strcat(a,DecP);}////////////////////////////////////void Main_Onmand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify) {static DELTIMES=0;static char str[256];static char Operator='0';static double RNum[3];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);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN2://数字2{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"2");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN3://数字3{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"3");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN4://数字4{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"4");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN5://数字5{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"5");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN6://数字6{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"6");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN7://数字7{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"7");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN8://数字8{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"8");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN9://数字9{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"9");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONN0://数字0{if(A_Op){SetDlgItemText(hwnd,IDC_EDIT,NULL);}GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));strcat(str,"0");SetDlgItemText(hwnd,IDC_EDIT,str);RNum[1]=atof(str);A_Op=FALSE;}break;case IDC_BUTTONDEL://小数点.del{if(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: //加法运算{RNum[1]=atof(str);RNum[0]=RNum[1];RNum[1]=RNum[2];RNum[2]=Operate(Operator,RNum[1],RNum[0]);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator='+';DELTIMES=0;A_Op=TRUE;}break;case IDC_BUTTONSUB: //减法运算{RNum[1]=atof(str);RNum[0]=RNum[1];RNum[1]=RNum[2];RNum[2]=Operate(Operator,RNum[1],RNum[0]);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);DELTIMES=0;A_Op=TRUE;Operator='-';}break;case IDC_BUTTONMUL: //乘法运算{RNum[1]=atof(str);RNum[0]=RNum[1];RNum[1]=RNum[2];RNum[2]=Operate(Operator,RNum[1],RNum[0]);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator='*';DELTIMES=0;A_Op=TRUE;}break;case IDC_BUTTONDIV: //除法运算{RNum[1]=atof(str);RNum[0]=RNum[1];RNum[1]=RNum[2];RNum[2]=Operate(Operator,RNum[1],RNum[0]);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator='/';DELTIMES=0;A_Op=TRUE;}break;case IDC_BUTTONXY://x的y次方{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[1]=atof(str);RNum[0]=RNum[1];RNum[1]=RNum[2];RNum[2]=Operate(Operator,RNum[1],RNum[0]);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator='^';DELTIMES=0;}break;case IDC_BUTTONPI: //圆周率PI,弧度{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));if(atof(str)!=0){RNum[2]=atof(str)*PI;sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);}else{sprintf(str,"%f",PI);SetDlgItemText(hwnd,IDC_EDIT,str);}A_Op=TRUE;}break;case IDC_BUTTONSQRT: //开根号{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=sqrt(atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONSIN: //三角函数sin函数{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=sin(atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONCOS://三角函数cos函数{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=cos(atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONTAN://三角函数tan函数{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=tan(atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONSQ: //平方{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=atof(str)*atof(str);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONCUBE://三次方{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=atof(str)*atof(str)*atof(str);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONEX://e的x次方{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=exp(atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTON10X://10的x次方{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=pow(10,atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONLN: //ln x{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=log(atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONLOG10: //log10{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=log10(atof(str));sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONBINARY: //十进制转换为二进制{char a[256]="";GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[2]=atof(str);Binary(a,RNum[2]);strcpy(str,a);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);A_Op=TRUE;}break;case IDC_BUTTONCLEAR://清除数据{DELTIMES=0;Operator='0';RNum[0]=RNum[1]=RNum[2]=0;memset(str,0,sizeof(str));SetDlgItemText(hwnd,IDC_EDIT,NULL);A_Op=FALSE;}break;case IDC_BUTTONBACKSPACE://退格键{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));int i=strlen(str);str[i-1]='\0';SetDlgItemText(hwnd,IDC_EDIT,str);}break;case IDC_ENTER://Enter键{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));RNum[1]=atof(str);RNum[0]=RNum[1];RNum[1]=RNum[2];RNum[2]=Operate(Operator,RNum[1],RNum[0]);sprintf(str,"%f",RNum[2]);TrimNumber(str);SetDlgItemText(hwnd,IDC_EDIT,str);Operator='0';DELTIMES=0;}break;default:break;}}void Main_OnClose(HWND hwnd){EndDialog(hwnd, 0);}本人拙作,如有不足之处请谅解。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

可以用鼠标操作的C语言计算器源码,比较精美了/** **** **** *** **** *文件包含****** *** *** ** *****/#include <dos.h> /*DOS接口函数*/#include <math.h> /*数学函数的定义*/#include <conio.h> /*屏幕操作函数*/#include <stdio.h> /*I/O函数*/#include <stdlib.h> /*库函数*/#include <stdarg.h> /*变量长度参数表*/#include <graphics.h> /*图形函数*/#include <string.h> /*字符串函数*/#include <ctype.h> /*字符操作函数*/#include <bios.h>/** **** ***** ******宏代换定义****** ****** *** *****/#define BWIDTH 50 /*按键条的宽度*/#define BHEIGHT 30 /*按键条的高度*/#define MAX_SCR 15#define PI 3.141592654/** **** ********** ***声明函数** ****** ** **** *****/void graph(void); /*画图形函数声明*/void windows(void); /*绘制窗口界面函数声明*/void button(int x,int y,int c1,int c2,int c3,char *bt); /*按键函数声明*/void scr(char scr_main[MAX_SCR],int error); /*屏显函数声明*/int mouse_message(void); /*鼠标信息函数声明*/void visbilemouse(void); /*鼠标可视化函数声明*/void getmouse(int *x,int *y,int *key); /*获得鼠标信息函数声明*/void drawmouse(int *x,int *y,int *z); /*画鼠标函数声明*/void jd(int x,int y); /*按钮焦点函数声明*/void calculator(int fun_code); /*实现计算器功能函数声明*/void clrnum(int n0,int n1); /*清空Num数组函数声明*/void adv(void); /*高级函数功能声明*/double qiu_zhi(char *bds_start,char *bds_end); /*求表达式值函数声明*/long jie_cheng(long n); /*阶乘函数声明*//** **** ***** **** ****定义全局变量* ****** **** ****/int Maxcolor,Maxx,Maxy; /*定义最大颜色数,边界*/char Num[2][MAX_SCR]={{0},{0}}; /*定义存储数据的二维数组,分别对应双目运算的数据*/double Memory=0; /*定义内存存储数据*/int Flag=0,Num_flag=0; /*二维数组的第几维数和第几个数*/char fun=0; /*功能变量,对应双目运算*/int Mx,My,Mkey,Mk0=-1; /*定义鼠标的位置和按键状态,初始键值为-1*/int jd0=-1,jd1=-1; /*定义按键焦点,按鼠标键后返回0~29或-1*/charfunction[30]={'Q','M','R','S','P','B','7','4','1','0','C','8','5','2','F','A','9','6','3','.','%','/','*','-','+','e','^','K','D ','='}; /*定义按键对应的function[fun_code]*/char Adv_ch[100]={0}; /*定义表达式数组变量*//** **** ***** ** ****** ***主函数** *** *** **** *****/void main(){int message; /*定义通信变量*/graph(); /*进入图形模式*/windows(); /*绘制窗口界面*/visbilemouse(); /*显示鼠标*/for (;message=mouse_message();)if (message!=-1) calculator(message); /*用鼠标输入数据mouse-message返回jd1到message*/closegraph(); /*关闭图形模式*/} /*message,fun-code,jd1是相互联系的通信变量*//** **** **** *** ***进入图形模式** *** *** ** ***** *****/void graph(void){int GraphDriver=DETECT,GraphMode,ErrorCode;initgraph( &GraphDriver, &GraphMode, "" ); /*初始化图形系统*/ErrorCode = graphresult(); /*读初始化结果*/if( ErrorCode != grOk ) /*如果初始化时出现错误*/{printf("Graphics System Error: %s\n",grapherrormsg( ErrorCode ) ); /*显示错误代码*/ exit(1); /*退出*/}/*读取最大颜色数,最大横纵座标*/Maxcolor=getmaxcolor();Maxx=getmaxx();Maxy=getmaxy();}/** **** *** ** ***** *绘制窗口界面***** ** ** ***** *****/void windows(void){int i,j;char btext[30][6]={"QUIT"," MC"," MR"," MS"," M+"," \033 "," 7 "," 4 "," 1 "," 0 "," C "," 8 ","5 "," 2 ","+/-","ADV"," 9 ","6 "," 3 "," . "," % "," / "," * "," - "," + ","EXP","X^Y","y\0373X","1/X"," = "};/*定义各键的显示符号*/intctext[30]={RED,GREEN,GREEN,GREEN,GREEN,RED,BLUE,BLUE,BLUE,BLUE,RED,BLU E,BLUE,BLUE,BLUE,RED,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLUE,BLU E,BLUE,BLUE,BLUE,RED}; /*定义各键的显示颜色*/setbkcolor(WHITE); /*定义背景色*/setcolor(BLUE); /*设定蓝色模式*/rectangle(10,10,Maxx-10,Maxy-10); /*画计算器边框*/line(10,300,400,300);line(400,10,400,300);bar(150,0,245,20);outtextxy(160,7,"Calculator");for (i=0;i<=5;i+=1)for (j=0;j<=4;j+=1)button(25+i*(BWIDTH+10),100+j*(BHEIGHT+10),WHITE,ctext,ctext,btext); /*画按键的矩形条*/scr(Num[Flag],0);}/** **** ***** *** ***绘制按钮** ****** ******** *****/void button(int x,int y,int c1,int c2,int c3,char *bt){setfillstyle(SOLID_FILL,c1); /*用c1颜色填充*/bar(x,y,x+BWIDTH,y+BHEIGHT); /*画按键的条形图*/setcolor(c2); /*设置c2颜色模式*/rectangle(x,y,x+BWIDTH,y+BHEIGHT); /*画矩形框*/setcolor(c3); /*设置c3颜色模式*/outtextxy(x+13,y+13,bt); /*字符输出定位函数*/}/** **** ****** ***计算器屏幕显示** ******* **** *****/void scr(char scr_main[MAX_SCR],int error){char memory_s[20]; /*定义内存数组来存储内存数据*/bar(25,25,375,75); /*画屏显的条形图*/setcolor(BLUE); /*设置蓝色模式*/rectangle(25,25,375,75); /*画屏显的边框*/setcolor(GREEN); /*设置绿色模式*/settextstyle(0,0,3); /*改变字符大小方向函数*/if (error) {strcpy(scr_main,"error"); setcolor(RED); Flag=0; Num_flag=0; clrnum(0,1); } outtextxy(30,50,scr_main); /*字符输出定位函数scr_main中存储的是主屏数据*/setcolor(RED); /*设置红色模式*/settextstyle(0,0,2); /*改变字符大小方向函数*/sprintf(memory_s,"M[%f]",Memory); /*将Memory拷贝到memory-s中再按"M[0.000000]"格式化输出*/outtextxy(30,30,memory_s); /*字符输出定位函数,内存显示*/}/** **** **** **** ***鼠标** ****** **** *****//*显示鼠标*/void visbilemouse(){union REGS inregs,outregs;inregs.x.ax=0x01; /*显示鼠标*/int86(0x33,&inregs,&outregs); /*通用软中断库函数*/}/*鼠标消息*/int mouse_message(){drawmouse(&Mx,&My,&Mkey); /*调用画鼠标函数*/for (;Mk0==Mkey;){getmouse(&Mx,&My,&Mkey); /*调用获得鼠标函数*/}if (Mk0==1){Mk0=-1;return jd1;}if (Mk0==2){Mk0=-1;return jd1;}}/*获取鼠标位置和按键,key=1是左键,key=2是右键*/void getmouse(int *x,int *y,int *key){union REGS inregs,outregs;inregs.x.ax=3; /*获取鼠标位置和状态也可以用3*/int86(0x33,&inregs,&outregs); /*中断调用*/*x=outregs.x.cx; /*cx寄存器中存的是横坐标*/*y=outregs.x.dx; /*dx寄存器中存的是列坐标*/*key=outregs.x.bx; /*bx寄存器是按键状态*/}/*按键后,返回当前鼠标的x,y和按键状态,直到按键后才返回*/void drawmouse(int *x,int *y,int *z) /*画鼠标是利用将一个空矩形存入内存中,然后再在该空矩形中画鼠标形状*/{int a=0,b=0,c=0,a_old=0,b_old=0; /*a,b的值可以随便*/int *ball; /*定义指向内存的存储图形的指针*/ball=malloc(imagesize(a,b,a+20,b+20)); /*返回矩形的大小*/getimage(a,b,a+20,b+20,ball); /*第一次将图形(一个空矩形)存入到内存中,内存中存入的是一个空矩形*/while(c==0) /*直到按键后才返回,不按键一直循环*/{getmouse(&a,&b,&c); /*a,为横坐标,b,为列坐标,c为按键状态*/if(a<0) a=0; /*保证鼠标左边不出界*/if(b<0) b=0; /*保证上面不出界*/if(a>Maxx-20) a=Maxx-20; /*保证右边不出界*/if(b>Maxy-20) b=Maxy-20; /*保证下边不出界*/if(a!=a_old || b!=b_old) /*当鼠标移动时*/{putimage(a_old,b_old,ball,0); /*在a_old,b_old输出图形,用来擦掉原来的鼠标*/jd(a,b);getimage(a,b,a+20,b+20,ball); /*这条语句是将目前鼠标所在位置的图形存贮到ball里面试着看着有无这条语句的区别*//*不需要在获取了*/setcolor(BLUE);setlinestyle(0,0,1);line(a,b,a+15,b+15/2);line(a,b,a+15/2,b+15);line(a+15/2,b+15,a+10,b+25/2);line(a+15,b+15/2,a+25/2,b+10);line(a+10,b+25/2,a+15,b+35/2);line(a+25/2,b+10,a+35/2,b+15);line(a+15,b+35/2,a+35/2,b+15);/*画鼠标*/}a_old=a;b_old=b;} /*while()结束*/Mk0=c;*x=a;*y=b;*z=c; /*返回按键后鼠标的位置*/putimage(a,b,ball,0); /*将鼠标擦掉,因为存在ball里面的是一个背景为缺省状态下的一个空矩形*/free(ball);}/** **** **** *** ***按钮焦点*** *** ** *** *****/void jd(int x,int y){int i;jd1=(y-95)/(BHEIGHT+10)+(x-20)/(BWIDTH+10)*5; /*确定鼠标具体在哪个键上,得到编号来对应键*/if (jd0==jd1) return; /*编号未变即鼠标未移位,返回*/if (!((x>20&&x<380) && (y>95&&y<295))) jd1=-1; /*超出边界,编号为-1*/if (jd0!=-1){setcolor(WHITE);setlinestyle(0,0,3);rectangle(jd0/5*(BWIDTH+10)+20,jd0%5*(BHEIGHT+10)+95,jd0/5*(BWIDTH+10)+30+B WIDTH,jd0%5*(BHEIGHT+10)+105+BHEIGHT);} /*将上次突出显示的黄色擦除*/if (jd1!=-1){setcolor(YELLOW);setlinestyle(0,0,3);rectangle((x-20)/(BWIDTH+10)*(BWIDTH+10)+20,(y-95)/(BHEIGHT+10)*(BHEIGHT+10) +95,(x-20)/(BWIDTH+10)*(BWIDTH+10)+30+BWIDTH,(y-95)/(BHEIGHT+10)*(BHEIGHT+1 0)+105+BHEIGHT);} /*突出显示鼠标所在键为黄色*/jd0=jd1; /*将上次的鼠标位置赋予jd0,以用于鼠标位置变化的判断和突出显示黄色的擦除*/}/** **** ****** ****实现计算器功能* ****** * *****/void calculator(int fun_code){int i,error=0;int dot_num=0,e_num=0;int len=0;char temp_s[20]={0};for (i=0;Num[Flag];i++) { dot_num+=Num[Flag]=='.'?1:0; e_num+=Num[Flag]=='e'?1:0; len++;}Num_flag=len;for (i=Num_flag;i<MAX_SCR;i++) Num[Flag]=0;switch(function[fun_code]){case '1':case '2':case '3':case '4':case '5':case '6':case '7':case '8':case '9': if (Num_flag<MAX_SCR-1) Num[Flag][Num_flag++]=function[fun_code]; break; case '0': if (Num_flag<MAX_SCR-1 && (atof(Num[Flag])!=0 || Num[Flag][0]=='.')) Num[Flag][Num_flag++]=function[fun_code]; break;case '.': if (Num_flag<MAX_SCR-1 && dot_num==0) Num[Flag][Num_flag++]=function[fun_code]; dot_num++; break;case 'e': if (Num_flag<MAX_SCR-1 && e_num==0) Num[Flag][Num_flag++]=function[fun_code]; e_num++; break;case 'F':if (Num[Flag][0]=='-'){for (i=0;i<MAX_SCR-1;i++) Num[Flag]=Num[Flag];}/*左移一位*/else if (Num_flag<MAX_SCR-1){for (i=MAX_SCR-2;i>0;i--) Num[Flag]=Num[Flag]; Num[Flag][0]='-';}/*右移一位*/break;case '+':case '-':case '*':case '/':case '%':case '^':case 'K': Flag=1; Num_flag=0; fun=function[fun_code]; clrnum(Flag,Flag); break;case 'B': if (Num_flag>0) Num[Flag][--Num_flag]=0; break;case 'A': closegraph();adv(); break;case 'C': Flag=0; Num_flag=0; clrnum(0,1); break;case 'M': Memory=0; break;case 'R': clrnum(Flag,Flag); gcvt(Memory,10,temp_s);strcpy(Num[Flag],temp_s); break;case 'S': Memory=atof(Num[Flag]); break;case 'P': Memory+=atof(Num[Flag]); break;case 'D': if (atof(Num[Flag]))gcvt(1/atof(Num[Flag]),10,Num[Flag]);elseerror=1;break;case '=': Flag=0; Num_flag=0;switch(fun){case '+': gcvt(atof(Num[0])+atof(Num[1]),10,Num[0]); break;case '-': gcvt(atof(Num[0])-atof(Num[1]),10,Num[0]); break;case '*': gcvt(atof(Num[0])*atof(Num[1]),10,Num[0]); break;case '/': if (atof(Num[1]))gcvt(atof(Num[0])/atof(Num[1]),10,Num[0]);else error=1;break;case '%': gcvt((long)atof(Num[0])%(long)atof(Num[1]),10,Num[0]); break;case '^': gcvt(pow(atof(Num[0]),atof(Num[1])),10,Num[0]); break;case 'K': if (atof(Num[1]))gcvt(pow(atof(Num[0]),1/atof(Num[1])),10,Num[0]);else error=1;break;}break;}scr(Num[Flag],error);}/*清空Num数组*/void clrnum(int n0,int n1){int i;for (i=0;i<MAX_SCR;i++) Num[n0]=Num[n1]=0;}/*高级功能*/void adv(){char *i;printf("Forexample:\n[1+(2-3)]*4/{5%6}+1e3+sin(pi/4)-arctan(1)*4+3^4+5!+ln2.718-log(2+3)|(10^3)\nInput esc to quit\n");for (;1;){printf("Please input:\n");gets(Adv_ch);if (!strcmp(Adv_ch,"quit") || !strcmp(Adv_ch,"esc")) exit(0);for (i=Adv_ch;i<Adv_ch+strlen(Adv_ch);i++){if (*i=='[' || *i=='{') *i='(';if (*i==']' || *i=='}') *i=')';}printf("=%f\n",qiu_zhi(Adv_ch,Adv_ch+strlen(Adv_ch)-1));}}/*求表达式的值*/double qiu_zhi(char *bds_start,char *bds_end){char *now;char temp[100]={0};int kuo_hao=0,i=0;for (now=bds_start+1;now<=bds_end;now++){if (*now=='+' || *now=='-' || *now=='*' || *now=='/' || *now=='%') i++;if (*now=='^' || *now=='!' || *now=='s' || *now=='c' || *now=='t' || *now=='l' || *now=='g' || *now=='n') i++;}if (!i){now=bds_start;for (;now<=bds_end;now++) temp[now-bds_start]=*now;if (temp[0]=='p' && temp[1]=='i') return PI;return (atof(temp));}for (now=bds_end;now>=bds_start;now--){kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);if (*now=='+' && kuo_hao==0) return(qiu_zhi(bds_start,now-1)+qiu_zhi(now+1,bds_end));if (*now=='-' && kuo_hao==0) return(qiu_zhi(bds_start,now-1)-qiu_zhi(now+1,bds_end));}for (now=bds_end;now>=bds_start;now--){kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);if (*now=='*' && kuo_hao==0) return(qiu_zhi(bds_start,now-1)*qiu_zhi(now+1,bds_end));if (*now=='/' && kuo_hao==0) return(qiu_zhi(bds_start,now-1)/qiu_zhi(now+1,bds_end));if (*now=='%' && kuo_hao==0) return((long)qiu_zhi(bds_start,now-1)%(long)qiu_zhi(now+1,bds_end));}for (now=bds_end;now>=bds_start;now--){kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='s' && *(now+1)=='i' && *(now+2)=='n' && kuo_hao==0)return(asin(qiu_zhi(now+3,bds_end)));if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='c' && *(now+1)=='o' && *(now+2)=='s' && kuo_hao==0)return(acos(qiu_zhi(now+3,bds_end)));if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='t' && *(now+1)=='a' && *(now+2)=='n' && kuo_hao==0)return(atan(qiu_zhi(now+3,bds_end)));if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='c' && *(now+1)=='s' && *(now+2)=='c' && kuo_hao==0)return(asin(1/qiu_zhi(now+3,bds_end)));if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='s' && *(now+1)=='e' && *(now+2)=='c' && kuo_hao==0)return(acos(1/qiu_zhi(now+3,bds_end)));if (*(now-3)=='a' && *(now-2)=='r' && *(now-1)=='c' && *now=='c' && *(now+1)=='o' && *(now+2)=='t' && kuo_hao==0)return(atan(1/qiu_zhi(now+3,bds_end)));if (*now=='s' && *(now+1)=='i' && *(now+2)=='n' && kuo_hao==0) return(sin(qiu_zhi(now+3,bds_end)));if (*now=='c' && *(now+1)=='o' && *(now+2)=='s' && kuo_hao==0) return(cos(qiu_zhi(now+3,bds_end)));if (*now=='t' && *(now+1)=='a' && *(now+2)=='n' && kuo_hao==0) return(tan(qiu_zhi(now+3,bds_end)));if (*now=='c' && *(now+1)=='s' && *(now+2)=='c' && kuo_hao==0) return(1/sin(qiu_zhi(now+3,bds_end)));if (*now=='s' && *(now+1)=='e' && *(now+2)=='c' && kuo_hao==0) return(1/cos(qiu_zhi(now+3,bds_end)));if (*now=='c' && *(now+1)=='o' && *(now+2)=='t' && kuo_hao==0) return(1/tan(qiu_zhi(now+3,bds_end)));}for (now=bds_end;now>=bds_start;now--){char *x;kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);if (*now=='l' && *(now+1)=='n' && kuo_hao==0) return(log(qiu_zhi(now+2,bds_end)));if (*now=='|' && kuo_hao==0){x=now;for (;x>=bds_start;x--)if (*x=='l' && *(x+1)=='o' && *(x+2)=='g') break;return(log10(qiu_zhi(now+1,bds_end))/log10(qiu_zhi(x+3,now-1)));}}for (now=bds_end;now>=bds_start;now--){kuo_hao+=(*now==')'?1:0); kuo_hao-=(*now=='('?1:0);if (*now=='^' && kuo_hao==0) return(pow(qiu_zhi(bds_start,now-1),qiu_zhi(now+1,bds_end)));if (*now=='!' && kuo_hao==0) return(jie_cheng((long)qiu_zhi(bds_start,now-1)));}if (*bds_start=='(' && *bds_end==')') return qiu_zhi(bds_start+1,bds_end-1);printf("error");}/*计算阶乘*/long jie_cheng(long n){long jc=n;for (n--;n>0;n--) jc*=n;return jc;}。

相关文档
最新文档