计算器源程序

合集下载

简易计算器程序源代码

简易计算器程序源代码

简易计算器程序源代码下面是一个简易计算器程序的源代码,它可以执行基本的四则运算:```python#定义加法函数def add(x, y):return x + y#定义减法函数def subtract(x, y):return x - y#定义乘法函数def multiply(x, y):return x * y#定义除法函数def divide(x, y):if y == 0:return "除数不能为0"else:return x / y#显示菜单print("选择操作:")print("1. 相加")print("2. 相减")print("3. 相乘")print("4. 相除")#获取用户输入choice = input("输入你的选择(1/2/3/4): ")#获取用户输入的两个数字num1 = float(input("输入第一个数字: "))num2 = float(input("输入第二个数字: "))#根据用户选择执行相应操作if choice == '1':print(num1, "+", num2, "=", add(num1, num2))elif choice == '2':print(num1, "-", num2, "=", subtract(num1, num2)) elif choice == '3':print(num1, "*", num2, "=", multiply(num1, num2)) elif choice == '4':print(num1, "/", num2, "=", divide(num1, num2))else:print("请输入有效的选择")```运行这个程序,你将看到一个简易的计算器菜单。

房贷计算器源代码

房贷计算器源代码

房贷计算器源代码:Private Sub Form_Click()Dim n As Integer 'n为贷款月数Dim x As Double, y As Double, sum As Double, k As Double, h As Double'x为月息,y为总息额,sum为本金总额,k为优惠的比例因子,h为平均月供Dim m As Long, s As Long, c As Single 'm为面积数,s为单价,c为贷款成数s = InputBox("请输入每平米单价:", , 3500)m = InputBox("请输入面积数:", , 145)n = InputBox("请输入贷款月数", , 240)x = InputBox("请输入利息额:", , 6.4)k = InputBox("请输入优惠的比例因子", , 0.85)c = InputBox("请输入按揭成数:", , 0.7)x = (x * k / 100) / 12 '将年利换算成月利息sum = s * m * ch = sum * x * ((1 + x) ^ n) / ((1 + x) ^ n - 1)Print "还款总额为:"; Round(h * n, 2)Print "贷款总额为:"; sumPrint "平均月供为:"; Round(h, 2)Print "总利息额度为:"; Round(h * n - sum)End Sub。

计算器编程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); /*返回键值*/}。

最新存款利息计算器源码程序

最新存款利息计算器源码程序

上传一个个人存款利息计算器的jsp源代码,经过调试可以正常使用了,php的空间即可。

界面如下,网络预览百度搜索。

尊重知识版权,请勿随便转载,请注明出处。

附录2 个人存款计算器 jsp源代码<%@page language="java"pageEncoding="GBK"%><!DOCTYPE html PUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="/1999/xhtml"><head><title>个人存款计算器</title><link href="../Styles/styles.css;pvf21b76d3545dc298"rel="Stylesheet" type="text/css"/><script language="javascript">function perSaving(){var amount=document.per_form.amountTextBox.valuevar yrate=document.per_form.yRateTextBox.valuevar term=document.per_form.termTextBox.valueif (amount==""){ alert("请输入存款金额!")document.per_form.amountTextBox.focus()window.event.returnValue = false;return}if (yrate==""){alert("请输入年利率或选择期限种类!")document.per_form.yRateTextBox.focus()window.event.returnValue = false;return}if (term==""){alert("请输入存期!")document.per_form.termTextBox.focus()window.event.returnValue = false;return}if(isNaN(amount)){alert("请输入数字!")document.per_form.amountTextBox.focus()window.event.returnValue = false;return}if(isNaN(yrate)){alert("请输入数字!")document.per_form.yRateTextBox.focus()window.event.returnValue = false;return}if(isNaN(term)){alert("请输入数字!")document.per_form.termTextBox.focus()window.event.returnValue = false;return}var taxrate=0.00;var interest=amount*yrate*term*0.01/12var tax=taxrate*amount*yrate*term*0.01/12var result=amount*(1+(1-taxrate)*yrate*term*0.01/12)interest=Math.round(interest*100)interest=interest/100interest=interest+""document.per_form.interestTextBox.value=interesttax=Math.round(tax*100)tax=tax/100tax=tax+""document.per_form.taxTextBox.value=taxresult=Math.round(result*100)result=result/100result=result+""document.per_form.resultTextBox.value=resultwindow.event.returnValue = false;}</script><script language="javascript">function checkTerm(){var during=document.per_form.duringDropDownlist.valuevar currencyDropDownList=document.per_form.currencyDropDownList.valueif(currencyDropDownList=="人民币"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.5000";}if(during=="通知存款一天"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.9500"; }if(during=="通知存款七天"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="1.4900"; }if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="3.1000"; }if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="3.3000"; }if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="3.5000"; }if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="4.4000"; }if(during=="整存整取三年"){document.per_form.termTextBox.value ="36";document.per_form.yRateTextBox.value="5.0000"; }if(during=="整存整取五年"){document.per_form.termTextBox.value ="60";document.per_form.yRateTextBox.value="5.5000"; }if(during=="零存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="3.1000"; }if(during=="零存整取三年"){document.per_form.termTextBox.value ="36";document.per_form.yRateTextBox.value="3.3000"; }if(during=="零存整取五年"){document.per_form.termTextBox.value ="60";document.per_form.yRateTextBox.value="3.5000"; }if(during=="整存零取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="3.1000"; }if(during=="整存零取三年"){document.per_form.termTextBox.value ="36";document.per_form.yRateTextBox.value="3.3000"; }if(during=="整存零取五年"){document.per_form.termTextBox.value ="60";document.per_form.yRateTextBox.value="3.5000"; }if(during=="零存零取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="3.1000";}if(during=="零存零取三年"){document.per_form.termTextBox.value ="36";document.per_form.yRateTextBox.value="3.3000";}if(during=="零存零取五年"){document.per_form.termTextBox.value ="60";document.per_form.yRateTextBox.value="3.5000";}if(during=="存本取息一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="3.1000";}if(during=="存本取息三年"){document.per_form.termTextBox.value ="36";document.per_form.yRateTextBox.value="3.3000";}if(during=="存本取息五年"){document.per_form.termTextBox.value ="60";document.per_form.yRateTextBox.value="3.5000";}}if(currencyDropDownList=="美元"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.1000";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.2500";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="0.5000";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="0.7500";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="1.2500";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="1.2500";}}if(currencyDropDownList=="英镑"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.1250";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.2180";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="0.8050";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="0.9760";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="1.0760";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="1.0760";}}if(currencyDropDownList=="欧元"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.1000";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.7500";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="1.0000";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="1.1250";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="1.2500";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="1.3125";}}if(currencyDropDownList=="日元"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.0001";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="0.0100";}}if(currencyDropDownList=="港币"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.0200";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.1500";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="0.4000";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="0.5000";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="0.8000";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="1.1000";}}if(currencyDropDownList=="加拿大元"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.0400";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.2165";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="0.3915";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="0.5100";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="0.7315";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="0.7315";}}if(currencyDropDownList=="瑞士法郎"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.0001";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="0.0100";}}if(currencyDropDownList=="澳大利亚元"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.2375";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="1.2400";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="1.3875";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="1.5075";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="1.5750";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="1.5750";}}if(currencyDropDownList=="新加坡元"){if(during=="活期"){document.per_form.termTextBox.value ="";document.per_form.yRateTextBox.value="0.0001";}if(during=="整存整取一个月"){document.per_form.termTextBox.value ="01";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取三个月"){document.per_form.termTextBox.value ="03";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取半年"){document.per_form.termTextBox.value ="06";document.per_form.yRateTextBox.value="0.7500";}if(during=="整存整取一年"){document.per_form.termTextBox.value ="12";document.per_form.yRateTextBox.value="0.0100";}if(during=="整存整取二年"){document.per_form.termTextBox.value ="24";document.per_form.yRateTextBox.value="0.0100";}}}</script></head><body><form name="per_form"method="post"action="xxx_check.jsp"id="per_form"><div><table class="black"cellSpacing="0"cellPadding="0"width="723" border="0"><tr><td vAlign="top"height="366"><table cellSpacing="0"cellPadding="0"width="100%"align="middle"borderColorDark="#ffffff"borderColorLight="#cccccc"border="1"><tr bgColor="#e0e0e0"><td colSpan="4"height="30"><div class="20"align="center"><font color="#cc0000"><strong>个人存款计算器</strong></font></div></td></tr><tr><td align="center"valign="top"><br><table cellSpacing="0"bgColor="#ffffff"borderColorDark="#ffffff"cellPadding="3"width="80%"borderColorLight="darkgray"border="1"><tr><td align="right"><span class="content">币种</span></td><td align="left"><select name="currencyDropDownList" onchange="on_currencyDropDownList_selected()"id="currencyDropDownList"> <option selected="selected"value="人民币">人民币</option><option value="美元">美元</option><option value="英镑">英镑</option><option value="欧元">欧元</option><option value="日元">日元</option><option value="港币">港币</option><option value="加拿大元">加拿大元</option><option value="瑞士法郎">瑞士法郎</option><option value="澳大利亚元">澳大利亚元</option><option value="新加坡元">新加坡元</option></select></td></tr><tr><td align="right"><span class="content">期限种类</span></td><td align="left"><select name="duringDropDownlist" onchange="javascript:checkTerm();"id="duringDropDownlist"> <option selected="selected"value="请选择期限种类">请选择期限种类</option> <option value="活期">活期</option><option value="通知存款一天">通知存款一天</option><option value="通知存款七天">通知存款七天</option><option value="整存整取三个月">整存整取三个月</option><option value="整存整取半年">整存整取半年</option><option value="整存整取一年">整存整取一年</option><option value="整存整取二年">整存整取二年</option><option value="整存整取三年">整存整取三年</option><option value="整存整取五年">整存整取五年</option><option value="零存整取一年">零存整取一年</option><option value="零存整取三年">零存整取三年</option><option value="零存整取五年">零存整取五年</option><option value="整存零取一年">整存零取一年</option><option value="整存零取三年">整存零取三年</option><option value="整存零取五年">整存零取五年</option><option value="存本取息一年">存本取息一年</option><option value="存本取息三年">存本取息三年</option><option value="存本取息五年">存本取息五年</option></select></td></tr><tr><td align="right"><span class="content">存款金额</span></td><td align="left"><input name="amountTextBox"type="text"id="amountTextBox"style="width:130px;"/><spanclass="content">元</span></td></tr><tr><td align="right"><span class="content">年利率</span></td><td align="left"><input name="yRateTextBox"type="text"id="yRateTextBox"style="color:#404040;width:130px;"/><span class="content">(%)</span></td></tr><tr><td align="right"><span class="content">存期</span></td><td align="left"><input name="termTextBox"type="text"id="termTextBox"style="width:130px;"/><span class="content">月</span></td></tr><tr bgColor="#e0e0e0"><td align="right"><span class="content">利息</span></td><td align="left"><input name="interestTextBox"type="text"readonly="readonly"id="interestTextBox"style="width:130px;" /><span class="content">元</span></td></tr><tr bgColor="#e0e0e0"><td align="right"><span class="content">扣除利息税</span></td><td align="left"><input name="taxTextBox"type="text"readonly="readonly"id="taxTextBox"style="width:130px;"/><span class="content">元</span></td></tr><tr bgColor="#e0e0e0"><td align="right"><span class="content">本息合计(税后)</span></td><td align="left"><input name="resultTextBox"type="text"readonly="readonly"id="resultTextBox"style="width:130px;" /><span class="content">元</span><input type="image"name="calculateImageButton" id="calculateImageButton"src="../images/calculator_button.gif"alt="计算"align="bottom"onclick="javascript:perSaving();"style="height:21px;border-width:0px;"/></td></tr></table><br></td></tr></table></td></tr></table><P></P></div></form><script type="text/javascript"><!--var data = {};data['人民币'] = ['活期','通知存款一天','通知存款七天', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年', '整存整取三年', '整存整取五年', '零存整取一年', '零存整取三年', '零存整取五年','整存零取一年', '整存零取三年', '整存零取五年', '存本取息一年', '存本取息三年', '存本取息五年' ];data['美元'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['英镑'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['欧元'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['日元'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['港币'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['加拿大元'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['瑞士法郎'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['澳大利亚元'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];data['新加坡元'] = ['活期', '整存整取一个月', '整存整取三个月','整存整取半年','整存整取一年','整存整取二年'];var currencyDropDownList=document.getElementById('currencyDropDownList');var duringDropDownlist = document.getElementById('duringDropDownlist'); function on_currencyDropDownList_selected(){var children = data[currencyDropDownList.value];duringDropDownlist.innerHTML = '';var str = '';for(var i in children){var c = children[i];var opt = document.createElement("option");opt.value = c;opt.innerHTML = c;duringDropDownlist.appendChild(opt);}}//--></script></body></html>。

FX5800计算器公路测量常用程序2.1版及详细说明

FX5800计算器公路测量常用程序2.1版及详细说明

FX5800计算器公路测量常用程序2.1版及详细说明一、程序功能主要功能:采用线元法与交点法相结合计算多条线路坐标正反算,可算任意复杂线型及立交匝道,包括C型,S型、卵型、回头曲线等;极坐标放样,全线路基边坡开挖口及坡脚放样计算、路基任意点设计高程、横坡、设计半幅宽度.隧道欠超挖放样计算。

新版本特点:1、建主程序合并原所有计算类型,在主程序中可选择操作类型。

隧道欠超挖增加变量衬砌厚度,因有设计衬砌厚度根据石岩来定的。

增加锥坡放样计算。

二、源程序1.总主程序(1、坐标计算放样程序2、坐标反算程序;3、高程计算查阅程序;4、路基半幅标准宽度查阅程序;5、路基边坡及开挖口放样程序;6、路基标准距离放样;7、桥梁锥坡计算放样程序;8、极坐标计算程序;9、隧道超欠挖计算程序)运行后输入1~9数子则选择1至9的程序,返回时,在桩号输入-1,返回选择选择计算类型。

输入-2,返回选择线路。

坐标计算中输入-3,则显示本段曲线要素。

程序名:0ZCXLbI Q: 15→DimZ:Norm 2:1→A:"A:XY=1, ZD=2 ,GC=3, GD=4,BP=5, FM=6, ZP=7, JS=8, SD=9"?A:A=1=>Goto 1:A=2=>Goto 2:A=3=>Goto 3:A=4=>Goto 4:A=5=>Goto 5:A=6=>Goto 6:A=7=>Goto 7:A=8=>Goto 8:A=9=>Goto 9LbI 1:Prog "DX":LbI A:Prog"QX":90→B: "PJ1"?B:B→C: "PJ2"?C:B→Z[1]:C→Z[8]:LbI B:1→F: "KM"?Z:Z= -1=>Goto 0:Z=-2=>Goto A:Z=-3=>Goto X:Prog"KM":?D:Porg"THB":O→L: "L0"?L:Z[2]+Z[1]-Z[8] →E:X+L cos(E) →X:Y+Lsin(E) →Y:Prog"XY":Prog"JS":Goto BLbI 2:2→F:90→Z[1]:Prog"QX":LbI C: "KM"?Z:Z=-1=>Goto 0:Z=-2=>Goto 2:Z=-3=>Goto X:Prog"KM": "XO"? X: "Y0"?Y:Prog"THB":Porg"ZD":Goto C:LbI 3:Prog"QX":0→B: "H-B"?B:B→Z[9]:LbI D: "KM"?Z: Z=-1=>Goto 0:Z=-2=>Goto 3:?D:Porg"H":Fix 3: " H=":Lc oate 6,4,H-Z[9] ◢" I=":Locate 6,4,I◢ Goto DLbI 4:Prog"QX":LbI E: "KM"?Z:Z=-1=>Goto 0:Z=-2=>Goto 4:?D:Prog"GD":Fix 3: " SJGD=":Locate7,4,L◢ Goto ELbI 5:Prog"QX":0.5→B:"TH-GD"?B:B→Z[15]:LbI F:2→F:90→Z[1]:"KM"?Z:Z=-1 =>Goto 0:Z=-2 =>Goto 5:Prog"KM": "X0"?X: "Y0"?Y:0→M:”M0”?M: M→Z[4]:Prog"3FBZ"Fix 2:Z[3] →D:Abs(D)-S→O: " L0=":Locate 6,4,O◢Prog"ZD": Z[5]→T:" TW=":Lcoate 6,4,T◢ Goto F:LbI 6:Prog"DX":LbI G:Prog"QX":LbI H:1→F:90→Z[1]: "KM"?Z:Z=-1=>Goto 0:Z=-2=>Goto G:Prog"KM":?D:Prog"THB":Prog"XY":Prog"JS":Prog"H":0→M: "M0"?M:Fix 2:H-M→T: " TW=":Locate 6,4,T◢ Goto H:LbI 7:Prog"DX":LbI I:Prog"QX":0→D: "LD:Z-,Y+"? D:Abs(D) →R: "LR"?R: "Z0"?Z: D→Z[6]:R→Z[7]:Z→Z[8]:LbIJ:0→Y: "L0:SZ+,DZ-"?Y:Y=-1=>Goto 0:Y=-2=>Goto I:Prog"ZP":Goto J:LbI 8:Prog"DX":LbI K:?X:X=-1=>Goto 0:X=-2=>Goto 8:?Y:Prog"JS":Goto K:LbI 9:Porg"DX":LbI L:Prog”QX”:LbI M:2→F:90→Z[1]: "KM"?Z:Z=-1=>Goto 0:Z=-2=>Goto L:Z=-3=>Goto X: Prog"SD1":0.5→A:“CQHD"?A:“X0"?X:"Y0"?Y:0→M="M0"?M:M→Z[8]:A→Z[15]:Prog"5SD": Goto M:LbI X:Mat F◢ Goto 02、次程序:路基开挖边线及填方坡脚线放样程序(输入填方放宽值、大概桩号及测量坐标、地面标高计算出偏移距离、桩号、距中距离、填挖高度)程序名:3FBXProg”THB”:D→P:Prog”GD”:If D<0:Then 0.75-L→D:Goto H:E lse L-0.75→D:Goto H:IfEndLbI H:Prog“H”:H-0.03-Z[4] →Z[4]: Prog “W1”:If Z[4]<0: Then –Z[4] →G:Goto W:Else Z[4] →G:Goto T:LbI W:Z[8]+Z[9] →A: If G>A:Then Goto 1:Else If G>Z[8]:The n Goto 2:Else Goto 3:IfEnd:LbI 1:L+Z[10]+Z[11]+Z[12]+(G-A)×Z[7]+Z[9]×Z[6]+Z[8]×Z[5]→S:Goto Z:LbI 2:L+Z[10]+Z[11]+(G-Z[8])×Z[6]+Z[8]×Z[5] →S:Goto Z: LbI 3:L+Z[10]+G×Z[5] →S:Goto Z:LbI T:L+Z[17]→T:If G>Z[15]:Then (T+Z[16]+(G-Z[15])×Z[14] +Z[15]×Z[13])→S:Goto Z:Else (T+G×Z[13])→S:Goto Z:LbI Z3.次程序3.隧道超欠挖值计算放样程序(输入隧道线路,大概桩号、输入衬砌厚度、测量三维坐标,计算准确桩号及位置、计算欠超挖值)程序名:5SDProg”KM”:Prog“THB”: D→Z[13]:0→D:Prog“H”:Cos(Z[10]) ×Z[4] →E: H+Z[5] →Z[5]: H+Z[7] →Z[7]: E+Z[5] →Z[10]:I f Z[8]>Z[10]:Then Goto R:Else Goto S:IfEnd:LbI R:√((Z[13]-Z[9]) 2+(Z[8]-Z[5]) 2 )- Z[4]-Z[15] →L:Goto L:LbI S:Z[4]-Z[6] →S:√(S 2-(Z[7]-Z[5]) 2 ) ×S÷Abs(S)→T:Abs(Z[13]-Z[9])-T→T:√(T 2+(Z[8]-Z[7]) 2 )- Z[6]-Z[15] →L:Goto L:LbI L: Fix 2:” L0=”: Locate 6,4,L◢Prog”ZD”:“ H0=”: Locate 6,4,Z[8]-H◢4:极坐放样计算程序(计算放样点至置仪点方位角及距离)程序名:JSX:Y:Z[11]→K:Z[12]→L:Pol(X-K, Y-L):IF J<0:Then J+360→J:IFEnd:Int(J)+0.01Int(60Frac(J))+0.006Frac(60Frac(J)) →J: Fix 4:” FWJ=”: Locate 6,4,J◢F ix 3:” S=”:Locate 6,4,I◢5.路基宽度子程序6:路基标准半幅宽度计算程序(对于设计有加宽渐变的有用,如路基宽度无变化,则把此程序直接输入半幅宽度值至L)程序名: GD1→S: Prog “G1”:Z-C→E:(B-A)*E/S+A→L:6.坐标计算次程序(THB)程序名:THBIf Q=2:Then Goto J: Else 1÷P→C:(P-R)÷(2HPR)→S:180÷Π→E:If F=1:Then Abs(Z-0) →W:Prog "A":Goto 2:El se X→I:Y→J:Prog "B":O+W→Z:D→D:Goto 2: IfEnd:LbI J: If F=1:Then Prog "Z":Goto 1:Else Prog "ZX":Go to 2: IfEnd:LbI 1:I+D×COS(Z[2]+Z[1]) →X: J+D×Sin(Z[2]+Z[1]) →Y: Lb I 27. 线元法正算子程序(A)程序名:A0.1184634425→A: 0.2393143352→B:0.2844444444→N:0.0469 10077→K: 0.2307653449→L:0.5→M: U+W(Acos(G+QEKW(C+KW S))+Bcos(G+QELW(C+LWS))+Ncos(G+QEMW(C+MWS))+Bcos(G+QE(1 -L)W(C+(1-L)WS))+Acos(G+QE(1-K)W(C+(1-K)WS))) →X:V+W(Asin(G+QEKW(C+KWS))+Bsin(G+QELW(C+LWS))+Nsin(G+QEMW (C+MWS))+Bsin(G+QE(1-L)W(C+(1-L)WS))+Asin(G+QE(1-K)W(C+(1-K)WS))) →Y:G+QEW(C+WS)→Z[2]:X+Dcos(Z[2]+ Z[1])→X: Y+Dsin(Z[2]+ Z[1])→Y8. 线元法反算子程序(B)程序名:BG-90→T: Abs((Y-V)cos(T)-(X-U)sin(T)) →W: 0→D:Lbl 0:Prog "A": T+QEW(C+WS) →L: (J-Y)cos(L)-(I-X)sin(L)→D:IF Abs(D)<0.01:Then Goto 1:Else W+D→W:Goto 0: If End:←┘Lbl 1:0→D:Prog "A":(J-Y)÷sin(Z[2]+90) →D9. 交点法正算子程序(Z)程序名:ZH2÷R÷24-H∧(4) ÷2688÷R∧(3)→A:H÷2-H∧(3) ÷240÷R2→B:(R+A)tan(Abs(P) ÷2)+B→T:O-T→C:C+H→L:L+ΠR×Abs(P) ÷180→N:N-H→E:P÷Abs(P) →W:0→M:If Z<C:Then Z-O→S:G→Z[2]:Goto 2: IfEnd: If Z≥N:Then Z-N+T→S:G+P→Z[2]:Goto 2: IfEnd: If Z≥E:Then N-Z→S:Prog“HX”:G+P→S:S-WK→Z[2]:U+(T-A)Cos(S)-WBSin(S)→I:V+(T-A)Sin(S)+WBcos(S)→J:Goto 3: IfEnd:If Z>L:Then 180(Z-L+0.5H) ÷R÷Π→S :H÷2-H∧(3) ÷240÷R2+Rsin(S)→A:H2÷R÷24-H∧(4) ÷2688÷R∧(3)+R(1-Cos(S))→B:R→M:G+WS→Z[2]:Goto 4: IfEnd:Z-C→S:Prog “HX”:G+WK→Z[2]:LbI 4:U+(A-T)cos(G)-WBsin(G)→I:V+(A-T)Sin(G)+WBcos(G) →J:Goto 3:LbI 2:U+Scos(Z[2])→I:V+Ssin(Z[2]) →J: LbI 310. 交点法缓和段转化子程序(HX)程序名:HXS-S∧(5) ÷40÷R2÷H2+S∧(9) ÷3456÷R∧(4) ÷H∧(4)→A:S∧(3) ÷6÷R÷H-S∧(7) ÷336÷R∧(3) ÷H∧(3)+S∧(11) ÷42240÷R∧(5)÷H∧(5)→B:90S2÷Π÷R÷H→K:RH÷S→M11. 交点法反算子程序(ZX)程序名:ZXZ:0→D:LbI 0:Prog “Z”:Pol(X-I,Y-J):J-Z[2] →J:Isin(J) →S: Icos(J) →I:If Abs(I)<0.1:Then Z+I→Z:S→D:Goto 2:Else Got o 1: LbI 1:If M=0:Then Z+I→Z:Goto 0:Eles Pol(M-WS,I):(JM Π)/180→I:Z+I→Z:Goto 0:IfEndLbI 212.高程计算子程序(H)程序名:HP rog “S1”:C-T→F:Z-F→S:C+T→E:G-TI→Q:If T=O:Then Q+SI →H:Goto 0:Else If Z<F:Then Q+SI→H:Goto 0:Else If Z≤E:Th en Q+SI+S2÷2÷R→H:Goto 0:LbI 0:H:If D=0:Then Goto I:Else Prog “I”:H+V→H:Goto I:L bI I13.高程超高计算程序(I)程序名:IIf Z[3]=1:Then Prog “I1”:Goto 1:Else Prog “I2”:Goto1:IfEnd:LbI 1: If W=1:Then:Goto Z:Else:Goto X: IfEndLbI Z:If S=0:Then Abs(D)×M→V:Goto 2:Else Abs(D)×((N-M)×(Z-C)÷S+M)→V:Goto 2:IfEnd:LbI X:If S=0:Then Abs(D)×M→V:Goto 2:Else Abs(D)×(((3((Z-C)÷S)2-2((Z-C)÷S)∧(3))×(N-M))+M)→V:Goto 2:IfEnd:LbI 2:Abs(D)→E:V÷E→I:I(E-K)→V14.导线点子程序(DX)程序名:DXZ[11] →K:Z[12] →L:“X Z”?K:”YZ”?L:K→Z[11]:L→Z[12]15.线路选择子程序(线路选择输0时。

易语言计算器源码(学习)

易语言计算器源码(学习)

. 版本2.程序集窗口程序集1.子程序_按钮1_被单击显示框.加入文本(“1”).子程序_按钮2_被单击显示框.加入文本(“2”).子程序_按钮3_被单击显示框.加入文本(“3”).子程序_按钮4_被单击显示框.加入文本(“4”).子程序_按钮5_被单击显示框.加入文本(“5”).子程序_按钮6_被单击显示框.加入文本(“6”).子程序_按钮7_被单击显示框.加入文本(“7”).子程序_按钮8_被单击显示框.加入文本(“8”).子程序_按钮9_被单击显示框.加入文本(“9”).子程序_按钮0_被单击显示框.加入文本(“0”).子程序_按钮点_被单击显示框.内容=显示框.内容+“.”.子程序_按钮加_被单击第一个数.内容=显示框.内容符号框.内容=“+”显示框.内容=“”.子程序_按钮减_被单击第一个数.内容=显示框.内容符号框.内容=“-”显示框.内容=“”.子程序_按钮乘_被单击第一个数.内容=显示框.内容符号框.内容=“*”显示框.内容=“”.子程序_按钮除_被单击第一个数.内容=显示框.内容符号框.内容=“/”显示框.内容=“”.子程序_按钮等于_被单击.如果(符号框.内容=“+”)显示框.内容=到文本(到数值(第一个数.内容) +到数值(显示框.内容)).否则.如果(符号框.内容=“-”)显示框.内容=到文本(到数值(第一个数.内容) -到数值(显示框.内容)) .否则.如果(符号框.内容=“*”)显示框.内容=到文本(到数值(第一个数.内容) ×到数值(显示框.内容)).否则.如果(显示框.内容≠“0”).如果(符号框.内容=“/”)显示框.内容=到文本(到数值(第一个数.内容) ÷到数值(显示框.内容)).否则.如果结束.否则信息框(“错误,被除数不能为0 ”, 0, ).如果结束.如果结束.如果结束.如果结束.子程序_按钮清空_被单击显示框.内容=“”.子程序_按钮清空_被双击, 逻辑型.参数横向位置, 整数型.参数纵向位置, 整数型.参数功能键状态, 整数型第一个数.内容=“”/book_3869.html。

用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>#definePI3.141593BOOLA_Op=FALSE;BOOLWINAPIMain_Proc(HWNDhWnd,UINTuMsg,WPARAMwParam,LPARAMlParam) {switch(uMsg){HANDLE_MSG(hWnd,WM_INITDIALOG,Main_OnInitDialog);HANDLE_MSG(hWnd,WM_COMMAND,Main_OnCommand);HANDLE_MSG(hWnd,WM_CLOSE,Main_OnClose);}returnFALSE;}BOOLMain_OnInitDialog(HWNDhwnd,HWNDhwndFocus,LPARAMlParam){returnTRUE;}voidTrimNumber(chara[])//判断并删除小数点后无用的零{for(unsignedi=0;i<strlen(a);i++){if(a[i]=='.'){for(unsignedj=strlen(a)-1;j>=i;j--){if(a[j]=='0'){a[j]='\0';}elseif(a[j]=='.'){a[j]='\0';}elsebreak;}}}}doubleOperate(charOperator,doublen1,doublen2)//判断符号,进行相应的运算{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;}////////////////////////////////////////////////voidIntBinary(chara[],intn){if(n>1)IntBinary(a,n/2);sprintf(a,"%s%i",a,n%2);}voiddecimal(chara[],doublem){if(m>0.000001){m=m*2;sprintf(a,"%s%d",a,(long)m);decimal(a,m-(long)m);}}voidBinary(chara[],doubleNum){charDecP[256]="";doublex,y;double*iptr=&y;x=modf(Num,iptr);decimal(DecP,x);IntBinary(a,(int)y);strcat(a,".");strcat(a,DecP);}////////////////////////////////////voidMain_OnCommand(HWNDhwnd,intid,HWNDhwndCtl,UINTcodeNotify) {staticDELTIMES=0;staticcharstr[256];staticcharOperator='0';staticdoubleRNum[3];switch(id){caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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{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;caseIDC_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;caseIDC_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;caseIDC_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;caseIDC_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{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;caseIDC_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;caseIDC_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;caseIDC_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{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{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;caseIDC_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{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{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{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;caseIDC_BUTTONLN://lnx{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;caseIDC_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;caseIDC_BUTTONBINARY://十进制转换为二进制{chara[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{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{GetDlgItemText(hwnd,IDC_EDIT,str,sizeof(str));inti=strlen(str);str[i-1]='\0';SetDlgItemText(hwnd,IDC_EDIT,str);}break;case{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;}}voidMain_OnClose(HWNDhwnd){EndDialog(hwnd,0);}本人拙作,如有不足之处请谅解。

测量计算器程序

测量计算器程序

一、程序功能本程序由6个主程序、5个次子程序及5个参数子程序组成。

主要用于公路测量中坐标正反算,设计任意点高程及横坡计算,桥涵放样,路基开挖口及填方坡脚线放样。

程序坐标计算适应于任何线型.二、源程序1.主程序1:一般放样反算程序(①正算坐标、放样点至置仪点方位角及距离;②反算桩号及距中距离)程序名:1ZD-XYLb1 0:Norm 2F=1:(正反算判别,F=1正算,F=2反算,也可以改F前加?,改F为变量)Z[1]=90(与路线右边夹角)Prog"THB":F=1=>Goto 1:F=2=>Goto 2Lb1 1:Fix 3:"X=":Locate 6,4,X◢"Y=":Locate 6,4,Y◢Prog"3JS”:Goto 0:Lb1 2:Fix 3:"KM=":Locate 6,4,Z◢"D=":Locate 6,4,D◢Goto 02.主程序2:高程序横坡程序(设计任意点高程及横坡)程序名:2GCLbI 0:Norm 2“KM”?Z:?D:Prog”H”:Fix 3:”H=”:Locate 6,4,H◢“I=”: Locate 6,4,I◢Goto 03.主程序3:极坐放样计算程序(计算放样点至置仪点方位角及距离)程序名:3JSX:Y:1268.123→K(置仪点X坐标)2243.545→L(置仪点Y坐标,都是手工输入,也可以建导线点数据库子程序,个人认为太麻烦)Y-L→E:X-K→F:Pol(F,E):IF J<0:Then J+360→J:Int(J)+0.01Int(60Frac(J))+0.006Frac(60Frac(J)) →J:(不习惯小数点后四位为角度显示的,也可以用命令J◢DMS◢来直接显示) Fix 4:” FWJ=”: Locate 6,4,J◢(不习惯小数点后四位为角度显示的,也可以用命令J◢DMS◢来直接显示)Fix 3:”S=”:Locate 6,4,I◢4.主程序4:涵洞放样程序(由涵中心桩号计算出各涵角坐标、在主程序3中输入置仪点坐标后计算放样点至置仪点方位角及距离)程序名:4JH-XYLbI 0:Norm 290→Z[1](涵洞中心桩与右边夹角,手工输入,也可以修改成前面加?后变为变量)1→F:Prog”THB”:?L:Z[2]-Z[1] →E:X+Lcos(E) →X:Y+Lsin(E) →Y:Fix 3: "X=":Locate 6,4,X◢"Y=":Locate 6,4,Y◢Prog"3JS”:Goto 0:5.主程序5:路基开挖边线及填方坡脚线放样程序(输入大概桩号及测量坐标、地面标高计算出偏移距离、桩号、距中距离、填挖高度)程序名:5FBXLbI 0:Norm 2: 18→DimZ:2→F:90→Z[1]:Prog “THB”:Z:D:”M0”?M:M→Z[4]:D→Z[3]:Prog”6GD”:L→Z[6]:If D<0:Then 0.75-L→D:Goto H:Else L-0.75→D:Goto H:IfEndLbI H:Prog”H”:H-0.03-Z[4] →Z[5]:Z[6] →L:If Z[5]<0:Then –z[5] →G:Goto W:Else Z[5] →G:Goto T:LbI W:Prog “W0”:Z[10]+Z[11] →A: If G>A:Then Goto 1:Else If G>Z[10]:Then Goto 2:Else Goto 3:IfEnd:LbI 1:L+Z[12]+Z[13]+Z[14]+(G-A)×Z[9]+Z[11]×Z[8]+Z[10]×Z[7]:Goto Z:LbI 2:L+Z[12]+Z[13]+(G-Z[10])×Z[8]+Z[10]×Z[7]:Goto Z:LbI 3:L+Z[12]+G×Z[7]:Goto z:LbI T:L+0.5→N:If G>Z[17]:Then (N+Z[18]+(G-Z[17])×Z[16]+Z[17]×Z[15])→S:Goto Z:Else (N+G×Z[15])→S:Goto z:LbI Z:Z[3]→D:Fix 2:A bs(D)-S→T:”L0=”:L Locate 6,4,T◢"KM=":Locate 6,4,Z◢"D=":Locate 6,4,D◢“TW=”: Locate 6,4,Z[5]◢Goto 06.主程序6:路基标准半幅宽度计算程序(对于设计有加宽渐变的有用,如路基宽度无变化,则把此程序直接输入半幅宽度值至L)程序名:6GDProg “G0”Z-C→E:(B-A)×E/S+A→L:L:7.坐标计算次程序(THB)程序名:THB18→DimZ:"KM"?Z:Prog "X0"1÷P→C: (P-R)÷(2HPR) →S:180÷π→E:F=1=>Goto 1:F=2=>Goto 2←┘Lbl 1:?D: Abs(Z-O) →W:Prog "A":X:Y:Goto 3LbI 2:X:Y:X→I:Y→J:Prog "B":O+W→Z:D→D:Goto 3 LbI 3:IF F=1Then X:Y:Else Z:D8. 正算子程序(A)程序名:A0.1184634425→A:0.2393143352→B:0.2844444444→N 0.046910077→K:0.2307653449→L:0.5→M:U+W(Acos(G+QEKW(C+KWS))+Bcos(G+QELW(C+LW S))+Ncos(G+QEMW(C+MW S))+Bcos(G+QE(1-L)W(C+(1-L)WS))+Acos(G+QE(1-K)W(C+(1-K)WS))) →X:V+W(Asin(G+QEKW(C+KWS))+Bsin(G+QELW(C+LW S))+Nsin(G+QEMW(C+MWS))+Bsin(G+QE(1-L)W(C+(1-L)WS))+Asin(G+QE(1-K)W( C+(1-K)WS))) →Y:G+QEW(C+WS)+Z[1]→Z[2]:X+Dcos(Z[2])→X: Y+Dsin(Z[2])→Y9. 反算子程序(B)程序名:BG-90→T: Abs((Y-V)cos(T)-(X-U)sin(T)) →W:0→D:Lbl 0:Prog "A":T+QEW(C+WS) →L: (J-Y)cos(L)-(I-X)sin(L)→D:IF Abs(D)<0.01:Then Goto1:Else W+D→W:Goto 0←┘Lbl 1:0→D:Prog "A":(J-Y)÷sin(Z[2]) →D:10.高程计算子程序(H)程序名:HProg “S0”:R:T:C:G:I:C-T→F:Z-F→L:C+T→E:G-TI→Q:If T=O:Then Q+LI→H:Goto 0:Else If Z<F:Then Q+LI→H:Goto 0:Else If Z≤E:Then Q+LI+L2÷2÷R→H:Goto 0:LbI 0:H:If D=0:Then Goto I:Else Prog “I”:H+V→H:Goto I:LbI I:H:I: 11.高程超高计算程序(I)程序名:IProg”I0”:W=1=> Goto 0:W=2=>Goto 1:LbI 0:If L=0:Then Abs(D)×M→V:Goto 2:Else Abs(D)×((N-M)×(Z-C)÷L+M)→V:Goto 2:IfEnd:LbI 1:If L=0:Then Abs(D)×M→V:Goto 2:Else Abs(D)×(((3((Z-C)÷L)2-2((Z-C)÷L)∧(3))×(N-M))+M)→V:Goto 2:IfEnd: LbI 2:Abs(D)→E:V÷E→I:I(E-K)→V:12.数据子程序(附后示例)①程序名:X0(坐标计算要素程序)If Z≥25900 And Z≤26615.555:Then 25900→O:11587.421→U:1847.983→V:101。

FX5800P计算器坐标正反算程序

FX5800P计算器坐标正反算程序

(以下程序是专业人士编写,本店铺不对程序负责,仅供您参考使用。

)卡西欧fx5800p计算器坐标正反算程序一、程序功能本程序由 6 个主程序、 5 个次子程序及 5 个参数子程序组成。

主要用于公路测量中坐标正反算,设计任意点高程及横坡计算 , 桥涵放样,路基开挖口及填方坡脚线放样。

程序坐标计算适应于任何线型 .二、源程序1. 主程序 1 :一般放样反算程序(① 正算坐标、放样点至置仪点方位角及距离;② 反算桩号及距中距离 )程序名 :1ZD-XYLb1 0:Norm 2F=1 : ( 正反算判别, F=1 正算, F=2 反算 , 也可以改 F 前加?,改 F 为变量 )Z[1]=90 (与路线右边夹角)Prog " THB ": F=1=>Goto 1:F=2=>Goto 2Lb1 1: F ix 3: "X = ": Locate 6,4, X◢"Y=": Locate 6,4, Y◢P rog "3JS”:Goto 0:Lb1 2:Fix 3: "KM=": Locate 6,4, Z◢"D=": Locate 6,4, D◢G oto 02.主程序2:高程序横坡程序 ( 设计任意点高程及横坡 )程序名: 2GCLbI 0:Norm 2“KM”?Z:?D:Prog”H”:Fix 3:” H=”:Locate 6,4,H◢“ I=”: Locate 6,4,I◢Goto 03. 主程序 3 :极坐放样计算程序 ( 计算放样点至置仪点方位角及距离 )程序名: 3JSX : Y :1268 .123→K( 置仪点 X 坐标 )2243 .545→L (置仪点 Y 坐标,都是手工输入 , 也可以建导线点数据库子程序 , 个人认为太麻烦)Y-L→E : X-K→F : Pol(F,E):IF J<0:ThenJ+360→J:Int(J)+0.01Int(60Frac(J))+0.006Frac(60Frac(J)) →J:( 不习惯小数点后四位为角度显示的,也可以用命令J◢DMS◢ 来直接显示) Fix 4:” FWJ=”: Locate 6,4,J◢( 不习惯小数点后四位为角度显示的,也可以用命令J◢DMS◢ 来直接显示 )Fix 3:” S=”:Locate 6,4,I◢4 .主程序 4 :涵洞放样程序(由涵中心桩号计算出各涵角坐标、在主程序 3 中输入置仪点坐标后计算放样点至置仪点方位角及距离 )程序名: 4JH-XYLbI 0:Norm 290→Z[1]( 涵洞中心桩与右边夹角,手工输入,也可以修改成前面加?后变为变量 )1→F:Prog”THB”:?L:Z[2]-Z[1] →E:X+Lcos(E) →X:Y+Lsin(E) →Y:Fix 3: "X = ": Locate 6,4, X◢"Y=": Locate 6,4, Y◢P rog "3JS”:Goto 0:5 .主程序 5: 路基开挖边线及填方坡脚线放样程序(输入大概桩号及测量坐标、地面标高计算出偏移距离、桩号、距中距离、填挖高度)程序名: 5FBXLbI 0:Norm 2: 18→DimZ:2→F:90→Z[1]:Prog“THB”:Z:D:”M0”?M:M→Z[4]:D→Z[3]:Prog”6GD”:L→Z[6]:If D<0:Then 0.75-L→D:Goto H:Else L-0.75→D:Goto H:IfEndLbI H:Prog”H”:H-0.03-Z[4] →Z[5]:Z[6] →L:If Z[5]<0:Then –z[5]→G:Goto W:Else Z[5] →G:Goto T:LbI W:Prog “W0”:Z[10]+Z[11] →A: If G>A:Then Goto 1:Else IfG>Z[10]:Then Goto 2:Else Goto 3:IfEnd:LbI 1:L+Z[12]+Z[13]+Z[14]+(G-A)×Z[9]+Z[11]×Z[8]+Z[10]×Z[7]:Goto Z: LbI 2:L+Z[12]+Z[13]+(G-Z[10])×Z[8]+Z[10]×Z[7]:G oto Z:LbI 3:L+Z[12]+G×Z[7]:Goto z:LbI T:L+0.5→N:If G>Z[17]:Then(N+Z[18]+(G-Z[17])×Z[16]+Z[17]×Z[15])→S:Goto Z:Else(N+G×Z[15])→S:Goto z:LbI Z:Z[3]→D:Fix 2:Abs(D)-S→T:” L0=”:L Locate 6,4,T◢"KM=": Locate 6,4, Z◢"D=": Locate 6,4, D◢“ TW=”: Locate 6,4,Z[5]◢Goto 06 .主程序 6 :路基标准半幅宽度计算程序 ( 对于设计有加宽渐变的有用,如路基宽度无变化,则把此程序直接输入半幅宽度值至 L)程序名: 6GDProg “G0”Z-C→E:(B-A)×E/S+A→L:L:7 .坐标计算次程序(THB)程序名: THB18→DimZ :"KM" ?Z : Prog "X0"1÷P→ C: (P-R)÷(2HPR) → S:180÷π→ E:F =1=>Goto 1 :F=2=>Goto 2←┘Lbl 1 : ? D: Abs( Z-O) →W : Prog " A " : X :Y:G oto 3 LbI 2: X:Y:X→I :Y→J : Prog "B":O+W→Z :D→ D:G oto 3LbI 3:IF F=1 Then X:Y: Else Z:D8. 正算子程序 ( A )程序名: A0.25→A :0.52→B :0.44→N 0.0→K :0.49→L :0.5→M :U+W(Acos(G+QEKW(C+KW S ))+Bcos(G+QELW(C+LW S ))+Ncos(G+QEMW(C+MWS ))+Bcos(G+QE(1-L)W(C+(1-L)WS))+Acos(G+QE(1-K)W(C+(1-K)WS))) →X :V+W(Asin(G+QEKW(C+KW S ))+Bsin(G+QELW(C+LWS ))+Nsin(G+QEMW(C+MWS))+Bsin(G+QE(1-L)W(C+(1-L)WS))+Asin(G+QE(1-K)W (C+(1-K)W S))) →Y :G+QEW(C+W S )+ Z[1]→ Z[2]: X+ D cos (Z[2])→ X: Y+ D sin (Z[2])→ Y9. 反算子程序 ( B )程序名: BG-90→ T: Abs((Y-V)cos(T)-(X-U)sin(T)) → W:0→ D: Lbl 0 : Prog " A " : T+QEW(C+W S) → L: (J-Y)cos(L)-(I-X)sin(L)→ D: IF Abs( D )<0.01:Then Goto1 : Else W+ D→W:Goto 0←┘Lbl 1:0→D : Prog " A " : (J-Y)÷sin( Z[2]) →D:10 .高程计算子程序( H )程序名: HProg “S0”:R:T:C:G:I:C-T→F:Z-F→L:C+T→E:G-TI→Q:If T=O:ThenQ+LI→H:Goto 0:Else If Z<F:Then Q+LI→H:Goto 0:Else If Z≤E:ThenQ+LI+L2÷2÷R→H:Goto 0:LbI 0:H:If D=0:Then Goto I:Else Prog “I”:H+V→H:Goto I:LbI I:H:I: 11. 高程超高计算程序( I )程序名: IProg”I0”:W=1=> Goto 0:W=2=>Goto 1:LbI 0:If L=0:Then Abs(D)×M→V:Goto 2:ElseAbs(D)×((N-M)×(Z-C)÷L+M)→V:Goto 2:IfEnd:LbI 1:If L=0:Then Abs(D)×M→V:Goto 2:ElseAbs(D)×(((3((Z-C)÷L)2-2((Z-C)÷L)∧(3))×(N-M))+M)→V:Goto 2:IfEnd: LbI 2:Abs(D)→E:V÷E→I:I(E-K)→V:12 .数据子程序 ( 附后示例 )① 程序名: X0 (坐标计算要素程序)If Z≥25900 And Z≤26615.555:Then25900→O:11587.421→U:1847.983→V:101 。

JAVA计算器源代码

JAVA计算器源代码

计算器源代码一、计算器源代码文件名:computer1.javaimport java.awt.*;import java.awt.event.*;public class computer1 extends Frame implements ActionListener{//声明窗口类并实现动作事件接口。

Button n0,n1,n2,n3,n4,n5,n6,n7,n8,n9;//声明数字按钮Button op,os,om,od,oe,oc;//声明操作按钮TextField tfd;//声明文本框String flg,rslt;//声明标志串、结果串Panel p1,p2,p3;//声明面板int i1,i2;float flt;computer1(){super("加减乘除计算器");n0 = new Button("0");//实现各按钮n1 = new Button("1");n2 = new Button("2");n3 = new Button("3");n4 = new Button("4");n5 = new Button("5");n6 = new Button("6");n7 = new Button("7");n8 = new Button("8");n9 = new Button("9");op = new Button("加");os = new Button("减");om = new Button("乘");od = new Button("除");oe = new Button("=");oc = new Button("c");tfd = new TextField(20);//实现文本框p1=new Panel();//实现各面板p2=new Panel();p3=new Panel();setLayout(new FlowLayout());//布局设计,用于安排按钮位置p1.add(n0);//将各数字按钮放入p1中p1.add(n1);p1.add(n2);p1.add(n3);p1.add(n4);p1.add(n5);p1.add(n6);p1.add(n7);p1.add(n8);p1.add(n9);p2.add(op);//将各操作按钮放入p2、p3中p2.add(os);p2.add(om);p2.add(od);p3.add(oe);p3.add(oc);setLayout(new BorderLayout());//布局设计,用于安排面板位置add("North",tfd);add("West",p1);add("Center",p2);add("East",p3);n0.addActionListener(this);//注册监听器到各按钮n1.addActionListener(this);n2.addActionListener(this);n3.addActionListener(this);n4.addActionListener(this);n5.addActionListener(this);n6.addActionListener(this);n7.addActionListener(this);n8.addActionListener(this);n9.addActionListener(this);op.addActionListener(this);os.addActionListener(this);om.addActionListener(this);od.addActionListener(this);oe.addActionListener(this);oc.addActionListener(this);addWindowListener(new closeWin());setSize(600,100);//确定窗口的尺寸setVisible(true);}public static void main (String args[]){new computer1();}public void actionPerformed(ActionEvent e){//处理鼠标事件的方法try{//异常处理if(e.getSource()==n0)//按数字键时tfd.setText(tfd.getText()+"0");if(e.getSource()==n1)tfd.setText(tfd.getText()+"1");if(e.getSource()==n2)tfd.setText(tfd.getText()+"2");if(e.getSource()==n3)tfd.setText(tfd.getText()+"3");if(e.getSource()==n4)tfd.setText(tfd.getText()+"4");if(e.getSource()==n5)tfd.setText(tfd.getText()+"5");if(e.getSource()==n6)tfd.setText(tfd.getText()+"6");if(e.getSource()==n7)tfd.setText(tfd.getText()+"7");if(e.getSource()==n8)tfd.setText(tfd.getText()+"8");if(e.getSource()==n9)tfd.setText(tfd.getText()+"9");if(e.getSource()==op){//按加号键时i1 = Integer.parseInt(tfd.getText());tfd.setText("");flg = "op";}if(e.getSource()==os){//按减号键时i1 = Integer.parseInt(tfd.getText());tfd.setText("");flg = "os";}if(e.getSource()==om){//按乘号键时i1 = Integer.parseInt(tfd.getText());tfd.setText("");flg = "om";}if(e.getSource()==od){//按除号键时i1 = Integer.parseInt(tfd.getText());tfd.setText("");flg = "od";}if(e.getSource()==oe){//按等号键时i2 = Integer.parseInt(tfd.getText());if(flg=="op"){rslt=Integer.toString(i1+i2);}if(flg=="os"){rslt=Integer.toString(i1-i2);}if(flg=="om"){rslt=Integer.toString(i1*i2);}if(flg=="od"){//除法需做小数处理flt=((float)i1)/((float)i2);rslt=Float.toString(flt);}tfd.setText(rslt);}if(e.getSource()==oc){//按清除键时tfd.setText("");flg = "";}}catch(Exception ex){}//扑捉到异常,但不进行处理}}class closeWin extends WindowAdapter{ //关闭窗口public void windowClosing(WindowEvent e){Frame frm=(Frame)(e.getSource());frm.dispose();System.exit(0);}}二、计算器界面三、修改后计算器界面。

(完整word版)c++分数计算器(含源码)

(完整word版)c++分数计算器(含源码)

一、实验设计方案1、实验内容与目的(简单介绍实验内容,说明实验目的)实验目的:设计一个分数计算器:1)实现输入>>,输出<<,+,-,*,/运算符的重载;2)实现分子分母的约分与规格化。

实验内容:你的具体选择(要详细)实现分数计算器的屏幕输入和输出:1)输入采用文件(input.txt)输入,可以有任意个二元分数表达式,表达式之间的分隔符自定义;2)输出到文件(output.txt)——————————————————————————————————————2、实验准备工作(阐述解决问题所涉及的算法思想,至少要画一个算法流程图来说明)以下为循环计算二元分数计算式的流程图:在实验中还需要面对六个运算符重载,通过运算符重载,我们可以简单的使用分数计算,而不需要关心它的结构,运算符重载,我们根据基本的数学定理,将加减乘除包装,并重载了输入输出运算符,这样,在输入输出时便可直接输出用户方便接收的格式。

——————————————————————————————————————二、实验步骤、测试与结果分析1、源程序的设计(在此附上源程序(cpp文件)清单)#include<iostream>#include<fstream>#include<cmath>using namespace std;//-------------------------------创建分数类------------------------------------class Fraction{private:int nume; //分子int deno; //分母int Gcf(int m,int n); //辅助函数,返回m 和n最大公因数public:Fraction(int n=1,int d=1);virtual~Fraction(){}void Reduction(); //约分int GetNume() const{return nume;} //返回分子int GetDeno() const{return deno;} //返回分母void SetNume(int n); //设置分子void SetDeno(int d); //设置分母Fraction operator+(const Fraction &a) const; //重载加法符+Fraction operator-(const Fraction &a) const; //重载加法符-Fraction operator*(const Fraction &a) const; //重载加法符*Fraction operator/(const Fraction &a) const; //重载加法符/ };ostream &operator << (ostream &out,const Fraction &a); //重载输出运算符<<istream &operator >> (istream &in,Fraction &a); //重载输入运算符>>//---------------------------------最大公因数函数------------------------------int Fraction::Gcf(int m,int n){if(n==0) return m; //如果n=0,m 为最大公因数else return Gcf(n,m%n); //否者辗转相除}//------------------------------------约分函数---------------------------------void Fraction::Reduction(){if(deno<0) //若分母小于0,将符号提前{nume=-nume;deno=-deno;}int f=Gcf(abs(nume),deno);nume=nume/f; //实现约数deno=deno/f;}//----------------------------------构造函数-----------------------------------Fraction::Fraction(int n,int d):nume(n),deno(d){if(deno==0) cout<<"分母为0"<<endl; //查出异常Reduction(); //约分}//----------------------------------设置分母函数-------------------------------void Fraction::SetNume(int n){nume=n;Reduction();}//----------------------------------设置分子函数-------------------------------void Fraction::SetDeno(int d){if(d==0) cout<<"分母为0"<<endl; //查出异常deno=d;Reduction();}//----------------------------------重载运算符+--------------------------------Fraction Fraction::operator+(const Fraction &a) const{Fraction result;result.nume=this->nume*a.deno+this->deno*a.nume; //求和的分子result.deno=this->deno*a.deno; //求和的分母result.Reduction(); //约分return result; //返回和}//----------------------------------重载运算符---------------------------------Fraction Fraction::operator-(const Fraction &a) const{Fraction result;result.nume=this->nume*a.deno-this->deno*a.nume; //求差的分子result.deno=this->deno*a.deno; //求差的分母result.Reduction(); //约分return result; //返回差}//----------------------------------重载运算符*--------------------------------Fraction Fraction::operator * (const Fraction &a) const{Fraction result;result.nume=this->nume*a.nume; //求积的分子result.deno=this->deno*a.deno; //求积的分母result.Reduction(); //约分return result; //返回积}//----------------------------------重载运算符/--------------------------------Fraction Fraction::operator / (const Fraction &a) const{if(a.nume==0) cout<<"除数为0"<<endl; //如果除数为0,输出异常Fraction result;result.nume=this->nume*a.deno; //求商的分子result.deno=this->deno*a.nume; //求商的分母result.Reduction(); //约分return result; //返回商}//----------------------------------重载运算符<<--------------------------------ostream &operator << (ostream &out,const Fraction &a){out<<a.GetNume()<<"/"<<a.GetDeno(); //按一定格式输出分数return out; //返回输出流}//----------------------------------重载运算符>>--------------------------------istream &operator >> (istream &in,Fraction &a){char ch; //接收字符int m,n; //定义分子和分母in>>m; //输入分子in>>ch; //输入/if(ch !='/') cout<<"非法字符"<<endl;in>>n; //输入分母if(n==0) cout<<"分母为0"<<endl; //如果分母为0,输出异常a.SetNume(m); //设置分子a.SetDeno(n); //设置分母a.Reduction(); //约分return in; //返回输入流}int main(void){Fraction obj1,obj2,result; //定义两个分数和结果char index,ch; //定义符号ifstream infile("input.txt",ios::in); //以输入的方式打开文件if(!infile) //若文件打开失败{cout<<"打开文件input.txt失败!"<<endl;exit(1);}ofstream outfile("output.txt",ios::app); //以输出的方式打开文件if(!outfile) //若文件打开失败{cout<<"打开文件output.txt失败"<<endl;exit(1);}outfile<<"---------------------本次计算结果如下--------------------"<<endl;for(;;) //无限次循环直到求解完成{infile>>obj1; //输入第一个分数infile>>index; //输入需要执行的操作符号infile>>obj2; //输入第二个分数infile>>ch; //选择继续或者计算结果if(index=='+') result=obj1+obj2; //加法else if(index=='-') result=obj1-obj2; //减法else if(index=='*') result=obj1*obj2; //乘法else if(index=='/') result=obj1/obj2; //除法else{system("PAUSE");return 0;}cout<<"正在计算"<<obj1<<" "<<index<<" "<<obj2<<"..."<<endl;;ofstream outfile("output.txt",ios::app);if(!outfile){cout<<"打开文件output.txt失败"<<endl;exit(1);}outfile<<obj1<<" "<<index<<" "<<obj2<<" "<<"="<<" "<<result<<endl;//输出结果到output.txtcout<<"计算完成,结果保存在output.txt中"<<endl<<endl;if(ch==';') continue; //若遇到";",继续执行else if(ch=='=') //若遇到"=",计算结果{outfile<<"-------------------------谢谢使用------------------------"<<endl<<endl;break;}outfile.close(); //文件输出流关闭}infile.close(); //文件输出流关闭system("PAUSE");return 0;} ——————————————————————————————————————2、实验现象及结论(应用文字和程序运行的截图说明程序测试现象,并解释结果)input.txt 输入截图如下:Jcsy.exe 执行截图如下:output.txt 输出截图如下:input.txt 输入截图如下:jcsy.exe 执行截图如下:Output.txt 输出截图如下:——————————————————————————————————————3、实验总结(是否成功解决问题,总结实验中最有价值的内容,程序能够在哪些方面进一步改善,自我评价成败得失)试验中,我们按照从简单到复杂的方法,一步一个脚印编写代码,使得程序不易发生错误,并且容易更正,编写出来的程序代码简洁明朗,效率较高;通过对例题的学习,我们最终将正确的代码编写出,并在不断地修改之下做到方便用户使用的要求;编码的速度有一个从慢到快的过程,在本次试验中,我们的速度依然比较慢,这看出我们平时编码比较少,缺乏熟练度,并对算法了解不深入;但是我们的代码看起来仍然有些凌乱,效率还没有带到真正的高效,每次运行都需要等待几秒钟。

用MATLAB实现计算器程序源代码

用MATLAB实现计算器程序源代码

function varargout = caculator(varargin)gui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @caculator_OpeningFcn, ...'gui_OutputFcn', @caculator_OutputFcn, ...'gui_LayoutFcn', [] , ...'gui_Callback', []);if nargin && ischar(varargin{1})gui_State.gui_Callback = str2func(varargin{1});endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});endfunction caculator_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject;set(handles.edit1,'string','0');set(handles.edit5,'string','0');guidata(hObject, handles);function varargout = caculator_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output;function edit1_Callback(hObject, eventdata, handles)function edit1_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit2_Callback(hObject, eventdata, handles)function edit2_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction edit3_Callback(hObject, eventdata, handles)function edit3_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction pushbutton1_Callback(hObject, eventdata, handles)handles.num1=strcat(get(handles.edit1,'string'),'+');set(handles.edit1,'string',handles.num1);guidata(hObject,handles);function pushbutton2_Callback(hObject, eventdata, handles) handles.num2=strcat(get(handles.edit1,'string'),'-');set(handles.edit1,'string',handles.num2);guidata(hObject,handles);function pushbutton3_Callback(hObject, eventdata, handles) handles.num3=strcat(get(handles.edit1,'string'),'*');set(handles.edit1,'string',handles.num3);guidata(hObject,handles);function pushbutton4_Callback(hObject, eventdata, handles) handles.num4=strcat(get(handles.edit1,'string'),'/');set(handles.edit1,'string',handles.num4);guidata(hObject,handles);function pushbutton_1_Callback(hObject, eventdata, handles) handles.shu1=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu1=strcat(handles.yuanshu,handles.shu1);if length(handles.shu1)<2;elseif (length(handles.shu1)>=2)&&(handles.shu1(end-1)==')')&& (handles.shu1(1)=='l')temp=handles.shu1(end);handles.shu1(end)=handles.shu1(end-1);handles.shu1(end-1)=temp;endset(handles.edit1,'string',handles.shu1);guidata(hObject, handles);function pushbutton_2_Callback(hObject, eventdata, handles) handles.shu2=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu2=strcat(handles.yuanshu,handles.shu2);if length(handles.shu2)<2;elseif (length(handles.shu2)>=2)&&(handles.shu2(end-1)==')')&& (handles.shu2(1)=='l')temp=handles.shu2(end);handles.shu2(end)=handles.shu2(end-1);handles.shu2(end-1)=temp;endset(handles.edit1,'string',handles.shu2);guidata(hObject, handles);function pushbutton_4_Callback(hObject, eventdata, handles) handles.shu4=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu4=strcat(handles.yuanshu,handles.shu4);if length(handles.shu4)<2;elseif (length(handles.shu4)>=2)&&(handles.shu4(end-1)==')')&& (handles.shu4(1)=='l')temp=handles.shu4(end);handles.shu4(end)=handles.shu4(end-1);handles.shu4(end-1)=temp;endset(handles.edit1,'string',handles.shu4);guidata(hObject, handles);function pushbutton_3_Callback(hObject, eventdata, handles) handles.shu3=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu3=strcat(handles.yuanshu,handles.shu3);if length(handles.shu3)<2;elseif (length(handles.shu3)>=2)&&(handles.shu3(end-1)==')')&& (handles.shu3(1)=='l')temp=handles.shu3(end);handles.shu3(end)=handles.shu3(end-1);handles.shu3(end-1)=temp;endset(handles.edit1,'string',handles.shu3);guidata(hObject, handles);function pushbutton_5_Callback(hObject, eventdata, handles) handles.shu5=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu5=strcat(handles.yuanshu,handles.shu5);if length(handles.shu5)<2;elseif (length(handles.shu5)>=2)&&(handles.shu5(end-1)==')')&& (handles.shu5(1)=='l')temp=handles.shu5(end);handles.shu5(end)=handles.shu5(end-1);handles.shu5(end-1)=temp;endset(handles.edit1,'string',handles.shu5);guidata(hObject, handles);function pushbutton_9_Callback(hObject, eventdata, handles) handles.shu9=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu9=strcat(handles.yuanshu,handles.shu9);if length(handles.shu9)<2;elseif (length(handles.shu9)>=2)&&(handles.shu9(end-1)==')')&& (handles.shu9(1)=='l')temp=handles.shu9(end);handles.shu9(end)=handles.shu9(end-1);handles.shu9(end-1)=temp;endset(handles.edit1,'string',handles.shu9);guidata(hObject, handles);function pushbutton_7_Callback(hObject, eventdata, handles) handles.shu7=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu7=strcat(handles.yuanshu,handles.shu7);if length(handles.shu7)<2;elseif (length(handles.shu7)>=2)&&(handles.shu7(end-1)==')')&& (handles.shu7(1)=='l')temp=handles.shu7(end);handles.shu7(end)=handles.shu7(end-1);handles.shu7(end-1)=temp;endset(handles.edit1,'string',handles.shu7);guidata(hObject, handles);function pushbutton_8_Callback(hObject, eventdata, handles) handles.shu8=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu8=strcat(handles.yuanshu,handles.shu8);if length(handles.shu8)<2;elseif (length(handles.shu8)>=2)&&(handles.shu8(end-1)==')')&& (handles.shu8(1)=='l')temp=handles.shu8(end);handles.shu8(end)=handles.shu8(end-1);handles.shu8(end-1)=temp;endset(handles.edit1,'string',handles.shu8);guidata(hObject, handles);function pushbutton_6_Callback(hObject, eventdata, handles) handles.shu6=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu6=strcat(handles.yuanshu,handles.shu6);if length(handles.shu6)<2;elseif (length(handles.shu6)>=2)&&(handles.shu6(end-1)==')')&& (handles.shu6(1)=='l')temp=handles.shu6(end);handles.shu6(end)=handles.shu6(end-1);handles.shu6(end-1)=temp;endset(handles.edit1,'string',handles.shu6);guidata(hObject, handles);function pushbutton18_Callback(hObject, eventdata, handles) handles.jieguo=get(handles.edit1,'string');handles.jieguo=strcat('=',handles.jieguo);eval(['handles.result''1' handles.jieguo]);set(handles.edit5,'string',num2str(handles.result1));guidata(hObject,handles);function pushbutton_0_Callback(hObject, eventdata, handles) handles.shu0=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');if handles.yuanshu(end)=='N';handles.yuanshu(end)='';endif handles.yuanshu(1)=='0';handles.yuanshu=handles.yuanshu(2:end);endhandles.shu0=strcat(handles.yuanshu,handles.shu0);if length(handles.shu0)<2;elseif (length(handles.shu0)>=2)&&(handles.shu0(end-1)==')')&& (handles.shu0(1)=='l')temp=handles.shu0(end);handles.shu0(end)=handles.shu0(end-1);handles.shu0(end-1)=temp;endset(handles.edit1,'string',handles.shu0);guidata(hObject, handles);function pushbutton20_Callback(hObject, eventdata, handles) handles.shu10=get(hObject,'string');handles.yuanshu=get(handles.edit1,'string');handles.shu10=strcat(handles.yuanshu,handles.shu10);set(handles.edit1,'string',handles.shu10);guidata(hObject, handles);function pushbutton21_Callback(hObject, eventdata, handles) function edit5_Callback(hObject, eventdata, handles)function edit5_CreateFcn(hObject, eventdata, handles)if ispc && isequal(get(hObject,'BackgroundColor'),get(0,'defaultUicontrolBackgroundColor'))set(hObject,'BackgroundColor','white');endfunction pushbutton22_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.fanhao=strcat('-(',handles.yuanshu,')');set(handles.edit1,'string',handles.fanhao);guidata(hObject, handles);function pushbutton23_Callback(hObject, eventdata, handles)set(handles.edit1,'string','0');set(handles.edit5,'string','0');guidata(hObject, handles);function pushbutton24_Callback(hObject, eventdata, handles)result=questdlg('ÕæµÄÒªÍ˳ö£¿','Í˳öÈ·ÈÏ','È·¶¨','È¡Ïû','È¡Ïû'); if result=='È·¶¨', close(gcf); endfunction pushbutton25_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.sin=strcat('sin(',handles.yuanshu,')');set(handles.edit1,'string',handles.sin);guidata(hObject, handles);function pushbutton26_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.cos=strcat('cos(',handles.yuanshu,')');set(handles.edit1,'string',handles.cos);guidata(hObject, handles);function pushbutton27_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.tan=strcat('tan(',handles.yuanshu,')');set(handles.edit1,'string',handles.tan);guidata(hObject, handles);function pushbutton28_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.ln=strcat('reallog(',handles.yuanshu,')');set(handles.edit1,'string',handles.ln);guidata(hObject, handles);function pushbutton29_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.log=strcat('log',handles.yuanshu,'()');set(handles.edit1,'string',handles.log);guidata(hObject, handles);function pushbutton30_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.daoshu=strcat('1/(',handles.yuanshu,')');set(handles.edit1,'string',handles.daoshu);guidata(hObject, handles);function pushbutton31_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.sqrt=strcat('sqrt(',handles.yuanshu,')');set(handles.edit1,'string',handles.sqrt);guidata(hObject, handles);function pushbutton32_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.pingfang=strcat('(',handles.yuanshu,')^2');set(handles.edit1,'string',handles.pingfang);guidata(hObject, handles);function pushbutton33_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.ncifang=strcat('(',handles.yuanshu,')^N');set(handles.edit1,'string',handles.ncifang);guidata(hObject, handles);function pushbutton35_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.kuohao=strcat('(',handles.yuanshu,')');set(handles.edit1,'string',handles.kuohao);guidata(hObject, handles);function pushbutton36_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.yuanshu=handles.yuanshu(1:(end-1));if length(handles.yuanshu)<1handles.yuanshu='0';endset(handles.edit1,'string',handles.yuanshu);guidata(hObject, handles);% --- Executes on button press in pushbutton37.function pushbutton37_Callback(hObject, eventdata, handles) handles.yuanshu=get(handles.edit1,'string');handles.exp=strcat('exp(',handles.yuanshu,')');set(handles.edit1,'string',handles.exp);guidata(hObject, handles);% --- Executes when user attempts to close figure1.function figure1_CloseRequestFcn(hObject, eventdata, handles)% hObject handle to figure1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)% Hint: delete(hObject) closes the figuredelete(hObject);%--------------------------------------------------------------------function Untitled_14_Callback(hObject, eventdata, handles)% hObject handle to Untitled_14 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)%--------------------------------------------------------------------function Untitled_15_Callback(hObject, eventdata, handles)set(gcf,'color','red')% hObject handle to Untitled_15 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)%--------------------------------------------------------------------function Untitled_16_Callback(hObject, eventdata, handles)set(gcf,'color','blue')% hObject handle to Untitled_16 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)%--------------------------------------------------------------------function Untitled_17_Callback(hObject, eventdata, handles)set(gcf,'color','green')% hObject handle to Untitled_17 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)%--------------------------------------------------------------------function Untitled_18_Callback(hObject, eventdata, handles)set(gcf,'color','black')% hObject handle to Untitled_18 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)%--------------------------------------------------------------------function Untitled_19_Callback(hObject, eventdata, handles)set(gcf,'color','yellow')% hObject handle to Untitled_19 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)%--------------------------------------------------------------------function Untitled_20_Callback(hObject, eventdata, handles)set(gcf,'color','m')% hObject handle to Untitled_20 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function Untitled_1_Callback(hObject, eventdata, handles)function Untitled_2_Callback(hObject, eventdata, handles)function Untitled_3_Callback(hObject, eventdata, handles)function Untitled_4_Callback(hObject, eventdata, handles)function Untitled_4_CreateFcn(hObject, eventdata, handles)function Untitled_5_Callback(hObject, eventdata, handles)function Untitled_6_Callback(hObject, eventdata, handles)。

C语言计算器程序源代码

C语言计算器程序源代码

C语⾔计算器程序源代码//strcmp(s1,s2) 当s1⼤于s2时,返回1 ,s1⼩于s2时,返回-1,相等时,返回0 #include "stdio.h"#include "ctype.h"#include "string.h"#include "math.h"#define MAX 256#define STACK_SIZE 128#define WORD_LEN 8#define POP 1#define PUSH 0#define ERR -1#define END 2#define OPER 0#define NUM 1#define WORD 2#define ADD 1#define SUB 2#define MUL 3#define DIV 4#define POW 5#define FAC 6#define BRA_L 7#define BRA_R 8#define SIN 9#define COS 10#define TAN 11#define CTG 12#define LG 13 //以10为底的常⽤对数//#define LN 14//#define LOG 15//⾏标为当前操作符代号,列标为栈顶元素代号//2表⽰计算结束,0表⽰当前操作符进栈,1表⽰栈顶操作符出栈// \0 + - * / ^ ! ( ) sin cos tg ctg lgint Priority[14][14]={2, 1, 1, 1, 1, 1, 1,-1,-1, 1, 1, 1, 1, 1, /* \0 */0, 1, 1, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* + */0, 1, 1, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* - */0, 0, 0, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* * */0, 0, 0, 1, 1, 1, 1, 0,-1, 1, 1, 1, 1, 1, /* / */0, 0, 0, 1, 1, 1, 1, 0,-1, 0, 0, 0, 0, 0, /* ^ */0, 0, 0, 0, 0, 0, 1, 0,-1, 0, 0, 0, 0, 0, /* ! */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* ( */-1,1, 1, 1, 1, 1, 1, 1,-1, 1, 1, 1, 1, 1, /* ) */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* sin */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* cos */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* tg */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0, /* ctg */0, 0, 0, 0, 0, 0,-1, 0,-1, 0, 0, 0, 0, 0}; /* lg */char KeyWord[36][WORD_LEN+1]={"sin", //前12个为函数,多余的⽤于扩展"cos","tan","tg","ctg","lg","","","","","","","","","","help", // 后⾯为命令,多余的为扩展"version","set","digit", //精度,⼩数点后的位数"color","radian", //弧度"degree", //⾓度"file","clr","clear","window", //窗⼝模式"fullscr", //全屏模式"","","","","","","","",""};int OperCode(char c){int code;switch(c){case '\0':code=0;break;case '+':code=1;break;case '-':code=2;break;case '*':code=3;break;case '/':code=4;break;case '^':code=5;break;case '!':code=6;break;case '(':code=7;break;case ')':code=8;break;case 's':code=9;break; //sincase 'c':code=10;break; //coscase 't':code=11;break; //tgcase 'C':code=12;break; //ctgcase 'l':code=13;break; //log default:code=-1;break;};return code;}int WordCode(char* word){int i;for(i=0;i<25;i++)if(strcmp(KeyWord[i],word)==0) break;if(i>=25)return -1;else}void help(){printf("显⽰帮助信息!\n");return;}void version(){printf("显⽰版本信息!\n");return;}void Err(int errcode,int position,char *p){printf("\n ERR:%d Position:%d %s",errcode,position,p); return;}double long factorial(int i){if(i==1 || i==0)return(1.0);elsereturn(i*factorial(i-1));}main(){char Expression[MAX+1];int Operator[STACK_SIZE];int OperStackTop;double long Number[STACK_SIZE];int NumStackTop;double long NumList[STACK_SIZE];int NumCursor,NumListSize;int OperList[STACK_SIZE];int OperCursor,OperListSize;int WordList[STACK_SIZE];int WordCursor,WordListSize;int Index[MAX+1];int IndexCursor,IndexSize;char Word[WORD_LEN+1];double long num,num1,num2,weight,tempnum;int Oper;int isDecimal,isErr,isNumber,isEnd;char CurrentOper;int i,j,k,m,n;char ch;num=0.0;num2=0.0;tempnum=0.0;Oper=-1;while(1){for(i=0;i<=MAX;i++) //表达式初始化,中间表索引初始化{Expression[i]='\0';Index[i]=-1;}for(i=0;i{Operator[i]='0';Number[i]=0.0;NumList[i]=0.0;OperList[i]=-1;WordList[i]=-1;}NumStackTop=-1; //栈顶指针初始化OperStackTop=0; //操作符栈压⼊\0Operator[OperStackTop]=OperCode('\0');NumCursor=0; //各种中间表指针初始化,各种中间表的长度初始化NumListSize=0;OperCursor=0;OperListSize=0; //操作符表中先写⼊第⼀个操作符'\0'WordCursor=0;WordListSize=0;IndexCursor=0;IndexSize=0;// Index[0]=OPER;printf("Cal>"); //初始化完成,输出提⽰符i=0;while((ch=getchar())!='\n'){if(i>MAX) /*输⼊超长,则出错*/{Err(0,i,"输⼊的表达式长度超过规定值!\n");isErr=1;break;}if(isupper(ch))ch=tolower(ch);Expression[i]=ch;i++;}if(isErr==1){isErr=0;continue;}if(strlen(Expression)==0) //直接回车continue;if(strcmp("end",Expression)==0 ||strcmp("exit",Expression)==0 || strcmp("quit",Expr ession)==0)break;//⼀下代码为编译预处理,主要处理负号,并检查括号是否配对k=0;for(i=0;Expression[i]!='\0';i++){if((i==0&&Expression[i]=='-') || (i>0&&Expression[i]=='-'&&Expression[i-1]=='(')){for(j=strlen(Expression);j>i;j--)Expression[j]=Expression[j-1];Expression[i]='0';}if(Expression[i]=='(') //检查括号k++;if(Expression[i]==')')k--;}if(k>0) //如果括号不配对{Err(1,-1,"缺少右括号 )\n");continue;}if(k<0){Err(1,-1,"缺少左括号 (\n");continue;}//编译预处理结束i=0; //词法分析while(1){if(Expression[i]=='\0'){OperList[OperListSize]=OperCode(Expression[i]);OperListSize++;Index[IndexSize]=OPER;IndexSize++;// printf("IndexSize=%d,Index[IndexSize]=%d,Expression[i]=%c\n",IndexSize,Index[IndexSize],Expression[i]); break;}isDecimal=0;isNumber=0;while(isdigit(Expression[i])||Expression[i]=='.') //读取数字{isNumber=1;if(Expression[i]=='.'){if((i<(MAX-1) && !isdigit(Expression[i+1])) || (i+1)==MAX) //不正确的⼩数点位置{Err(2,i,"⼩数点位置不正确!\n");isErr=1;isNumber=0;i++;break;}isDecimal=1;weight=0.1;i++;continue;}if(isDecimal==0)num=num*10.0+(double long)(Expression[i]-'0');{num=num+(double long)(Expression[i]-'0')*weight;weight=weight*0.1;}i++;} //数字读完if(isErr==1)break;if(isNumber==1) //如果刚才成功读取了数字,则数字⼊栈{NumList[NumListSize]=num;NumListSize++;isNumber=0;num=0.0;Index[IndexSize]=NUM;// printf("IndexSize=%d,Index[IndexSize]=%d\n",IndexSize,Index[IndexSize]); IndexSize++;}for(k=0;k<=WORD_LEN;k++)Word[k]='\0';j=0;while(isalpha(Expression[i])){if(j>=WORD_LEN) //超过长度仍然未匹配,则出错{Err(3,i,"单词长度超过规定值/未定义的单词:");printf("%s\n",Word);isErr=1;break;}Word[j]=Expression[i];j++;// printf("WORD:%s\n",Word);if(WordCode(Word)==-1) //匹配不成功{if(!isalpha(Expression[i+1]))//匹配不成功,但是下⼀个字符已经不是字母,{Err(4,i,"未定义的单词:"); //则出错,并跳出循环printf("%s\n",Word);isErr=1;break;} //匹配不成功且还能继续读取字符,则继续读取下⼀个字母i++;continue;}else //匹配成功,则单词⼊表,读取下⼀个字符{switch(WordCode(Word)){case 0:ch='s';break;case 1:ch='c';break;case 2:case 3:ch='t';break;case 4:ch='C';case 5:ch='l';break;default:ch='\0';WordList[WordListSize]=WordCode(Word);WordListSize++;Index[IndexSize]=WORD;IndexSize++;break;};if(ch!='\0'){OperList[OperListSize]=OperCode(ch);OperListSize++;Index[IndexSize]=OPER;IndexSize++;}i++;break;}} //单词读完if(isErr==1)break;if(Expression[i]==' ')i++;if(!isdigit(Expression[i]) && !isalpha(Expression[i]) && Expression[i]!='\0') {if(OperCode(Expression[i])==-1){isErr=1;Err(5,i,"未定义的操作符:");printf("%c\n",Expression[i]);break;}else{OperList[OperListSize]=OperCode(Expression[i]);OperListSize++;Index[IndexSize]=OPER;IndexSize++;i++;}} //操作符读完if(isErr==1)break;} //词法分析结束if(isErr==1){isErr=0;continue;}/* for(k=0;kprintf("NumList[%d]=%f\n",k,NumList[k]);for(k=0;kprintf("OperList[%d]=%d\n",k,OperList[k]);for(k=0;kprintf("WordList[%d]=%d\n",k,WordList[k]);for(k=0;kprintf("Index[%d]=%d\n",k,Index[k]);printf("\n\n IndexCursor=%d IndexSize=%d,\n",IndexCursor,IndexSize);printf("OperStacktop=%d,Operator[OperStackTop]=%d,NumStackTop=%d\n",OperStackTop,Operator[OperStackTop],NumStackTop); // continue;*/isEnd=0;IndexCursor=0;while(1){if(Index[IndexCursor]==NUM){if(NumCursor<0 || NumListSize<0){Err(10,-1,"索引列表与操作数列表信息不匹配\n");isErr=1;break;}NumStackTop++;Number[NumStackTop]=NumList[NumCursor];NumCursor++;IndexCursor++;continue;} //数字处理if(Index[IndexCursor]==OPER){m=OperList[OperCursor];n=Operator[OperStackTop];switch(Priority[m][n]){case ERR:Err(20,IndexCursor,"不可预见的错误!\n");isErr=1;break;case PUSH:OperStackTop++;Operator[OperStackTop]=m;OperCursor++;IndexCursor++;break;case END:isEnd=1;break;case POP:Oper=Operator[OperStackTop];OperStackTop--;switch(Oper){case BRA_L: IndexCursor++;OperCursor++;break;case ADD:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;num1=Number[NumStackTop];NumStackTop--;tempnum=num1+num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(11,IndexCursor,"加法运算缺少操作数!\n");isErr=1;}break;case SUB:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;num1=Number[NumStackTop];NumStackTop--;tempnum=num1-num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(12,IndexCursor,"减法运算缺少操作数!\n");isErr=1;}break;case MUL:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;num1=Number[NumStackTop];NumStackTop--;tempnum=num1*num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(13,IndexCursor,"乘法运算缺少操作数!\n");isErr=1;}break;case DIV:if(NumStackTop>=1){num2=Number[NumStackTop];NumStackTop--;if(num2==0.0){Err(14,IndexCursor,"除数为 0 ,不能进⾏除法运算!\n"); isErr=1;break;}num1=Number[NumStackTop];NumStackTop--;tempnum=num1/num2;NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(15,IndexCursor,"除法运算缺少操作数!\n"); isErr=1;}break;case POW:if(NumStackTop>=1){num2=Number[NumStackTop]; NumStackTop--;num1=Number[NumStackTop]; NumStackTop--;tempnum=pow(num1,num2); NumStackTop++;Number[NumStackTop]=tempnum;num1=0.0;num2=0.0;tempnum=0.0;}else{Err(16,IndexCursor,"乘⽅运算缺少操作数!\n"); isErr=1;}break;case FAC:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=factorial(num2); NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(17,IndexCursor,"阶乘运算缺少操作数!\n"); isErr=1;}break;case SIN:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=sin(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}{Err(18,IndexCursor,"正弦函数缺少参数!\n"); isErr=1;}break;case COS:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=cos(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(19,IndexCursor,"余弦函数缺少参数!\n"); isErr=1;}break;case TAN:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=tan(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(20,IndexCursor,"正切函数缺少参数!\n");isErr=1;}break;case CTG:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;tempnum=1.0/tan(num2); NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(21,IndexCursor,"余切函数缺少参数!\n"); isErr=1;}break;/* case LN:if(NumStackTop>=0)num2=Number[NumStackTop]; NumStackTop--;if(num2<=0.0){Err(20,IndexCursor,"⾃然对数函数真数:"); printf(" %f ⼩于0!\n",num2);isErr=1;break;}tempnum=log(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(17,IndexCursor,"⾃然对数函数缺少参数!\n"); isErr=1;}break; */case LG:if(NumStackTop>=0){num2=Number[NumStackTop]; NumStackTop--;if(num2<=0.0){Err(23,IndexCursor,"常⽤对数函数真数:"); printf(" %f ⼩于0!\n",num2);isErr=1;break;}tempnum=log10(num2);NumStackTop++;Number[NumStackTop]=tempnum;num2=0.0;tempnum=0.0;}else{Err(22,IndexCursor,"常⽤对数函数缺少参数!\n"); isErr=1;}break;default:Err(100,IndexCursor,"运算符(代码:"); printf(" %d )暂不⽀持!\n",Oper);isErr=1;break;/*#define SIN 9#define COS 10#define TAN 11#define CTG 12#define LOG 13 */}; //switch 语句结束break;};//switchif(isErr==1 || isEnd==1)break;continue;} //运算符处理if(Index[IndexCursor]==WORD){printf(" 单词尚未处理!\n");break;}//在这⾥处理单词}//核⼼计算结束if(isErr==1){isErr=0;continue;}if(NumStackTop>0){Err(1000,-1,"多余的操作数:");printf("%f!\n",Number[NumStackTop]);}elseif(NumStackTop==0 && isEnd==1){if(fabs(Number[NumStackTop])>1e20) printf(" %.20e\n",Number[NumStackTop]); elseprintf(" %f\n",Number[NumStackTop]); isEnd=0;}}//主循环结束}//主函数结束。

C语言简单计算器程序源代码

C语言简单计算器程序源代码

C语言简单计算器程序源代码以下是一个简单的C语言计算器程序的源代码:```c#include <stdio.h>int maichar operator;double num1, num2;printf("请输入运算符:");scanf("%c", &operator);printf("请输入两个数字:");scanf("%lf %lf", &num1, &num2);switch (operator)case '+':printf("%.2lf + %.2lf = %.2lf", num1, num2, num1 + num2); break;case '-':printf("%.2lf - %.2lf = %.2lf", num1, num2, num1 - num2); break;case '*':printf("%.2lf * %.2lf = %.2lf", num1, num2, num1 * num2);break;case '/':if (num2 != 0)printf("%.2lf / %.2lf = %.2lf", num1, num2, num1 / num2);elseprintf("除数不能为0");break;default:printf("无效的运算符");}return 0;```这个程序首先提示用户输入一个运算符,然后再提示输入两个数字。

接下来,程序会根据输入的运算符执行相应的计算,并打印结果。

在计算除法时,程序会检查除数是否为0,如果为0,则打印错误信息。

请注意,这只是一个非常简单的计算器程序,没有考虑很多错误处理情况。

数独计算器源码(java语言)

数独计算器源码(java语言)

/*这是本人最近做的一个数独计算器程序。

1.该程序由java编写。

2.该程序具有界面3.把以下代码复制到记事本上保存为java文件。

4.javac Test8.java ,然后再java Test8,你懂的。

5.再图形中输入已知的数字,点击确定,图形中就会出现解。

*/import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.util.ArrayList;import java.util.Iterator;import java.util.TreeSet;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JTextField;class Myframe extends JFrame{public static Object obj=new Object();public final static JTextField[][] filed=new JTextField[9][9]; public Myframe(){for(int a=0;a<9;a++){for(int b=0;b<9;b++){filed[a][b]=new JTextField();filed[a][b].setText("");}}JPanel jpan=new JPanel();jpan.setLayout(new GridLayout(9,9));for(int a=8;a>-1;a--){for(int b=0;b<9;b++){jpan.add(filed[b][a]);}}add(jpan,BorderLayout.CENTER);JPanel jpb=new JPanel();JButton button=new JButton("确定");jpb.add(button);button.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent event){synchronized (obj) {for(int a=0;a<9;a++){for(int b3=0;b3<9;b3++){int pp=0;if(!(filed[a][b3].getText().trim().equals(""))){pp=Integer.parseInt(filed[a][b3].getText().trim());Jieda.b[a][b3]=pp;}}}}synchronized (obj) {new Thread(new Jieda()).start();}}});add(jpb,BorderLayout.SOUTH);}}public class Test8{public static void main(String[] args) {Myframe myf=new Myframe();myf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);myf.setTitle("数独");myf.setSize(500,500);myf.setVisible(true);}}class Jieda implements Runnable{public static boolean[][] boo=new boolean[9][9];public static int shanghang=0;public static int shanglie=0;public static int[][] b=new int[9][9];public static void Huigui(boolean[][] boo1,int hang,int lie){int s=lie*9+hang;s--;int shang=s/9;int yushu=s%9;if(boo1[yushu][shang]){Huigui(boo1,yushu,shang);}else{shanghang=yushu;shanglie=shang;}}public static void arrayAdd(ArrayList<Integer> array,TreeSet<Integer> tree){for(int z=1;z<10;z++){boolean flag3=true;Iterator<Integer> it=tree.iterator();while(it.hasNext()){//10int b=it.next().intValue();if(z==b){flag3=false;break;}}if(flag3){array.add(new Integer(z));}flag3=true;}}public static ArrayList<Integer> Maybe(int hang,int lie){ ArrayList<Integer> array=new ArrayList<Integer>();TreeSet<Integer> tree=new TreeSet<Integer>();if(0<=hang&&hang<=2&&0<=lie&&lie<=2){for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=0;a2<3;a2++){for(int b4=0;b4<3;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(0<=hang&&hang<=2&&3<=lie&&lie<=5){for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=0;a2<3;a2++){for(int b4=3;b4<6;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(0<=hang&&hang<=2&&6<=lie&&lie<=8){ for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=0;a2<3;a2++){for(int b4=6;b4<9;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(3<=hang&&hang<=5&&0<=lie&&lie<=2){ for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}for(int a2=3;a2<6;a2++){for(int b4=0;b4<3;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(3<=hang&&hang<=5&&3<=lie&&lie<=5){ for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=3;a2<6;a2++){for(int b4=3;b4<6;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(3<=hang&&hang<=5&&6<=lie&&lie<=8){ for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=3;a2<6;a2++){for(int b4=6;b4<9;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(6<=hang&&hang<=8&&0<=lie&&lie<=2){ for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=6;a2<9;a2++){for(int b4=0;b4<3;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(6<=hang&&hang<=8&&3<=lie&&lie<=5){ for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=6;a2<9;a2++){for(int b4=3;b4<6;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}else if(6<=hang&&hang<=8&&6<=lie&&lie<=8){ for(int a=0;a<9;a++){if(a!=lie&&b[hang][a]!=0){tree.add(new Integer(b[hang][a]));}}for(int b1=0;b1<9;b1++){if(b1!=hang&&b[b1][lie]!=0){tree.add(new Integer(b[b1][lie]));}}for(int a2=6;a2<9;a2++){for(int b4=6;b4<9;b4++){if((!(a2==hang&&b4==lie))&&b[a2][b4]!=0){tree.add(new Integer(b[a2][b4]));}}}arrayAdd(array,tree);}return array;}public void run() {for(int a=0;a<9;a++){for(int b1=0;b1<9;b1++){if(b[a][b1]!=0){boo[a][b1]=true;}else{boo[a][b1]=false;}}}boolean flag=true;ArrayList<Integer>[][] yinyong=new ArrayList[9][9]; int hang=0;int lie=0;while(lie<9){if(flag==true){hang=0;}while(hang<9){if(b[hang][lie]==0){if(flag){ArrayList<Integer> list=Maybe(hang,lie);yinyong[hang][lie]=list;}if(yinyong[hang][lie].isEmpty()){Huigui(boo,hang,lie);hang=shanghang;lie=shanglie;b[hang][lie]=0;lie--;flag=false;break;}//if(list.isEmpty())else{b[hang][lie]=yinyong[hang][lie].get(0);yinyong[hang][lie].remove(0);flag=true;boolean r=true;for(int a1=0;a1<9;a1++){for(int b1=0;b1<9;b1++){if(r==false){break;}if(b[a1][b1]==0){r=false;}}}if(r){for(int a1=0;a1<9;a1++){for(int b1=0;b1<9;b1++){System.out.print("b["+a1+"]["+b1+"]"+b[a1][b1]+","); Myframe.filed[a1][b1].setText(b[a1][b1]+"");}}}}}//if(int[hang][lie]==0)else{flag=true;}hang++;}lie++;}}}。

android计算器源代码

android计算器源代码

界面设计<LinearLayoutxmlns:android="/apk/res/android"xmlns:tools="/tools"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical"tools:context=".MainActivity"><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="2"android:orientation="horizontal"><EditTextandroid:id="@+id/led"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_margin="3dip"android:background="#ccc"android:gravity="top|right"android:text=""android:textColor="#000"android:textSize="12pt"/></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal"><Buttonandroid:id="@+id/time"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="time"android:textSize="10pt"/><Buttonandroid:id="@+id/pow"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="pow"android:textSize="10pt"/><Buttonandroid:id="@+id/sqrt"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="sqrt"android:textSize="10pt"/><Buttonandroid:id="@+id/clear"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="clear"android:textSize="10pt"/></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal"><Buttonandroid:id="@+id/seven"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="7"android:textSize="12pt"/><Buttonandroid:id="@+id/eight"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="8"android:textSize="12pt"/><Buttonandroid:id="@+id/nine"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="9"android:textSize="12pt"/><Buttonandroid:id="@+id/division"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="÷"android:textSize="12pt"/></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal"><Buttonandroid:id="@+id/four"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="4"android:textSize="12pt"/><Buttonandroid:id="@+id/five"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="5"android:textSize="12pt"/><Buttonandroid:id="@+id/six"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="6"android:textSize="12pt"/><Buttonandroid:id="@+id/mult"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="*"android:textSize="12pt"/></LinearLayout><LinearLayoutandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_weight="1"android:orientation="horizontal"><Buttonandroid:id="@+id/one"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="1"android:textSize="12pt"/><Buttonandroid:id="@+id/two"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="2"android:textSize="12pt"/><Buttonandroid:id="@+id/three"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="3"android:textSize="12pt"/><Buttonandroid:id="@+id/sub"android:layout_width="fill_parent"android:layout_height="fill_parent"android:layout_weight="1"android:text="-"android:textSize="12pt"/></LinearLayout>Java源代码package youtclss;import java.util.Date;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener; import android.widget.Button;import android.widget.EditText;public class MainActivity extends Activity { private Button one;private Button two;private Button three;private Button four;private Button five;private Button six;private Button seven;private Button eight;private Button nine;private Button zero;private Button dot;private Button add;private Button sub;private Button mult;private Button division;private Button amount;private Button clear;private Button time;private Button sqrt;private Button pow;private EditText led;String num1 = "";String num2 = "";double num3 = 0;String rezult = "";String sign = null;int mark = 0;boolean flag = true;boolean dotmark = true;protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);setContentView(yout.main);zero = (Button) findViewById(R.id.zero);one = (Button) findViewById(R.id.one);two = (Button) findViewById(R.id.two);three = (Button) findViewById(R.id.three);four = (Button) findViewById(R.id.four);five = (Button) findViewById(R.id.five);six = (Button) findViewById(R.id.six);seven = (Button) findViewById(R.id.seven);eight = (Button) findViewById(R.id.eight);nine = (Button) findViewById(R.id.nine);dot = (Button) findViewById(R.id.dot);add = (Button) findViewById(R.id.add);sub = (Button) findViewById(R.id.sub);mult = (Button) findViewById(R.id.mult);division = (Button) findViewById(R.id.division); clear = (Button) findViewById(R.id.clear); amount = (Button) findViewById(R.id.amount); time = (Button) findViewById(R.id.time);pow = (Button) findViewById(R.id.pow);sqrt = (Button) findViewById(R.id.sqrt);led = (EditText) findViewById(R.id.led);zero.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "0";led.setText(num1);} else if (mark == 1) {num2 = num2 + "0";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "0";led.setText(num1 + sign + num2);}}});one.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "1";led.setText(num1);} else if (mark == 1) {num2 = num2 + "1";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "1";led.setText(num1 + sign + num2);}}});two.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "2";led.setText(num1);} else if (mark == 1) {num2 = num2 + "2";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "2";led.setText(num1 + sign + num2);}}});three.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "3";led.setText(num1);} else if (mark == 1) {num2 = num2 + "3";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "3";led.setText(num1 + sign + num2);}}});four.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "4";led.setText(num1);} else if (mark == 1) {num2 = num2 + "4";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "4";led.setText(num1 + sign + num2);}}});five.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "5";led.setText(num1);} else if (mark == 1) {num2 = num2 + "5";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "5";led.setText(num1 + sign + num2);}}});six.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "6";led.setText(num1);} else if (mark == 1) {num2 = num2 + "6";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "6";led.setText(num1 + sign + num2);}}});seven.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "7";led.setText(num1);} else if (mark == 1) {num2 = num2 + "7";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "7";led.setText(num1 + sign + num2);}}});eight.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "8";led.setText(num1);} else if (mark == 1) {num2 = num2 + "8";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "8";led.setText(num1 + sign + num2);}}});nine.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (mark == 0) {num1 = num1 + "9";led.setText(num1);} else if (mark == 1) {num2 = num2 + "9";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + "9";led.setText(num1 + sign + num2);}}});add.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (flag) {sign = "+";mark++;flag = false;dotmark = true;}}});sub.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (flag) {sign = "-";mark++;flag = false;dotmark = true;}}});mult.setOnClickListener(new OnClickListener() { public void onClick(View v) {if (flag) {sign = "*";mark++;flag = false;dotmark = true;}}});division.setOnClickListener(new OnClickListener() {public void onClick(View v) {if (flag) {sign = "÷";mark++;flag = false;dotmark = true;}}});pow.setOnClickListener(new OnClickListener() {public void onClick(View v) {if (flag) {sign = "^";mark++;flag = false;dotmark = true;}}});dot.setOnClickListener(new OnClickListener() {public void onClick(View v) {if (dotmark) {if (mark == 0) {num1 = num1 + ".";led.setText(num1);} else if (mark == 1) {num2 = num2 + ".";led.setText(num1 + sign + num2);} else {num1 = String.valueOf(num3);num2 = num2 + ".";led.setText(num1 + sign + num2);}dotmark = false;}}});amount.setOnClickListener(new OnClickListener() { // 等于时发生的运算public void onClick(View v) {flag = true;dotmark = true;if (sign.equals("+")) {double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x + y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + "=" + rezult);num2 = "";} else if (sign.equals("-")) {double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x - y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + "=" + rezult);num2 = "";} else if (sign.equals("*")) {double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x * y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + "=" + rezult);num2 = "";} else if (sign.equals("÷")) {double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = x / y;rezult = String.valueOf(num3);led.setText(num1 + sign + num2 +"=" + rezult);num2 = "";} else if (sign.equals("^")) {double x = Double.parseDouble(num1);double y = Double.parseDouble(num2);num3 = Math.pow(x, y);rezult = String.valueOf(num3);led.setText(num1 + sign + num2 + "=" + rezult);num2 = "";}}});clear.setOnClickListener(new OnClickListener() {public void onClick(View v) {num1 = "";num2 = "";num3 = 0;mark = 0;sign = "";led.setText("0");flag = true;dotmark = true;}});sqrt.setOnClickListener(new OnClickListener() {public void onClick(View v) {if (mark == 0 && !num1.equals("") &&num2.equals("")) {double parent =Double.parseDouble(num1);double root = Math.sqrt(parent);rezult = String.valueOf(root);led.setText(rezult);num1 = "";}}});time.setOnClickListener(new OnClickListener() { public void onClick(View v) {Date date = new Date();led.setText(date.toLocaleString());}});}。

卡西欧fx5800p计算器 坐标正反算程序

卡西欧fx5800p计算器 坐标正反算程序

(以下程序是专业人士编写,本店铺不对程序负责,仅供您参考使用。

)卡西欧fx5800p计算器坐标正反算程序一、程序功能本程序由 6 个主程序、 5 个次子程序及 5 个参数子程序组成。

主要用于公路测量中坐标正反算,设计任意点高程及横坡计算 , 桥涵放样,路基开挖口及填方坡脚线放样。

程序坐标计算适应于任何线型 .二、源程序1. 主程序 1 :一般放样反算程序(① 正算坐标、放样点至置仪点方位角及距离;② 反算桩号及距中距离 )程序名 :1ZD-XYLb1 0:Norm 2F=1 : ( 正反算判别, F=1 正算, F=2 反算 , 也可以改 F 前加?,改 F 为变量 )Z[1]=90 (与路线右边夹角)Prog " THB ": F=1=>Goto 1:F=2=>Goto 2Lb1 1: F ix 3: "X = ": Locate 6,4, X◢"Y=": Locate 6,4, Y◢P rog "3JS”:Goto 0:Lb1 2:Fix 3: "KM=": Locate 6,4, Z◢"D=": Locate 6,4, D◢G oto 02.主程序2:高程序横坡程序 ( 设计任意点高程及横坡 )程序名: 2GCLbI 0:Norm 2“KM”?Z:?D:Prog”H”:Fix 3:” H=”:Locate 6,4,H◢“ I=”: Locate 6,4,I◢Goto 03. 主程序 3 :极坐放样计算程序 ( 计算放样点至置仪点方位角及距离 )程序名: 3JSX : Y :1268 .123→K( 置仪点 X 坐标 )2243 .545→L (置仪点 Y 坐标,都是手工输入 , 也可以建导线点数据库子程序 , 个人认为太麻烦)Y-L→E : X-K→F : Pol(F,E):IF J<0:ThenJ+360→J:Int(J)+0.01Int(60Frac(J))+0.006Frac(60Frac(J)) →J:( 不习惯小数点后四位为角度显示的,也可以用命令J◢DMS◢ 来直接显示) Fix 4:” FWJ=”: Locate 6,4,J◢( 不习惯小数点后四位为角度显示的,也可以用命令J◢DMS◢ 来直接显示 )Fix 3:” S=”:Locate 6,4,I◢4 .主程序 4 :涵洞放样程序(由涵中心桩号计算出各涵角坐标、在主程序 3 中输入置仪点坐标后计算放样点至置仪点方位角及距离 )程序名: 4JH-XYLbI 0:Norm 290→Z[1]( 涵洞中心桩与右边夹角,手工输入,也可以修改成前面加?后变为变量 )1→F:Prog”THB”:?L:Z[2]-Z[1] →E:X+Lcos(E) →X:Y+Lsin(E) →Y:Fix 3: "X = ": Locate 6,4, X◢"Y=": Locate 6,4, Y◢P rog "3JS”:Goto 0:5 .主程序 5: 路基开挖边线及填方坡脚线放样程序(输入大概桩号及测量坐标、地面标高计算出偏移距离、桩号、距中距离、填挖高度)程序名: 5FBXLbI 0:Norm 2: 18→DimZ:2→F:90→Z[1]:Prog“THB”:Z:D:”M0”?M:M→Z[4]:D→Z[3]:Prog”6GD”:L→Z[6]:If D<0:Then 0.75-L→D:Goto H:Else L-0.75→D:Goto H:IfEndLbI H:Prog”H”:H-0.03-Z[4] →Z[5]:Z[6] →L:If Z[5]<0:Then –z[5]→G:Goto W:Else Z[5] →G:Goto T:LbI W:Prog “W0”:Z[10]+Z[11] →A: If G>A:Then Goto 1:Else IfG>Z[10]:Then Goto 2:Else Goto 3:IfEnd:LbI 1:L+Z[12]+Z[13]+Z[14]+(G-A)×Z[9]+Z[11]×Z[8]+Z[10]×Z[7]:Goto Z: LbI 2:L+Z[12]+Z[13]+(G-Z[10])×Z[8]+Z[10]×Z[7]:G oto Z:LbI 3:L+Z[12]+G×Z[7]:Goto z:LbI T:L+0.5→N:If G>Z[17]:Then(N+Z[18]+(G-Z[17])×Z[16]+Z[17]×Z[15])→S:Goto Z:Else(N+G×Z[15])→S:Goto z:LbI Z:Z[3]→D:Fix 2:Abs(D)-S→T:” L0=”:L Locate 6,4,T◢"KM=": Locate 6,4, Z◢"D=": Locate 6,4, D◢“ TW=”: Locate 6,4,Z[5]◢Goto 06 .主程序 6 :路基标准半幅宽度计算程序 ( 对于设计有加宽渐变的有用,如路基宽度无变化,则把此程序直接输入半幅宽度值至 L)程序名: 6GDProg “G0”Z-C→E:(B-A)×E/S+A→L:L:7 .坐标计算次程序(THB)程序名: THB18→DimZ :"KM" ?Z : Prog "X0"1÷P→ C: (P-R)÷(2HPR) → S:180÷π→ E:F =1=>Goto 1 :F=2=>Goto 2←┘Lbl 1 : ? D: Abs( Z-O) →W : Prog " A " : X :Y:G oto 3 LbI 2: X:Y:X→I :Y→J : Prog "B":O+W→Z :D→ D:G oto 3LbI 3:IF F=1 Then X:Y: Else Z:D8. 正算子程序 ( A )程序名: A0.→A :0.→B :0.→N 0.→K :0.→L :0.5→M : U+W(Acos(G+QEKW(C+KW S ))+Bcos(G+QELW(C+LW S ))+Ncos(G+QEMW(C+MWS ))+Bcos(G+QE(1-L)W(C+(1-L)WS))+Acos(G+QE(1-K)W(C+(1-K)WS))) →X :V+W(Asin(G+QEKW(C+KW S ))+Bsin(G+QELW(C+LWS ))+Nsin(G+QEMW(C+MWS))+Bsin(G+QE(1-L)W(C+(1-L)WS))+Asin(G+QE(1-K)W (C+(1-K)W S))) →Y :G+QEW(C+W S )+ Z[1]→ Z[2]: X+ D cos (Z[2])→ X: Y+ D sin (Z[2])→ Y9. 反算子程序 ( B )程序名: BG-90→ T: Abs((Y-V)cos(T)-(X-U)sin(T)) → W:0→ D: Lbl 0 : Prog " A " : T+QEW(C+W S) → L: (J-Y)cos(L)-(I-X)sin(L)→ D: IF Abs( D )<0.01:Then Goto1 : Else W+ D→W:Goto 0←┘Lbl 1:0→D : Prog " A " : (J-Y)÷sin( Z[2]) →D:10 .高程计算子程序( H )程序名: HProg “S0”:R:T:C:G:I:C-T→F:Z-F→L:C+T→E:G-TI→Q:If T=O:ThenQ+LI→H:Goto 0:Else If Z<F:Then Q+LI→H:Goto 0:Else If Z≤E:ThenQ+LI+L2÷2÷R→H:Goto 0:LbI 0:H:If D=0:Then Goto I:Else Prog “I”:H+V→H:Goto I:LbI I:H:I: 11. 高程超高计算程序( I )程序名: IPr og”I0”:W=1=> Goto 0:W=2=>Goto 1:LbI 0:If L=0:Then Abs(D)×M→V:Goto 2:ElseAbs(D)×((N-M)×(Z-C)÷L+M)→V:Goto 2:IfEnd:LbI 1:If L=0:Then Abs(D)×M→V:Goto 2:ElseAbs(D)×(((3((Z-C)÷L)2-2((Z-C)÷L)∧(3))×(N-M))+M)→V:Goto 2:IfEnd: LbI 2:Abs(D)→E:V÷E→I:I(E-K)→V:12 .数据子程序 ( 附后示例 )① 程序名: X0 (坐标计算要素程序)If Z≥25900 And Z≤26615.555:Then25900→O:11587.421→U:1847.983→V:101 。

C语言课程设计(计算器)

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系统流程图3.2查询函数流程图4 详细设计4.1分析和设计在程序的开头部分定义了结构替类型, 用来存放按钮信息struct s_button /*按键的结构体*/{int sx,sy,ex,ey;char *head;int press;}button[17]; /*图表按键数*/char far *vid_mem;static int tx=32,ty=3; /*静态变量*/float v1=0.0,v2=0.0;用输入函数input()来输入按键放在s_button数组中。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
void mwindow(char *header); /*窗口函数*/
int specialkey(void) ; /*获取特殊键函数*/
int arrow(); /*设置箭头光标函数*/
/*主函数*/
int main()
{
initialize();/* 设置系统进入图形模式 */
setcolor(RED); /*设置颜色为红色*/
outtextxy(x+3*width,y+height/2,"0."); /*输出字符串"0."*/
x =2*width-width/2; /*设置x的坐标值*/
y =2*height+height/2; /*设置y的坐标值*/
for( j=0 ; j<4 ; ++j ) /*画按钮*/
}
if(c=='-')
{
if(strcmp(str2,"")==0) /*如果str2为空,说明是负号,而不是减号*/
flag=-1; /*设置负数标志*/
else
{
num1=atof(str2); /*将第二个操作数转换为浮点数*/
strcpy(str2,""); /*将str2清空*/
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);
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."); /*显示字符串*/
{
strcpy(str2,"-"); /*将负号连接到字符串中*/
flag=1;
} /*将标志值恢复为1*/
sprintf(temp,"%c",c); /*将字符保存到字符串变量temp中*/
strcat(str2,temp); /*将temp中的字符串连接到str2中*/
setfillstyle(SOLID_FILL,color+3);
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 ); /*画一个矩形边框线*/
m=0;
n=0;
strcpy(str2,""); /*设置str2为空串*/
while((v=specialkey())!=45) /*当压下Alt+x键结束程序,否则执行下面的循环*/
{
while((v=specialkey())!=ENTER) /*当压下键不是回车时*/
}
}
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);
#define DOWN 0x50 /*光标下移键*/
#define LEFT 0x4b /*光标左移键*/
#define RIGHT 0x4d /*光标右移键*/
#define ENTER 0x0d /*回车键*/
void *rar; /*全局变量,保存光标图象*/
struct palettetype palette; /*使用调色板信息*/
void drawboder(void); /*画边框函数*/
void initialize(void); /*初始化函数*/
void computer(void); /*计算器计算函数*/
void changetextstyle(int font, int direction, int charsize); /*改变文本样式函数*/
#include <dos.h> /*DOS接口函数*/
#include <math.h> /*数学函数的定义*/
#include <conio.h> /*屏幕操作函数*/
#include <stdio.h> /*I/O函数*/
#include <stdlib.h> /*库函数*/
{
putimage(x,y,rar,XOR_PUT); /*显示光标图象*/
if(v==RIGHT) /*右移箭头时新位置计算*/
if(x>=x0+6*width) /*如果右移,移到尾,则移动到最左边字符位置*/
{
x=x0;
m=0;
}
else
{
x=x+width+width/2;
#include <stdarg.h> /*变量长度参数表*/
#include <graphics.h> /*图形函数*/
#include <string.h> /*字符串函数*/
#include <ctype.h> /*字符操作函数*/
#define UP 0x48 /*光标上移键*/
{
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; /* 移动行坐标*/
m++;
} /*否则,右移到下一个字符位置*/
if(v==LEFT) /*左移箭头时新位置计算*/
if(x<=x0)
{
x=x0+6*width;
m=4;
} /*如果移到头,再左移,则移动到最右边字符位置*/
else
{
x=x-width-width/2;
m--;
strcpy(str2,""); /*将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."); /*显示字符串*/
GraphDriver = DETECT; /* 自动检测显示器*/
initgraph( &GraphDriver, &GraphMode, "" ); /*初始化图形系统*/
ErrorCode = graphresult(); /*读初始化结果*/
if( ErrorCode != grOk ) /*如果初始化时出现错误*/
} /*否则,左移到前一个字符位置*/
if(v==UP) /*上移箭头时新位置计算*/
if(y<=y0)
{
y=y0+4*height+height/2;
n=3;
} /*如果移到头,再上移,则移动到最下边字符位置*/
else
{
y=y-height-height/2;
{
printf("Graphics System Error: %s\n",
grapherrormsg( ErrorCode ) ); /*显示错误代码*/
exit( 1 ); /*退出*/
}
getpalette( &palette ); /* 读面板信息*/
MaxColors = getmaxcolor() + 1; /* 读取颜色的最大值*/
n--;
} /*否则,移到上边一个字符位置*/
相关文档
最新文档