C编写简易计算器附源代码超详细

合集下载

简易计算器C语言代码

简易计算器C语言代码

#include<stdio.h>#include<math.h>int main(void){int choice,t=1;printf("**********************计算器*****************************************\n"); printf(" 1.加法运算2.减法运算\n"); printf(" 3.乘法运算4.除法运算\n"); printf(" 5.平方运算6.开方运算\n"); printf(" 7.解一元二次方程By:_一念成殇、\n"); printf("**********************************************************************\n");printf("请选择您即将进行的运算方式(输入对应数字):");while(t==1){scanf("%d",&choice);if(choice>7) printf("请您输入正确的选项编号!\n");//加法if(choice==1){float addend_1,addend_2,sum;printf("请输入两个加数:\n");scanf("%f",&addend_1);scanf("%f",&addend_2);sum=addend_1+addend_2;printf("结果为:%.2f",sum);}//减法if(choice==2){float reduction,minuend,difference;printf("请输入被减数和减数:\n");scanf("%f",&reduction);scanf("%f",&minuend );difference=reduction-minuend ;printf("结果为:%.2f",difference);}//乘法if(choice==3){float multiplier_1,multiplier_2,product;printf("请输入两个乘数:\n");scanf("%f",&multiplier_1);scanf("%f",&multiplier_2);product= multiplier_1 * multiplier_2;printf("结果为:%.2f",product);}//除法if(choice==4){float dividend,divisor,conslut;printf("请输入被除数和除数:\n");scanf("%f",&dividend);scanf("%f",&divisor);conslut=dividend/divisor;printf("结果为:%.2f",conslut);}//平方if(choice==5){float base,power;printf("请输入底数:\n");scanf("%f",&base);power=base*base;printf("结果为:%.2f",power);}//开方if(choice==6){float power,base;printf("请输入需要开方的数:\n");scanf("%f",&power);base=sqrt(power);printf("结果为:%.2f",base);}//解一元二次方程if(choice==7){float a,b,c,delta,root_1,root_2;printf("方程一般形式:ax^2+bx+c=0,请输入其中常量a,b,c的值:\n"); scanf("%f",&a);if(a==0){printf("此方程不是一元二次方程!请重新输入!\n");}else{scanf("%f",&b);scanf("%f",&c);delta=(b*b)-(4*a*c);printf("△=%f\n",delta);if(delta<0){printf("此方程无实数根.\n");}else{root_1=(sqrt(delta)-b)/(2.0*a);root_2=((-b)-sqrt(delta))/(2.0*a);printf("解得:x1=%f x2=%f\n",root_1,root_2);}}}printf("\n\n\n\n请选择您即将进行的运算方式(输入对应数字):"); }return 0;}。

简易计算器C语言代码

简易计算器C语言代码

简易四则运算计算器计算机工具地历史而言,中国古代最早采用地一种计算工具叫筹策,又叫做算筹,这种算筹多用竹子制成,也有用木头,兽骨充当材料的,大约270枚一束,放在布袋里可随身携带。

直到今天仍在使用的住算盘,是中国古代计算工具领域中的另一项发明明代时的住算盘已经与现代的住算盘几乎相同。

17世纪初,西方国家的计算工具有了较大的发展。

英国数学家纳尔发现了“纳皮尔算筹”;英国牧师奥却德发明了圆柱形对数计算尺,这种计算尺不仅能做加减乘涂,乘方和开方运算,甚至可以计算三角函数,指数函数和对数函数。

这些计算工具不仅带动了计算的发展,也为现代计算器发展尊定了良好的基础,成为现代社会应用广泛的计算工具,如手机,操作系统上附带的多功能计算器。

项目设计目的掌握模块的划分;掌握结构体定义;掌握栈的操作;掌握函数的定义;掌握栈的基本操作;掌握VC的基本绘图库;掌握鼠标的响应操作;目设计内容设计一个含有界面的计算器,输入一个包含括号的表达式,使用栈数据类型实现整数的四则运算操作,开方运算。

项目设计要求根据分析,系统要求实现以下几点基本功能:可通过按钮输入数字、运算符;能通过按钮实现退格、清除功能;实现加、减、乘、除、开方运算功能;实现括号运算;显示运算结果;良好的交互界面。

项目详细设计功能模块图根据系统功能要求,主要含有四大模块,分别是计算器界面设计模块、计算器按键控制模块、四则混合运算模块、计算器记忆处理模块。

计算器界面设计模块:调用VC图形系统函数和字符函数画出计算器的界面,包括24个按钮和一个文本输入框。

计算机按键控制模块:计算器通过键盘按键值的判断,执行相应的操作,如接收数字输入等。

计算器计算处理模块。

计算处理模块主要完成可以包括括号的表达式运算,运算包括加,减,乘,除、开方。

计算处理模块在按键控制模块中被调用执行。

处理模块是通过栈来实现的,分别定义了两个顺序栈,一个用来存放操作符栈,一个用来存放操作数栈。

计算器记忆处理模块。

单片机简易计算器程序代码

单片机简易计算器程序代码
{i=table1[num];fuhao=2;if(eq==0){ gz++;write_date(0x30+i);}
else{write_com(0x01);write_date(0x41) ;write_date(0x4e);write_date(0x53);write_date(0x30+i);a=daan;gz=gz+4;}
{fuhao=3;i=table1[num];if(eq==0){gz++; write_date(0x30+i);}
else {write_com(0x01);write_date(0x41) ;write_date(0x4e);write_date(0x53);write_date(0x30+i);a=daan;gz=gz+4;}
}//3表示乘号已按
if(g==1)
{g=0;gg(gz);fuhao=6;if(eq==0){gz=gz+3;write_date(0x43);write_date(0x4f);write_date(0x53);}
else{write_com(0x01);write_date(0x43);write_date(0x4f);write_date(0x53);write_date(0x4e);write_date(0x41) ;write_date(0x4e);write_date(0x53);b=daan;gz=gz+6;}
if(g==0)
{
write_com(0x01);
a=0;
b=0;
flag=0;
fuhao=0;
eq=0;
ad=0;bd=0;afd=0;bfd=0;

c语言制作简单的计算器

c语言制作简单的计算器

c语言制作简单的计算器在计算机编程领域中,C语言是一种广泛使用的编程语言之一。

它具有简单易学的特点,并且能够进行复杂的计算和逻辑处理。

今天,我们就来学习一下如何使用C语言来制作一个简单的计算器。

首先,我们需要明确我们计算器的功能和界面设计。

本次制作的计算器将具有基本的四则运算功能,即加法、减法、乘法和除法。

我们将在控制台中实现计算器的操作,并通过简单的用户界面进行交互。

接下来,我们需要创建一个C语言程序的框架。

首先,我们需要包含头文件,以便在程序中使用各种函数和变量。

我们可以使用"#include" 来引入头文件,例如:```c#include <stdio.h>```然后,我们需要定义主函数 `main()`。

在这个函数中,我们将编写计算器的逻辑代码。

让我们开始编写函数吧!首先,我们需要声明一些变量来存储用户输入的数字和运算符。

我们可以使用 `int` 来定义整数变量,并用 `char` 定义字符变量。

例如:```cint num1, num2, result;char operator;```接下来,我们需要提示用户输入要进行的运算,并读取用户输入的数字和运算符。

我们可以使用 `printf` 和 `scanf` 函数来完成这个任务,例如:```cprintf("请输入第一个数字: ");scanf("%d", &num1);printf("请输入运算符(+, -, *, /): ");scanf(" %c", &operator);printf("请输入第二个数字: ");scanf("%d", &num2);```注意,我们在读取运算符之前添加了空格,这是为了消除输入缓冲区中可能残留的换行符等字符。

接下来,我们需要编写代码来进行实际的计算操作。

简易计算器代码

简易计算器代码
connect(button[9],SIGNAL(clicked()),this,SLOT(setOper()));
button[10] = new QPushButton(buttontext[10],this,buttontext[10]); // “—”
button[10]->setFixedSize(BUTTONWIDTH,BUTTONHEIGHT);
edit->setText(tr("%1").arg(0)); //这个函数可获取文本编辑框中光标的位置,并显示在状态栏中
//setText(tr(“%1行%2列”).arg(rowNum).arg(colNum));
initialize(); //调用初始化函数
}
void CWidget::initialize()
cwidget.cpp
#include "cwidget.h"
#define KEY_CLR "CLR"
#define KEY_ADD "+"
#define KEY_SUB "-"
#define KEY_MUL "*"
#define KEY_DIV "/"
#define KEY_EQ "="
#define KEY_0 "0"
{
delete edit;
delete *button;
delete mainLayout;
delete topLayout;
delete bottomLayout;
}
void CWidget::calculate() //响应按键“=”,调用计算功能

c语言计算器程序编写代码

c语言计算器程序编写代码

c语言计算器程序编写代码C语言是一门广泛应用于计算机程序设计中的高级编程语言,计算器是我们日常生活中必不可少的工具之一。

今天,我们将探讨如何使用C语言编写计算器程序。

步骤一:确定计算器的基本功能在开始编写任何计算器程序之前,我们需要先决定它的基本功能。

例如,我们需要让计算器能够执行四种基本算术运算 -- 加、减、乘、除。

我们可能还需要添加其他一些功能,例如计算百分数、开根号、求幂等。

步骤二:编写C语言代码接下来,我们可以开始编写计算器程序的C代码。

此时,我们需要确定程序的最外层框架。

这包括用于接收用户输入、调用所需的函数以及输出结果的代码。

例如,我们可以使用如下的代码框架:```#include <stdio.h>int main() {// 接收输入// 调用对应的函数进行计算// 输出结果return 0;}```步骤三:编写函数我们需要编写函数来执行各种计算。

例如,我们可以编写一个add函数来执行加法,一个Subtract函数来执行减法,以此类推。

对于每个函数,我们需要指定它所需的输入,以及它返回的输出。

例如,对于add函数,我们期望它将两个数字相加,并返回结果:```int add(int x, int y) {return x + y;}```步骤四:解析用户输入为了使计算器程序更加友好,我们希望程序能够解析用户输入并检查其是否有效。

例如,如果用户输入了两个不能相互转换为数字的字符串,则程序应该输出错误消息。

步骤五:测试代码最后,我们需要测试我们的代码以确保它能够正常工作。

这意味着我们应该使用各种输入和边缘情况进行测试,例如“0除以任何数字”和“无效输入”的情况。

总结编写C语言计算器程序可能看起来很困难,但实际上它是一项非常有趣的任务,因为它要求我们配备基本的编程知识并创造性地思考解决方案。

通过这篇文章,我们了解了如何确定计算器的基本功能,如何编写C语言代码并编写函数,如何解析用户输入以及如何测试我们的代码。

计算器编程c语言

计算器编程c语言

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

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

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

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

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

超详细一、因为计算器设计的控件太多,不便使用控制台应用程序完成,所以这里使用Windows窗体应用程序,并命名为Calc,如下图所示:二、向窗体中拖入需要的控件,如下图所示:(完成效果图)结果显示区(作者博客左边的文本框)是TextBox控件,并修改其name为txtShow,按键0~9为Button控件,并将其name分别修改为btn_0、btn_1、btn_2、btn_3、btn_4、btn_5、btn_6、btn_7、btn_8、btn_9;按键【负数】的name值修改为btn_sign,按键【.】的name修改为btn_dot,按键【+-*/】的name值分别修改为btn_add、btn_sub、btn_mul、btn_div,按键【=】的name值修改为btn_equ,按键【倒数】的name值修改为btn_rev,按键【平方】的name值修改为btn_sqr,按键【开方】的name值修改为btn_sqrt。

右边的计算器图片空间是PictureBox,作者博客控件是LinkLabel,可以不添加,以上所有控件均可按照需求添加,只保留自己需要的按钮控件和textbox控件即可。

三、代码部分(含解释),采用switch多分支语句编写using System;using System.Drawing;using System.Collections;using ponentModel;usingusing System.Data;namespace Calc{///<summary>///温柔一刀C#简易计算器的实现///</summary>publicclass CalcForm:Form{private Button btn_0;private Button btn_1;private Button btn_2;private Button btn_3;private Button btn_4;private Button btn_5;private Button btn_6;private Button btn_7;private Button btn_8;private Button btn_9;private Button btn_add;private Button btn_sub;private Button btn_mul;private Button btn_div;private Button btn_sqrt;private Button btn_sign;private Button btn_equ;private Button btn_dot;private Button btn_rev;private TextBox txtShow;private Button btn_sqr;private PictureBox pictureBox1;private LinkLabel linkLabel1;///<summary>///必需的设计器变量。

///</summary>private ponentModel.Container components=null;public CalcForm(){////Windows窗体设计器支持所必需的//InitializeComponent();////TODO:在InitializeComponent调用后添加任何构造函数代码//}///<summary>///清理所有正在使用的资源。

///</summary>protectedoverridevoid Dispose(bool disposing){if(disposing){if(components!=null){components.Dispose();}}base.Dispose(disposing);}#region WindowsFormDesignergeneratedcode///<summary>///设计器支持所需的方法-不要使用代码编辑器修改///此方法的内容。

///</summary>privatevoid InitializeComponent(){ponentResourceManager resources=new ponentRe sourceManager(typeof(CalcForm));this.btn_9=new Button();this.txtShow=new TextBox();this.btn_8=new Button();this.btn_7=new Button();this.btn_div=new Button();this.btn_sqrt=new Button();this.btn_4=new Button();this.btn_5=new Button();this.btn_6=new Button();this.btn_1=new Button();this.btn_2=new Button();this.btn_3=new Button();this.btn_0=new Button();this.btn_mul=new Button();this.btn_sub=new Button();this.btn_sign=new Button();this.btn_equ=new Button();this.btn_add=new Button();this.btn_dot=new Button();this.btn_sqr=new Button();this.btn_rev=new Button();this.pictureBox1=new PictureBox();this.linkLabel1=new LinkLabel();((ponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();this.SuspendLayout();////btn_9//this.btn_9.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_9.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_9.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_9.ForeColor=System.Drawing.Color.Black;this.btn_9.Location=new System.Drawing.Point(126,37);this.btn_="btn_9";this.btn_9.Size=new System.Drawing.Size(59,31);this.btn_9.TabIndex=0;this.btn_9.Tag="9";this.btn_9.Text="9";this.btn_eVisualStyleBackColor=false;this.btn_9.Click+=new System.EventHandler(this.btn_0_Click);////txtShow//this.txtShow.Location=new System.Drawing.Point(4,6);="txtShow";this.txtShow.ReadOnly=true;this.txtShow.Size=new System.Drawing.Size(242,21);this.txtShow.TabIndex=1;this.txtShow.TextAlign=HorizontalAlignment.Right;////btn_8//this.btn_8.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_8.BackgroundImageLayout=ImageLayout.Center;this.btn_8.FlatAppearance.MouseDownBackColor=System.Drawing.SystemColors.ButtonFace; this=System.Drawing.Color.WhiteSmoke;this.btn_8.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_8.ForeColor=System.Drawing.Color.Black;this.btn_8.Location=new System.Drawing.Point(66,37);this.btn_="btn_8";this.btn_8.Size=new System.Drawing.Size(59,31);this.btn_8.TabIndex=2;this.btn_8.Tag="8";this.btn_8.Text="8";this.btn_eVisualStyleBackColor=false;this.btn_8.Click+=new System.EventHandler(this.btn_0_Click);////btn_7//this.btn_7.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_7.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_7.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_7.ForeColor=System.Drawing.Color.Black;this.btn_7.Location=new System.Drawing.Point(4,37);this.btn_="btn_7";this.btn_7.Size=new System.Drawing.Size(59,31);this.btn_7.TabIndex=3;this.btn_7.Tag="7";this.btn_7.Text="7";this.btn_eVisualStyleBackColor=false;this.btn_7.Click+=new System.EventHandler(this.btn_0_Click);////btn_div//this.btn_div.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_div.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_div.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_div.ForeColor=System.Drawing.Color.Red;this.btn_div.Location=new System.Drawing.Point(187,37);this.btn_="btn_div";this.btn_div.Size=new System.Drawing.Size(59,31);this.btn_div.TabIndex=4;this.btn_div.Text="/";this.btn_eVisualStyleBackColor=false;this.btn_div.Click+=new System.EventHandler(this.btn_div_Click);////btn_sqrt//this.btn_sqrt.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_sqrt.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_sqrt.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_sqrt.ForeColor=System.Drawing.Color.Black;this.btn_sqrt.Location=new System.Drawing.Point(253,37);this.btn_="btn_sqrt";this.btn_sqrt.Size=new System.Drawing.Size(59,31);this.btn_sqrt.TabIndex=5;this.btn_sqrt.Text="开方";this.btn_eVisualStyleBackColor=false;this.btn_sqrt.Click+=new System.EventHandler(this.btn_sqrt_Click);////btn_4//this.btn_4.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_4.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_4.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_4.ForeColor=System.Drawing.Color.Black;this.btn_4.Location=new System.Drawing.Point(4,72);this.btn_="btn_4";this.btn_4.Size=new System.Drawing.Size(59,31);this.btn_4.TabIndex=6;this.btn_4.Tag="4";this.btn_4.Text="4";this.btn_eVisualStyleBackColor=false;this.btn_4.Click+=new System.EventHandler(this.btn_0_Click);////btn_5//this.btn_5.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_5.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_5.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_5.ForeColor=System.Drawing.Color.Black;this.btn_5.Location=new System.Drawing.Point(66,72);this.btn_="btn_5";this.btn_5.Size=new System.Drawing.Size(59,31);this.btn_5.TabIndex=7;this.btn_5.Tag="5";this.btn_5.Text="5";this.btn_eVisualStyleBackColor=false;this.btn_5.Click+=new System.EventHandler(this.btn_0_Click);////btn_6//this.btn_6.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_6.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_6.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_6.ForeColor=System.Drawing.Color.Black;this.btn_6.Location=new System.Drawing.Point(126,72);this.btn_="btn_6";this.btn_6.Size=new System.Drawing.Size(59,31);this.btn_6.TabIndex=8;this.btn_6.Tag="6";this.btn_6.Text="6";this.btn_eVisualStyleBackColor=false;this.btn_6.Click+=new System.EventHandler(this.btn_0_Click);////btn_1//this.btn_1.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_1.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_1.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_1.ForeColor=System.Drawing.Color.Black;this.btn_1.Location=new System.Drawing.Point(4,108);this.btn_="btn_1";this.btn_1.Size=new System.Drawing.Size(59,31);this.btn_1.TabIndex=9;this.btn_1.Tag="1";this.btn_1.Text="1";this.btn_eVisualStyleBackColor=false;this.btn_1.Click+=new System.EventHandler(this.btn_0_Click);////btn_2//this.btn_2.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_2.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_2.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_2.ForeColor=System.Drawing.Color.Black;this.btn_2.Location=new System.Drawing.Point(66,108);this.btn_="btn_2";this.btn_2.Size=new System.Drawing.Size(59,31);this.btn_2.TabIndex=10;this.btn_2.Tag="2";this.btn_2.Text="2";this.btn_eVisualStyleBackColor=false;this.btn_2.Click+=new System.EventHandler(this.btn_0_Click);////btn_3//this.btn_3.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_3.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_3.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_3.ForeColor=System.Drawing.Color.Black;this.btn_3.Location=new System.Drawing.Point(126,108);this.btn_="btn_3";this.btn_3.Size=new System.Drawing.Size(59,31);this.btn_3.TabIndex=11;this.btn_3.Tag="3";this.btn_3.Text="3";this.btn_eVisualStyleBackColor=false;this.btn_3.Click+=new System.EventHandler(this.btn_0_Click);////btn_0//this.btn_0.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_0.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_0.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_0.ForeColor=System.Drawing.Color.Black;this.btn_0.Location=new System.Drawing.Point(4,143);this.btn_="btn_0";this.btn_0.Size=new System.Drawing.Size(59,31);this.btn_0.TabIndex=12;this.btn_0.Tag="0";this.btn_0.Text="0";this.btn_eVisualStyleBackColor=false;this.btn_0.Click+=new System.EventHandler(this.btn_0_Click);////btn_mul//this.btn_mul.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_mul.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_mul.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_mul.ForeColor=System.Drawing.Color.Red;this.btn_mul.Location=new System.Drawing.Point(187,72);this.btn_="btn_mul";this.btn_mul.Size=new System.Drawing.Size(59,31);this.btn_mul.TabIndex=13;this.btn_mul.Text="*";this.btn_eVisualStyleBackColor=false;this.btn_mul.Click+=new System.EventHandler(this.btn_mul_Click);////btn_sub//this.btn_sub.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_sub.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_sub.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_sub.ForeColor=System.Drawing.Color.Red;this.btn_sub.Location=new System.Drawing.Point(187,108);this.btn_="btn_sub";this.btn_sub.Size=new System.Drawing.Size(59,31);this.btn_sub.TabIndex=14;this.btn_sub.Text="-";this.btn_eVisualStyleBackColor=false;this.btn_sub.Click+=new System.EventHandler(this.btn_sub_Click);////btn_sign//this.btn_sign.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_sign.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_sign.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_sign.ForeColor=System.Drawing.Color.Red;this.btn_sign.Location=new System.Drawing.Point(66,143);this.btn_="btn_sign";this.btn_sign.Size=new System.Drawing.Size(59,31);this.btn_sign.TabIndex=15;this.btn_sign.Text="负数";this.btn_eVisualStyleBackColor=false;this.btn_sign.Click+=new System.EventHandler(this.btn_sign_Click);////btn_equ//this.btn_equ.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_equ.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_equ.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_equ.ForeColor=System.Drawing.Color.Red;this.btn_equ.Location=new System.Drawing.Point(253,143);this.btn_="btn_equ";this.btn_equ.Size=new System.Drawing.Size(59,31);this.btn_equ.TabIndex=16;this.btn_equ.Text="=";this.btn_eVisualStyleBackColor=false;this.btn_equ.Click+=new System.EventHandler(this.btn_equ_Click);////btn_add//this.btn_add.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_add.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_add.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_add.ForeColor=System.Drawing.Color.Red;this.btn_add.Location=new System.Drawing.Point(187,143);this.btn_="btn_add";this.btn_add.Size=new System.Drawing.Size(59,31);this.btn_add.TabIndex=17;this.btn_add.Text="+";this.btn_eVisualStyleBackColor=false;this.btn_add.Click+=new System.EventHandler(this.btn_add_Click);////btn_dot//this.btn_dot.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_dot.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_dot.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_dot.ForeColor=System.Drawing.Color.Black;this.btn_dot.Location=new System.Drawing.Point(126,143);this.btn_="btn_dot";this.btn_dot.Size=new System.Drawing.Size(59,31);this.btn_dot.TabIndex=18;this.btn_dot.Text=".";this.btn_eVisualStyleBackColor=false;this.btn_dot.Click+=new System.EventHandler(this.btn_dot_Click);////btn_sqr//this.btn_sqr.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_sqr.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_sqr.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_sqr.ForeColor=System.Drawing.Color.Black;this.btn_sqr.Location=new System.Drawing.Point(253,72);this.btn_="btn_sqr";this.btn_sqr.Size=new System.Drawing.Size(59,31);this.btn_sqr.TabIndex=19;this.btn_sqr.Text="平方";this.btn_eVisualStyleBackColor=false;this.btn_sqr.Click+=new System.EventHandler(this.btn_sqr_Click);////btn_rev//this.btn_rev.BackColor=System.Drawing.SystemColors.ActiveBorder;this.btn_rev.BackgroundImageLayout=ImageLayout.Center;this=System.Drawing.SystemColors.ButtonFace;this=System.Drawing.Color.WhiteSmoke;this.btn_rev.Font=new System.Drawing.Font("黑体",10.5F,System.Drawing.FontStyle.Bold,System.Drawing.GraphicsUnit.Point,((byte)(134))); this.btn_rev.ForeColor=System.Drawing.Color.Red;this.btn_rev.Location=new System.Drawing.Point(253,108);this.btn_="btn_rev";this.btn_rev.Size=new System.Drawing.Size(59,31);this.btn_rev.TabIndex=20;this.btn_rev.Text="倒数";this.btn_eVisualStyleBackColor=false;this.btn_rev.Click+=new System.EventHandler(this.btn_rev_Click);////pictureBox1//this.pictureBox1.Image=((System.Drawing.Image)(resources.GetObject("pictureBox1.Image"))); this.pictureBox1.Location=new System.Drawing.Point(319,6);="pictureBox1";this.pictureBox1.Size=new System.Drawing.Size(100,168);this.pictureBox1.TabIndex=21;this.pictureBox1.TabStop=false;////linkLabel1//this.linkLabel1.AutoSize=true;this.linkLabel1.Location=new System.Drawing.Point(253,13);="linkLabel1";this.linkLabel1.Size=new System.Drawing.Size(53,12);this.linkLabel1.TabIndex=22;this.linkLabel1.TabStop=true;this.linkLabel1.Text="作者博客";this.linkLabel1.LinkClicked+=new LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked );////CalcForm//this.AutoScaleBaseSize=new System.Drawing.Size(6,14);this.ClientSize=new System.Drawing.Size(427,181);this.Controls.Add(this.linkLabel1);this.Controls.Add(this.pictureBox1);this.Controls.Add(this.btn_rev);this.Controls.Add(this.btn_sqr);this.Controls.Add(this.btn_dot);this.Controls.Add(this.btn_add);this.Controls.Add(this.btn_equ);this.Controls.Add(this.btn_sign);this.Controls.Add(this.btn_sub);this.Controls.Add(this.btn_mul);this.Controls.Add(this.btn_0);this.Controls.Add(this.btn_3);this.Controls.Add(this.btn_2);this.Controls.Add(this.btn_1);this.Controls.Add(this.btn_6);this.Controls.Add(this.btn_5);this.Controls.Add(this.btn_4);this.Controls.Add(this.btn_sqrt);this.Controls.Add(this.btn_div);this.Controls.Add(this.btn_7);this.Controls.Add(this.btn_8);this.Controls.Add(this.txtShow);this.Controls.Add(this.btn_9);this.FormBorderStyle=FormBorderStyle.FixedDialog;this.MaximizeBox=false;="CalcForm";this.StartPosition=FormStartPosition.CenterScreen;this.Text="C#编写计算器by";this.Load+=new System.EventHandler(this.CalcForm_Load);((ponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); this.ResumeLayout(false);this.PerformLayout();}#endregionpublicconstint NULL=0; //定义操作码publicconstint ADD=1;publicconstint SUB=2;publicconstint MUL=3;publicconstint DIV=4;publicconstint SQR=5;publicconstint SQRT=6;publicconstint NODOT=0; //定义是否点击了小数点publicconstint HASDOT=1;privatedouble res=0; //记录结果数privatedouble tmp=0; //当前输入的操作数privateint opt=NULL; //记录操作码privateint dot=NODOT; //记录是否点击了小数点privateint num=0; //记录输入操作数的个数privateint dotnum=0; //记录小数点部分的个数///<summary>///应用程序的主入口点。

相关文档
最新文档