《c语言课程设计计算器设计 .docx》由会员分享,可在线阅读,更多相关《c语言课程设计计算器设计 .docx(14页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、精品名师归纳总结封面可编辑资料 - - - 欢迎下载精品名师归纳总结作者: PanHongliang仅供个人学习C 语言课程设计 _运算器设计#include/*DOS接 口 函 数 */ #include/*数 学 函 数 的 定 义 */ #include/*屏 幕 操 作 函 数 */ #include/*I/O函数*/ #include/*库函数*/可编辑资料 - - - 欢迎下载精品名师归纳总结/*可用颜色的最大数值*/。/*屏幕的最大分辨率*/#include/*变 量 长 度 参 数 表 */ #include/*图形函 数*/ #include/*字 符 串 函 数 */ #i
2、nclude/*字 符 操 作 函 数 */ #defineUP0x48/*光 标 上 移 键 */ #defineDOWN0x50/*光 标 下 移 键 */ #defineLEFT0x4b/*光 标 左 移 键 */ #defineRIGHT0x4d/*光 标 右 移 键 */ #defineENTER 0x0d /* 回 车 键 */ void *rar 。 /* 全 局 变 量 , 保 存 光 标 图 象 */ struct palettetype palette 。 /* 使 用 调 色 板 信 息 */ int GraphDriver 。 /* 图 形 设 备 驱 动 */ int
3、 GraphMode 。 /* 图 形 模 式 值 */ int ErrorCode 。 /* 错 误 代 码 */ int MaxColors 。intMaxX,MaxY边框函数*/始化函数*/doubleAspectRatio。 /*屏 幕 的 像 素 比 */ voiddrawbodervoid。/*画voidinitializevoid。voidcomputervoid。/*/*初。/*获取特殊键函数*/*设置箭头光标函数*/主函数*/main计 算 器 计 算 函 数 */ void changetextstyleint font, int direction, int charsi
4、ze 。 /* 改 变 文 本 样 式 函 数 */ voidmwindowchar*header。/*窗 口 函 数 */ intspecialkeyvoidintarrow。/* intinitialize。/*设置系统进入图形模式*/。/*运/*系统关闭图形。/*计算器*/式返回文本模式*/束程序*/computer行closegraph。模return0结/*设置系统进入图形模式*/ voidinitializevoid纵横比*/显示器*/。统结果*/*/现错误*/intxasp,yasp。/*用于读x和y方向GraphDriver=DETECT。/*自动检测initgraph&Gra
5、phDriver,&GraphMode,/*初始化图形系ErrorCode=graphresult。/*读初始化ifErrorCode.=grOk/*如果初始化时出printfGraphicsSystemError:%sn, grapherrormsgErrorCode。/*显示错误代码*/可编辑资料 - - - 欢迎下载精品名师归纳总结exit1。/*退出*/可编辑资料 - - - 欢迎下载精品名师归纳总结getpalette MaxColors/*读面板信息*/&palette。=getmaxcolor+1。/*读取颜色的最大值*/可编辑资料 - - - 欢迎下载精品名师归纳总结MaxX=
6、getmaxx。/*读屏幕尺寸*/MaxY=getmaxy。/*读屏幕尺寸*/拷贝纵横比到变量中*/。/*计算纵横比值*/函数*/computervoidgetaspectratio&xasp,&yasp。/* AspectRatio=doublexasp/doubleyasp/*计算器voidvp。/*定义视口类型变量*/color,height,width。structviewporttype intintx,y,x0,y0,i,j,v,m,n,act,flag=1。floatnum1=0,num2=0,result。/*操作数和计算结果变量*/ charcnum5,str220=,c,t
7、emp20=。/*定 义字 符串 在按 钮图 形上显示的符号*/。/*显示主窗口*/charstr1=1230.456+-789*/Qc=% mwindowCalculatorcolor=7。/*设置灰颜色值*/ getviewsettings&vp。/*读取当前窗口的大小*/ width=vp.right+1/10。/*设置按钮宽 度 */。/*设置按钮高度*/2。/*设置x的坐标值*/height=vp.bottom-10/10 x=widthy=height/2。/*设置y的坐标值*/setfillstyleSOLID_FILL,color+3。barx+width*2,y,x+7*wi
8、dth,y+height。*/*设置淡绿颜色边框线*/y,x+7*width,y+height。个矩形边框线*/*画一个二维矩形条显示运算数和结果setcolorcolor+3。rectanglex+width*2,/*画一可编辑资料 - - - 欢迎下载精品名师归纳总结/*/*设设置置xy的的坐坐标标值值*/*/。+j/*画按钮*/setcolorRED。/*设outtextxyx+3*width,y+height/2,0.。 x=2*width-width/2。y=2*height+height/2。为红色*/置颜色/*输出字符串0.*/可编辑资料 - - - 欢迎下载精品名师归纳总结fo
9、rj=0。j4fori=0。+icolor。i=x0+6*width/*如 果 右 移 ,移 到 尾 ,就 移 动 到 最 左 边 字 符 位 置 */x=x0。m=0。elsex=x+width+width/2。m+。/*否就,右移到下一个字符位置*/ ifv=LEFT/*左移箭头时新位置计算*/ifx=x0x=x0+6*width。m=4。/*如 果 移 到 头 ,再 左 移 ,就 移 动 到 最 右 边 字 符 位 置 */elsex=x-width-width/2。m-。可编辑资料 - - - 欢迎下载精品名师归纳总结/*否就,ifv=UP/*上y=y+height+height/2e
10、lse。n+。/*否就, putimagex,y,rar,XOR_PUT移到下。/*在新setfillstyleSOLID_FILL边一的位,color+3个置显字示符光位标箭置头*/*/。bar2*width+width/2,height/2,15*wid outtextxy5*width,height,str2。/*num1=atofstr2。/*将第一个操strcpystr2,。/*act=1。/*做计算th/2将,3*height/2显示字符。串*/ ifc=+左移到前一个字符位置*/移箭头时新位置计算*/ify=7*heighty=y0。/*如果移到尾,再下移,n=0就移动到最上边字
11、符位。置 */c=str1n*5+m。/*将字符保存到变量c中*/ifisdigitc|c=./*判断是否是数字或小数点*/ifflag=-1/*如果标志为-1,表明为负数*/strcpystr2,-。/*将负号连接到字符串中*/*将标flag=1志值恢复为。1*/sprintftemp,%c,c。/*将 字符 保 存 到 字符串变量temp中*/strcatstr2,temp。/*将temp中的字符串连接到str2中*/作数转str2换为清浮点空数*/*/加法标志值*/可编辑资料 - - - 欢迎下载精品名师归纳总结setfillstyleSOLID_FILL,color+3。bar2*wi
12、dth+width/2,height/2,15*width/2,3*height/2。outtextxy5*width,height,0.。/*显示字符串*/ ifc=-ifstrcmpstr2,=0/*如 果str2为 空,说 明是 负 号,而 不是减 号 */ flag=-1。/*设置负数标志*/else个操作数转换为浮点数*/将str2清空*/num1=atofstr2。/*将第二strcpystr2,。/*act=2。/*做计算减法标志值*/setfillstyleSOLID_FILL,color+3。bar2*width+width/2,height/2,15*width/2,3*h
13、eight/2。/*画矩形*/ outtextxy5*width,height,0.。/*显示字符串*/ifc=*个操作数转换为浮点数*/将str2清空*/算乘法标志值*/num1=atofstr2。/*将第二strcpystr2,。/* act=3。/*做计setfillstyleSOLID_FILL,color+3。bar2*width+width/2,height/2,15*width/2,3*height/2。outtextxy5*width,height,0.。/*显示字符串*/ifc=/个操作数转换为浮点数*/将str2清空*/num1=atofstr2。/*将第二strcpyst
14、r2,。/*标志值*/。字符串*/act=4。/*做计算除法setfillstyleSOLID_FILL,color+3 bar2*width+width/2,height/2,15*width/2,3*height/2outtextxy5*width,height,0.。/*显示可编辑资料 - - - 欢迎下载精品名师归纳总结个操作数转换为浮点数*/将str2清空*/num1=atofstr2。/*将第二strcpystr2,。/*ifc=可编辑资料 - - - 欢迎下载精品名师归纳总结act=5。/*做计算乘方标志值*/ setfillstyleSOLID_FILL,color+3。/*设
15、置用淡绿色实体填充*/ bar2*width+width/2,height/2,15*width/2,3*height/2。/*画矩形*/ outtextxy5*width,height,0.。/* 显 示 字 符 串 */可编辑资料 - - - 欢迎下载精品名师归纳总结ifc=%作数转str2换为清浮点空数*/*/算乘方标志值*/用淡绿色实体填充*/。/*画矩形*/显示字符串*/num1=atofstr2。/*将第二个操strcpystr2,。/*将计算模运。/*设置act=6。/*做setfillstyleSOLID_FILL,color+3 bar2*width+width/2,heig
16、ht/2,15*width/2,3*height/2 outtextxy5*width,height,0.。/*ifc=num2=atofstr2switchact。/*/*将根第据二个运操作算数符转换号为浮计点算数*/*/case1:result=num1+num2。break。/*做加法*/case2:result=num1-num2。break。/*做减法*/case3:result=num1*num2。break。/*做乘法*/case4:result=num1/num2。break。/*做除法*/case5:result=pownum1,num2。break。/*做x的y次方*/ c
17、ase6:result=fmodnum1,num2。break。/*做模运算*/setfillstyleSOLID_FILL,color+3。/*设置用淡绿色实体填充*/ bar2*width+width/2,height/2,15*width/2,3*height/2。/*覆盖结果区*/可编辑资料 - - - 欢迎下载精品名师归纳总结sprintftemp,%f,result。outtextxy5*width,height,temptemp中*/*将结果保存到。/*显示结果*/ifc=c可编辑资料 - - - 欢迎下载精品名师归纳总结setfillstyleSOLID_FILL,color+
18、3。/*设bar2*width+width/2,height/2,15*width/2,3*height/2置。用淡/*绿覆色盖实体结填充果区*/*/outtextxy5*width,height,0.。/*显示字符串*/ifc=Qexit0。/*如 果选 择了q回车,结束计 算程序*/putimagex,y,rar,XOR_PUT。/*在退return。出/*之前消返去光标回箭头*/*/num1=0。/*将两个操作数复位0,符号标志为1*/num2=0。flag=1。strcpystr2,。/*将str2清空*/*窗口函数*/voidmwindowchar*header可编辑资料 - - -
19、 欢迎下载精品名师归纳总结intheight。cleardevice。/*清除图形屏幕*/为白色*/口大小*/setcolorMaxColors-1。/*设置当前颜色setviewport20,20,MaxX/2,MaxY/2,1。/*设置视height=textheightH。/*读取基本文本大小*/ settextstyleDEFAULT_FONT,HORIZ_DIR,1。/*设置文本样式*/ settextjustifyCENTER_TEXT,TOP_TEXT。 /* 设 置 字 符 排 列 方 式 */ outtextxy MaxX/4, 2, header 。 /* 输 出 标 题
20、*/*设置视口大小*/边框*/setviewport20,20+height+4,MaxX/2+4,MaxY/2+20,1。drawboder。/*画voiddrawbodervoid/*画边框*/struct viewporttype vp 。 /* 定 义 视 口 类 型 变 量 */ setcolor MaxColors - 1 。 /* 设 置 当 前 颜 色 为 白 色 */ setlinestyle SOLID_LINE, 0, NORM_WIDTH 。 /* 设 置 画 线 方 式 */ getviewsettings &vp 。 /* 将 当 前 视 口 信 息 装 入 vp
21、所 指 的 结 构 中 */ rectangle 0, 0, vp.right-vp.left, vp.bottom-vp.top 。 /* 画 矩 形 边 框 */*设计鼠标图形函数*/ intarrowintsize。intraw=4,4,4,8,6,8,14,16,16,16,8,6,8,4,4,4。/*定义多边形坐标*/ setfillstyleSOLID_FILL,2。/*设置填充模式*/ fillpoly8,raw。/*画出一光标箭头*/ size=imagesize4,4,16,16 。 /* 测 试 图 象 大 小 */ rar=mallocsize 。 /* 分 配 内 存
22、区 域 */ getimage4,4,16,16,rar 。 /* 存 放 光 标 箭 头 图 象 */ putimage4,4,rar,XOR_PUT 。 /* 消 去 光 标 箭 头 图 象 */ return 0 。/*按键函数*/ intspecialkeyvoidkey。/*等待键盘输入*/。/*只/*取特键殊键盘的 扫描输值,其入余为*/ 0*/*返回键值*/intwhilebioskey1=0。key=bioskey0。key=key&0xff.key&0xff:key8 returnkey。可编辑资料 - - - 欢迎下载精品名师归纳总结c 语言课程设计 _运算器设计版权申明可
23、编辑资料 - - - 欢迎下载精品名师归纳总结本文部分内容,包括文字、图片、以及设计等在网上搜集整理。版权为潘宏亮个人全部This article includes some parts, including text, pictures, and design. Copyright is Pan Hongliangs personal ownership.用户可将本文的内容或服务用于个人学习、争论或观看,以及其他非商业性或非盈利性用途,但同时应遵守著作权法及其他相关法律的规定,不得侵害本网站及相关权益人的合法权益。除此以 外,将本文任何内容或服务用于其他用途时,须征得本人及相关权益人的书面许可,并支付酬劳。Users may use the contents or services of this article for personal study, research or appreciation, and other non-commercial or non-profit purposes, but at the same time, they shall abide by the provisions of copyright law and