可以用鼠标操作的C语言计算器源码
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
可以用鼠标操作的C语言计算器源码,比较精美了
/** **** **** *** **** *文件包含****** *** *** ** *****/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/** **** ***** ******宏代换定义****** ****** *** *****/
#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*/
char
function[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"," = "};/*定义各键的显示符号*/
int
ctext[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); /*定义背景色*/