C语言课程设计计算器.docx
《C语言课程设计计算器.docx》由会员分享,可在线阅读,更多相关《C语言课程设计计算器.docx(27页珍藏版)》请在冰豆网上搜索。
C语言课程设计计算器
目录
1前言2
2需求分析2
2.1要求2
2.2任务2
2.3运行环境2
2.4开发工具2
3概要设计2
3.1系统流程图3
3.2查询函数流程图4
4详细设计8
4.1分析和设计8
4.2具体代码实现9
5课程设计总结25
参考文献25
致谢26
1前言
编写一个程序来实现算术计算器。
通过结构体数组和共用体数组来存放输入的每一数字或运算符号的记录(包括1、2、3等数字,+、--、*、等运算符号),然后将其信息存入文件中。
输入一个算术计算式,就在屏幕上显示结果。
2需求分析
2.1要求
(1)用C语言实现程序设计;
(2)利用结构体、共用体进行相关信息处理;
(3)画出查询模块的流程图;
(4)系统的各个功能模块要求用函数的形式实现;
(5)界面友好(良好的人机互交),程序要有注释。
2.2任务
(1)定义一个结构体类型数组,输入0~9及+、--、*等符号的信息,将其信息存入文件中;
(2)输入简单的加减乘除算术计算式,并在屏幕上显示计算结果;
(3)画出部分模块的流程图;
(4)编写代码;
(5)程序分析与调试。
2.3运行环境
(1)WINDOWS2000/XP系统
(2)TurboC2.0编译环境
2.4开发工具
C语言
3概要设计
3.1系统流程图
如图3.1所示。
图3.1系统流程图
开始
调用输入函数init_stack();
N
Y
printf("can'tformthedevice,pressanykeytoleave!
...");
调用左窗口函数menu();
再调用计算器构成函数calculator();
结束
3.2查询函数流程图
4详细设计
4.1分析和设计
在程序的开头部分定义了结构替类型,用来存放按钮信息
structs_button/*按键的结构体*/
{
intsx,sy,ex,ey;
char*head;
intpress;
}button[17];/*图表按键数*/
charfar*vid_mem;
staticinttx=32,ty=3;/*静态变量*/
floatv1=0.0,v2=0.0;
用输入函数input()来输入按键放在s_button数组中。
再定义结构体栈:
structstack/*结构体栈*/
chars[20];
inttos,top;
}stack;
chartag;
用于数据的输入和存放。
进而定义了表格窗口函数,窗口画线函数和边界线函数:
intform_win()/*表格窗口初始化*/
textbackground(WHITE);/*窗口背景颜色*/
clrscr();/*清零*/
draw_win();/*窗口画线*/
active_button();/*窗口按键*/
out_text_win();/*输出文本窗口*/
window_xy(32,3);/*计算结果窗口*
draw_win()/*边框画线窗口*/
………
draw_border(intsx,intsy,intex,intey,intattrib)/*边界线函数*/
通过这些为形成整个界面提供了大的前提。
接着通过“write_char()”,“active_button()”,“write_top()”,“make_button()”,“out_text_win()”,“get_key()”,“window_xy()”等一系列的函数,使得计算器的整个外型呈现了出来。
为了输入方便一些,就接着定义的小键盘的输入函数:
key_choice()把小键盘数字键和运算键的键值通过“get_data(bx,by);send1()”和计算器界面按键连接起来,使得通过小键盘相应的键就能获得计算器相应的值。
下面就定义了文本光标函数:
text_clo()/*文本光标*/
tx--;/*光标向左移*/
if(tx<32)tx++;/*backspace时X不能小于32*/
put_char(tx,ty,'');
}当按“〈-”或:
”backspace”时光标随tx减小而减小。
再就是计算器运算的主程序:
put_string()/*计算机运算函数*/
floatresult;
tx=32;
switch(tag)/*根据运算符号计算*/
case'+':
result=v1+v2;break;/*做加法*/
case'-':
result=v1-v2;break;/*做减法*/
case'*':
result=v1*v2;break;/*做乘法*/
case'/':
result=v1/v2;break;/*做除法*/
default:
result=v1;/*若不计算输出0*/
}
sprintf(stack.s,"%.3f",result);/*输出结果保留小数点后三位*/
通过switch来实现相应的计算,输出保留三位小数的结果。
最后mian()函数:
main()
init_stack();
vid_mem=(charfar*)0xb8000000;
if(!
form_win())
getch();
exit();
menu();
calculator();
通过调用上面定义的函数实现了计算器整个功能。
4.2具体代码实现
源程序代码:
#include"dos.h"
#include"conio.h"
#include"string.h"
#include"stdio.h"
#definenormbut_bor0x80
#definepresbut_but0xb8
#definenormnum_but0x8e
#definepresnum_but0xb9
#definespebut_char0x2c
#definewin_color0xf2
#definewin_char0xfb
init_stack()/*初始化栈*/
stack.tos=0;
stack.top=0;
stack.s[stack.tos]='\0';
push(charch)/*入栈*/
stack.s[stack.tos++]=ch;
pop()/*取栈数据通过*/
if(stack.tos>0)
stack.s[--stack.tos]='\0';
clear_stack()/*清空栈*/
window_xy(32,3);/*计算结果窗口*/
inti;
charfar*t;
char*s="Thisisasimplecalculator!
";/*顶端边框输出的字符*/
draw_border(30,0,79,24,win_color);/*边框的位置和颜色*/
i=(79-30-strlen(s))/2+30;
t=vid_mem+i*2;
for(;*s;)
*t++=*s++;
*t++=win_color;/*顶端字体颜色*/
charfar*t,far*v;
t=vid_mem;
for(i=sx+1;i{v=t+sy*160+i*2;*v++=196;/*每一行上画线确定为直线*/*v=attrib;v=t+ey*160+i*2;*v++=196;/*每一行下画线确定为直线*/*v=attrib;}for(i=sy+1;i{v=t+i*160+sx*2;*v++=179;/*每一列左画线确定为直线*/*v=attrib;v=t+i*160+ex*2;*v++=179;/*每一列由画线确定为直线*/*v=attrib;}write_char(sx,sy,218,attrib);write_char(ex,sy,191,attrib);write_char(sx,ey,192,attrib);write_char(ex,ey,217,attrib);}write_char(intx,inty,charch,intattrib)/*字符输入函数*/{charfar*v;v=vid_mem;v+=x*2+160*y;*v++=ch;*v=attrib;}active_button()/*图表按钮设定函数*/{inti;make_button(0,32,9,38,11,"1");/*每个键对应的位置和数值*/make_button(1,42,9,48,11,"2");make_button(2,52,9,58,11,"3");make_button(3,62,9,67,11,"+");make_button(4,71,9,76,11,"-");make_button(5,32,12,38,14,"4");make_button(6,42,12,48,14,"5");make_button(7,52,12,58,14,"6");make_button(8,62,12,67,14,"*");make_button(9,71,12,76,14,"/");/*“/”的位置*/make_button(10,32,15,38,17,"7");make_button(11,42,15,48,17,"8");make_button(12,52,15,58,17,"9");make_button(13,62,15,67,17,"=");make_button(14,71,15,76,17,"<-");make_button(15,32,18,38,20,"0");/*“0”的位置*/make_button(16,71,18,76,20,"End");for(i=0;i<17;i++){draw_border(button[i].sx,button[i].sy,button[i].ex,button[i].ey,normbut_bor);}for(i=0;i<17;i++){write_top(button[i].sx+1,button[i].sy+1,button[i].ex-1,button[i].head,normnum_but);}}write_top(intx1,inty,intx2,char*s,intattrib){charfar*v,far*t;inti;v=vid_mem;for(i=x1;i<=x2;i++){t=v+y*160+i*2;*t++='';*t=attrib;}i=(x2-x1-strlen(s)+1)/2+x1;t=v+160*y+i*2;for(;*s;){*t++=*s++;*t++=attrib;}}make_button(intnum,intsx,intsy,intex,intey,char*top){button[num].sx=sx;button[num].sy=sy;button[num].ex=ex;button[num].ey=ey;button[num].head=top;button[num].press=0;}out_text_win()/*结果输出窗口*/{draw_border(31,2,75,4,0x7f);write_top(32,3,74,"",0xff);}get_key()/*得到按键值*/{unioninkey/*共用体*/{charch[2];inti;}c;c.i=bioskey(0);return(c.i);}window_xy(intx,inty){unionREGSr;/*定义联合体*/r.h.ah=2;/*初始化*/r.h.dh=y;r.h.dl=x;r.h.bh=0;int86(0x10,&r,&r);}key_choice()/*小键盘键的输入函数*/{intch,bx=0,by=0;/*起始停留键的位置*/do{ch=get_key();switch(ch){case0x4f31:res_but(bx,by);bx=0;by=0;get_data(bx,by);break;/*图表键和小键盘的键对应,此处为1*/case0x5032:res_but(bx,by);bx=1;by=0;get_data(bx,by);break;/*2*/case0x5133:res_but(bx,by);bx=2;by=0;get_data(bx,by);break;/*3*/case0x4b34:res_but(bx,by);bx=0;by=1;get_data(bx,by);break;/*4*/case0x4c35:res_but(bx,by);bx=1;by=1;get_data(bx,by);break;/*5*/case0x4d36:res_but(bx,by);bx=2;by=1;get_data(bx,by);break;/*6*/case0x4737:res_but(bx,by);bx=0;by=2;get_data(bx,by);break;/*7*/case0x4838:res_but(bx,by);bx=1;by=2;get_data(bx,by);break;/*8*/case0x4939:res_but(bx,by);bx=2;by=2;get_data(bx,by);break;/*9*/case0x5230:res_but(bx,by);bx=0;by=3;get_data(bx,by);break;/*0*/case0x4e2b:res_but(bx,by);bx=3;by=0;get_data(bx,by);send1();break;/*加*/case0x4a2d:res_but(bx,by);bx=4;by=0;get_data(bx,by);send1();break;/*减*/case0x372a:res_but(bx,by);bx=3;by=1;get_data(bx,by);send1();break;/*乘*/case0x352f:res_but(bx,by);bx=4;by=1;get_data(bx,by);send1();break;/*除*/case0x0d3d:res_but(bx,by);bx=3;by=2;get_data(bx,by);send2();out_text_win();put_string();break;/*等于号*/case0x1c0d:res_but(bx,by);bx=2;by=4;get_data(bx,by);send2();out_text_win();put_string();break;/*回车键(相当与等于号)*/case0x0e08:res_but(bx,by);bx=4;by=2;pop();text_clo();break;/*退格(backspace)*/case0x3920:res_but(bx,by);get_data(bx,by);ba_space(bx,by);break;/*空格*/case0x4f00:res_but(bx,by);bx=4;by=3;exit(1);break;/*结束(End)*/case0x4800:res_but(bx,by);by--;break;/*上*/case0x4b00:res_but(bx,by);bx--;break;/*左*/case0x5000:res_but(bx,by);by++;break;/*下*/case0x4d00:res_but(bx,by);bx++;break;/*右*/}if(bx<0)bx=0;/*只能在X0到4和Y在0到4内选择按键*/if(by<0)by=0;if(by>4)by=4;if(bx>4)bx=4;/*只能在X0到4和Y在0到4内选择按键*/select_but(bx,by);}while(1);}ba_space(intx,inty){intnum;charch;if(y>2)if(x<2)num=15;elsenum=16;elsenum=x+5*y;switch(num){case3:send1();break;case13:send2();out_text_win();put_string();break;case4:send1();break;case8:send1();break;case9:send1();break;case16:exit(1);break;/*图表对应的结束键*/case14:pop();text_clo();break;/*“〈—”对应功能*/default:;}}text_clo()/*文本光标*/{tx--;/*光标向左移*/if(tx<32)tx++;/*backspace时X不能小于32*/put_char(tx,ty,'');}put_string()/*计算机运算函数*/{floatresult;tx=32;switch(tag)/*根据运算符号计算*/{case'+':result=v1+v2;break;/*做加法*/case'-':result=v1-v2;break;/*做减法*/case'*':result=v1*v2;break;/*做乘法*/case'/':result=v1/v2;break;/*做除法*/default:result=v1;/*若不计算输出0*/}sprintf(stack.s,"%.3f",result);/*输出结果保留小数点后三位*/while(stack.s[stack.top]){put_char(tx,ty,stack.s[stack.top++]);tx++;}}send1()/*向服务器发送请求*/{sscanf(stack.s,"%f",&v1);/*输入并储存在V1中*/clear_stack();/*清除栈*/}send2()/*向服务器发送信息*/{sscanf(stack.s,"%f",&v2);clear_stack();/*清除栈*/}get_data(intx,inty)/*键的移动和对应数值关系*/{intnum;charch;if(y>2)if(x<2)num=15;elsenum=16;/*使得第3行只能取的0键和End键*/elsenum=x+5*y;/*其余各键坐标和原来设定的值的关系*/switch(num)/*使得图表面键和实际键一致*/{case0:ch='1';break;/*图表面1键和实际1一致*/case1:ch='2';break;case2:ch='3';break;case3:ch='+';break;case4:ch='-';break;case5:ch='4';break;case6:ch='5';break;case7:ch='6';break;case8:ch='*';break;case9:ch='/';break;case10:ch='7';break;case11:ch='8';break;case12:ch='9';break;case13:ch='=';break;case15:ch='0';break;/*图表面0键和实际0一致*/default:ch=1;}if(ch!=1){put_char(tx,ty,ch);if(ch!='+'&&ch!='-'&&ch!='*'&&ch!='/')push(ch);elsetag=ch;tx++;}}select_but(intx,inty)/*选择按钮*/{intnum;if(y>
v=t+sy*160+i*2;
*v++=196;/*每一行上画线确定为直线*/
*v=attrib;
v=t+ey*160+i*2;
*v++=196;/*每一行下画线确定为直线*/
for(i=sy+1;i{v=t+i*160+sx*2;*v++=179;/*每一列左画线确定为直线*/*v=attrib;v=t+i*160+ex*2;*v++=179;/*每一列由画线确定为直线*/*v=attrib;}write_char(sx,sy,218,attrib);write_char(ex,sy,191,attrib);write_char(sx,ey,192,attrib);write_char(ex,ey,217,attrib);}write_char(intx,inty,charch,intattrib)/*字符输入函数*/{charfar*v;v=vid_mem;v+=x*2+160*y;*v++=ch;*v=attrib;}active_button()/*图表按钮设定函数*/{inti;make_button(0,32,9,38,11,"1");/*每个键对应的位置和数值*/make_button(1,42,9,48,11,"2");make_button(2,52,9,58,11,"3");make_button(3,62,9,67,11,"+");make_button(4,71,9,76,11,"-");make_button(5,32,12,38,14,"4");make_button(6,42,12,48,14,"5");make_button(7,52,12,58,14,"6");make_button(8,62,12,67,14,"*");make_button(9,71,12,76,14,"/");/*“/”的位置*/make_button(10,32,15,38,17,"7");make_button(11,42,15,48,17,"8");make_button(12,52,15,58,17,"9");make_button(13,62,15,67,17,"=");make_button(14,71,15,76,17,"<-");make_button(15,32,18,38,20,"0");/*“0”的位置*/make_button(16,71,18,76,20,"End");for(i=0;i<17;i++){draw_border(button[i].sx,button[i].sy,button[i].ex,button[i].ey,normbut_bor);}for(i=0;i<17;i++){write_top(button[i].sx+1,button[i].sy+1,button[i].ex-1,button[i].head,normnum_but);}}write_top(intx1,inty,intx2,char*s,intattrib){charfar*v,far*t;inti;v=vid_mem;for(i=x1;i<=x2;i++){t=v+y*160+i*2;*t++='';*t=attrib;}i=(x2-x1-strlen(s)+1)/2+x1;t=v+160*y+i*2;for(;*s;){*t++=*s++;*t++=attrib;}}make_button(intnum,intsx,intsy,intex,intey,char*top){button[num].sx=sx;button[num].sy=sy;button[num].ex=ex;button[num].ey=ey;button[num].head=top;button[num].press=0;}out_text_win()/*结果输出窗口*/{draw_border(31,2,75,4,0x7f);write_top(32,3,74,"",0xff);}get_key()/*得到按键值*/{unioninkey/*共用体*/{charch[2];inti;}c;c.i=bioskey(0);return(c.i);}window_xy(intx,inty){unionREGSr;/*定义联合体*/r.h.ah=2;/*初始化*/r.h.dh=y;r.h.dl=x;r.h.bh=0;int86(0x10,&r,&r);}key_choice()/*小键盘键的输入函数*/{intch,bx=0,by=0;/*起始停留键的位置*/do{ch=get_key();switch(ch){case0x4f31:res_but(bx,by);bx=0;by=0;get_data(bx,by);break;/*图表键和小键盘的键对应,此处为1*/case0x5032:res_but(bx,by);bx=1;by=0;get_data(bx,by);break;/*2*/case0x5133:res_but(bx,by);bx=2;by=0;get_data(bx,by);break;/*3*/case0x4b34:res_but(bx,by);bx=0;by=1;get_data(bx,by);break;/*4*/case0x4c35:res_but(bx,by);bx=1;by=1;get_data(bx,by);break;/*5*/case0x4d36:res_but(bx,by);bx=2;by=1;get_data(bx,by);break;/*6*/case0x4737:res_but(bx,by);bx=0;by=2;get_data(bx,by);break;/*7*/case0x4838:res_but(bx,by);bx=1;by=2;get_data(bx,by);break;/*8*/case0x4939:res_but(bx,by);bx=2;by=2;get_data(bx,by);break;/*9*/case0x5230:res_but(bx,by);bx=0;by=3;get_data(bx,by);break;/*0*/case0x4e2b:res_but(bx,by);bx=3;by=0;get_data(bx,by);send1();break;/*加*/case0x4a2d:res_but(bx,by);bx=4;by=0;get_data(bx,by);send1();break;/*减*/case0x372a:res_but(bx,by);bx=3;by=1;get_data(bx,by);send1();break;/*乘*/case0x352f:res_but(bx,by);bx=4;by=1;get_data(bx,by);send1();break;/*除*/case0x0d3d:res_but(bx,by);bx=3;by=2;get_data(bx,by);send2();out_text_win();put_string();break;/*等于号*/case0x1c0d:res_but(bx,by);bx=2;by=4;get_data(bx,by);send2();out_text_win();put_string();break;/*回车键(相当与等于号)*/case0x0e08:res_but(bx,by);bx=4;by=2;pop();text_clo();break;/*退格(backspace)*/case0x3920:res_but(bx,by);get_data(bx,by);ba_space(bx,by);break;/*空格*/case0x4f00:res_but(bx,by);bx=4;by=3;exit(1);break;/*结束(End)*/case0x4800:res_but(bx,by);by--;break;/*上*/case0x4b00:res_but(bx,by);bx--;break;/*左*/case0x5000:res_but(bx,by);by++;break;/*下*/case0x4d00:res_but(bx,by);bx++;break;/*右*/}if(bx<0)bx=0;/*只能在X0到4和Y在0到4内选择按键*/if(by<0)by=0;if(by>4)by=4;if(bx>4)bx=4;/*只能在X0到4和Y在0到4内选择按键*/select_but(bx,by);}while(1);}ba_space(intx,inty){intnum;charch;if(y>2)if(x<2)num=15;elsenum=16;elsenum=x+5*y;switch(num){case3:send1();break;case13:send2();out_text_win();put_string();break;case4:send1();break;case8:send1();break;case9:send1();break;case16:exit(1);break;/*图表对应的结束键*/case14:pop();text_clo();break;/*“〈—”对应功能*/default:;}}text_clo()/*文本光标*/{tx--;/*光标向左移*/if(tx<32)tx++;/*backspace时X不能小于32*/put_char(tx,ty,'');}put_string()/*计算机运算函数*/{floatresult;tx=32;switch(tag)/*根据运算符号计算*/{case'+':result=v1+v2;break;/*做加法*/case'-':result=v1-v2;break;/*做减法*/case'*':result=v1*v2;break;/*做乘法*/case'/':result=v1/v2;break;/*做除法*/default:result=v1;/*若不计算输出0*/}sprintf(stack.s,"%.3f",result);/*输出结果保留小数点后三位*/while(stack.s[stack.top]){put_char(tx,ty,stack.s[stack.top++]);tx++;}}send1()/*向服务器发送请求*/{sscanf(stack.s,"%f",&v1);/*输入并储存在V1中*/clear_stack();/*清除栈*/}send2()/*向服务器发送信息*/{sscanf(stack.s,"%f",&v2);clear_stack();/*清除栈*/}get_data(intx,inty)/*键的移动和对应数值关系*/{intnum;charch;if(y>2)if(x<2)num=15;elsenum=16;/*使得第3行只能取的0键和End键*/elsenum=x+5*y;/*其余各键坐标和原来设定的值的关系*/switch(num)/*使得图表面键和实际键一致*/{case0:ch='1';break;/*图表面1键和实际1一致*/case1:ch='2';break;case2:ch='3';break;case3:ch='+';break;case4:ch='-';break;case5:ch='4';break;case6:ch='5';break;case7:ch='6';break;case8:ch='*';break;case9:ch='/';break;case10:ch='7';break;case11:ch='8';break;case12:ch='9';break;case13:ch='=';break;case15:ch='0';break;/*图表面0键和实际0一致*/default:ch=1;}if(ch!=1){put_char(tx,ty,ch);if(ch!='+'&&ch!='-'&&ch!='*'&&ch!='/')push(ch);elsetag=ch;tx++;}}select_but(intx,inty)/*选择按钮*/{intnum;if(y>
v=t+i*160+sx*2;
*v++=179;/*每一列左画线确定为直线*/
v=t+i*160+ex*2;
*v++=179;/*每一列由画线确定为直线*/
write_char(sx,sy,218,attrib);
write_char(ex,sy,191,attrib);
write_char(sx,ey,192,attrib);
write_char(ex,ey,217,attrib);
write_char(intx,inty,charch,intattrib)/*字符输入函数*/
charfar*v;
v=vid_mem;
v+=x*2+160*y;
*v++=ch;
active_button()/*图表按钮设定函数*/
make_button(0,32,9,38,11,"1");/*每个键对应的位置和数值*/
make_button(1,42,9,48,11,"2");
make_button(2,52,9,58,11,"3");
make_button(3,62,9,67,11,"+");
make_button(4,71,9,76,11,"-");
make_button(5,32,12,38,14,"4");
make_button(6,42,12,48,14,"5");
make_button(7,52,12,58,14,"6");
make_button(8,62,12,67,14,"*");
make_button(9,71,12,76,14,"/");/*“/”的位置*/
make_button(10,32,15,38,17,"7");
make_button(11,42,15,48,17,"8");
make_button(12,52,15,58,17,"9");
make_button(13,62,15,67,17,"=");
make_button(14,71,15,76,17,"<-");
make_button(15,32,18,38,20,"0");/*“0”的位置*/
make_button(16,71,18,76,20,"End");
for(i=0;i<17;i++)
draw_border(button[i].sx,button[i].sy,button[i].ex,button[i].ey,normbut_bor);
write_top(button[i].sx+1,button[i].sy+1,button[i].ex-1,button[i].head,normnum_but);
write_top(intx1,inty,intx2,char*s,intattrib)
charfar*v,far*t;
for(i=x1;i<=x2;i++)
t=v+y*160+i*2;
*t++='';
*t=attrib;
i=(x2-x1-strlen(s)+1)/2+x1;
t=v+160*y+i*2;
*t++=attrib;
make_button(intnum,intsx,intsy,intex,intey,char*top)
button[num].sx=sx;
button[num].sy=sy;
button[num].ex=ex;
button[num].ey=ey;
button[num].head=top;
button[num].press=0;
out_text_win()/*结果输出窗口*/
draw_border(31,2,75,4,0x7f);
write_top(32,3,74,"",0xff);
get_key()/*得到按键值*/
unioninkey/*共用体*/
charch[2];
}c;
c.i=bioskey(0);
return(c.i);
window_xy(intx,inty)
unionREGSr;/*定义联合体*/
r.h.ah=2;/*初始化*/
r.h.dh=y;
r.h.dl=x;
r.h.bh=0;
int86(0x10,&r,&r);
key_choice()/*小键盘键的输入函数*/
intch,bx=0,by=0;/*起始停留键的位置*/
do
ch=get_key();
switch(ch)
case0x4f31:
res_but(bx,by);bx=0;by=0;get_data(bx,by);break;/*图表键和小键盘的键对应,此处为1*/
case0x5032:
res_but(bx,by);bx=1;by=0;get_data(bx,by);break;/*2*/
case0x5133:
res_but(bx,by);bx=2;by=0;get_data(bx,by);break;/*3*/
case0x4b34:
res_but(bx,by);bx=0;by=1;get_data(bx,by);break;/*4*/
case0x4c35:
res_but(bx,by);bx=1;by=1;get_data(bx,by);break;/*5*/
case0x4d36:
res_but(bx,by);bx=2;by=1;get_data(bx,by);break;/*6*/
case0x4737:
res_but(bx,by);bx=0;by=2;get_data(bx,by);break;/*7*/
case0x4838:
res_but(bx,by);bx=1;by=2;get_data(bx,by);break;/*8*/
case0x4939:
res_but(bx,by);bx=2;by=2;get_data(bx,by);break;/*9*/
case0x5230:
res_but(bx,by);bx=0;by=3;get_data(bx,by);break;/*0*/
case0x4e2b:
res_but(bx,by);bx=3;by=0;get_data(bx,by);send1();break;/*加*/
case0x4a2d:
res_but(bx,by);bx=4;by=0;get_data(bx,by);send1();break;/*减*/
case0x372a:
res_but(bx,by);bx=3;by=1;get_data(bx,by);send1();break;/*乘*/
case0x352f:
res_but(bx,by);bx=4;by=1;get_data(bx,by);send1();break;/*除*/
case0x0d3d:
res_but(bx,by);bx=3;by=2;get_data(bx,by);send2();
out_text_win();put_string();break;/*等于号*/
case0x1c0d:
res_but(bx,by);bx=2;by=4;get_data(bx,by);send2();
out_text_win();put_string();break;/*回车键(相当与等于号)*/
case0x0e08:
res_but(bx,by);bx=4;by=2;pop();text_clo();break;/*退格(backspace)*/
case0x3920:
res_but(bx,by);get_data(bx,by);ba_space(bx,by);break;/*空格*/
case0x4f00:
res_but(bx,by);bx=4;by=3;exit
(1);break;/*结束(End)*/
case0x4800:
res_but(bx,by);by--;break;/*上*/
case0x4b00:
res_but(bx,by);bx--;break;/*左*/
case0x5000:
res_but(bx,by);by++;break;/*下*/
case0x4d00:
res_but(bx,by);bx++;break;/*右*/
if(bx<0)bx=0;/*只能在X0到4和Y在0到4内选择按键*/
if(by<0)by=0;
if(by>4)by=4;
if(bx>4)bx=4;/*只能在X0到4和Y在0到4内选择按键*/
select_but(bx,by);
}while
(1);
ba_space(intx,inty)
intnum;
charch;
if(y>2)
if(x<2)num=15;
elsenum=16;
elsenum=x+5*y;
switch(num)
case3:
send1();break;
case13:
send2();out_text_win();put_string();break;
case4:
case8:
case9:
case16:
exit
(1);break;/*图表对应的结束键*/
case14:
pop();text_clo();break;/*“〈—”对应功能*/
;
while(stack.s[stack.top])
put_char(tx,ty,stack.s[stack.top++]);
tx++;
send1()/*向服务器发送请求*/
sscanf(stack.s,"%f",&v1);/*输入并储存在V1中*/
clear_stack();/*清除栈*/
send2()/*向服务器发送信息*/
sscanf(stack.s,"%f",&v2);
get_data(intx,inty)/*键的移动和对应数值关系*/
elsenum=16;/*使得第3行只能取的0键和End键*/
elsenum=x+5*y;/*其余各键坐标和原来设定的值的关系*/
switch(num)/*使得图表面键和实际键一致*/
case0:
ch='1';break;/*图表面1键和实际1一致*/
case1:
ch='2';break;
case2:
ch='3';break;
ch='+';break;
ch='-';break;
case5:
ch='4';break;
case6:
ch='5';break;
case7:
ch='6';break;
ch='*';break;
ch='/';break;
case10:
ch='7';break;
case11:
ch='8';break;
case12:
ch='9';break;
ch='=';break;
case15:
ch='0';break;/*图表面0键和实际0一致*/
ch=1;
if(ch!
=1)
put_char(tx,ty,ch);
='+'&&ch!
='-'&&ch!
='*'&&ch!
='/')
push(ch);
elsetag=ch;
select_but(intx,inty)/*选择按钮*/
if(y>
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1