简要的计算器

//以上为运行结果

//以下为借助Button按键完成的

static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}

public partial class Form1 : Form

{
public Form1()
{
InitializeComponent();
}
private double One = 0, Two = 0;//定义变量用来存储操作数
private void button1_Click(object sender, EventArgs e)//0
{
this.textBox1.Text += button1.Text;
this.textBox2.Text += button1.Text;
}
private void button2_Click(object sender, EventArgs e)// .点
{
this.textBox1.Text += button2.Text;
this.textBox2.Text += button2.Text;
}
private void button3_Click(object sender, EventArgs e)// 1
{
this.textBox1.Text += button3.Text;
this.textBox2.Text += button3.Text;
}
private void button4_Click(object sender, EventArgs e)// 2
{
this.textBox1.Text += button4.Text;
this.textBox2.Text += button4.Text;
}
private void button5_Click(object sender, EventArgs e)// 3
{
this.textBox1.Text += button5.Text;
this.textBox2.Text += button5.Text;
}
private void button6_Click(object sender, EventArgs e)// 4
{
this.textBox1.Text += button6.Text;
this.textBox2.Text += button6.Text;
}
private void button7_Click(object sender, EventArgs e)// 5
{
this.textBox1.Text += button7.Text;
this.textBox2.Text += button7.Text;
}
private void button8_Click(object sender, EventArgs e)//6
{
this.textBox1.Text += button8.Text;
this.textBox2.Text += button8.Text;
}
private void button9_Click(object sender, EventArgs e)//7
{
this.textBox1.Text += button9.Text;
this.textBox2.Text += button9.Text;
}
private void button10_Click(object sender, EventArgs e)//8
{
this.textBox1.Text += button10.Text;
this.textBox2.Text += button10.Text;
}
private void button11_Click(object sender, EventArgs e)//9
{
this.textBox1.Text += button11.Text;
this.textBox2.Text += button11.Text;
}
private string s = string.Empty;//用来存放运算符
private bool b = true;
private void button12_Click(object sender, EventArgs e)// +加
{
if (b)
{
this.textBox1.Text += button12.Text;
One = double.Parse(textBox2.Text);//存储操作数一
s = this.button12.Text;
this.textBox2.Text = "";
b = false;
}
}

private void button13_Click(object sender, EventArgs e)// -减
{if (b)
{
this.textBox1.Text += button13.Text;
One = double.Parse(textBox2.Text);
s = this.button13.Text;
this.textBox2.Text = "";
b = false;
}
}

private void button14_Click(object sender, EventArgs e)// *乘
{if (b)
{
this.textBox1.Text += button14.Text;
One = double.Parse(textBox2.Text);
s = this.button14.Text;
this.textBox2.Text = "";
b = false;
}
}

private void button15_Click(object sender, EventArgs e)// /除
{if (b)
{
this.textBox1.Text += button15.Text;
One = double.Parse(textBox2.Text);
s = this.button15.Text;
this.textBox2.Text = "";
b = false;
}
}

private void button16_Click(object sender, EventArgs e)// C归零
{
this.textBox1.Text = "";
this.textBox2.Text = "";
}

private void button17_Click(object sender, EventArgs e)// =等号
{
if (b != true)
{
this.textBox1.Text += this.button17.Text;
Two = double.Parse(this.textBox2.Text);//存储操作数一
switch (s)//判断运算符
{
case "+":
double sum = One + Two;
this.textBox2.Text = sum.ToString();
this.textBox1.Text += sum.ToString();
b = true;
break;
case "-":
sum = One - Two;
this.textBox2.Text = sum.ToString();
this.textBox1.Text += sum.ToString();
b = true;
break;
case "*":
sum = One * Two;
this.textBox2.Text = sum.ToString();
this.textBox1.Text += sum.ToString();
b = true;
break;
case "/":
sum = One / Two;
this.textBox2.Text = sum.ToString();
this.textBox1.Text += sum.ToString();
b = true;
break;
}
}

}
}

时间: 2024-08-03 19:25:24

简要的计算器的相关文章

0-Broadcast机制原理简要介绍

Broadcast机制简要介绍 来源: http://blog.csdn.net/luoshengyang/article/details/6730748 导语 广播机制在Android系统中,也不算是什么创新的东西.如果读者了解J2EE或者COM,就会知道,在J2EE中,提供了消息驱动Bean(Message-Driven Bean),用来实现应用程序各个组件之间的消息传递:而在COM中,提供了连接点(Connection Point)的概念,也是用来在应用程序各个组间间进行消息传递.无论是J

大一C语言结课设计之《简单计算器》

/*===============================================*** 设计目的:简单计算器,计算形如10*(20.2-30.6)+5.0/2的表达式值 ** 简要原理:中缀式转逆波兰式(后缀式) ** IDE:Dev-Cpp 4.9.9.2 ** 注意事项:括号必须是英文状态的 ** 时间: 2014-6-17 \*===============================================*/ #include <stdio.h> #in

团队-科学计算器-项目总结

一,目的 我们日常生活的开支,大额数字或者多倍小数的计算都需要计算器的帮助,处理数字的开方.正余弦都离不开计算器.虽然现在的计算器价格比较低廉,但是功能过于简单的不能满足个人需求,功能多的价格昂贵,操作不便不说,很多功能根本做不到.所以,我们可以想到设计开发一个属于自己的简单的计算器来完成我们的日常生活需求. 二,设计思路 "科学计算器 "是一个软件.整个软件程序分为三个个功能模块,一个TextView, 一个是BuTTon, 一个是监听 .其中TextView有1个显示框等TextV

信利SC123金融财务计算器评测——不错的HP 12C仿品

最近X宝48包邮购入信利SC123金融计算器,只是为了玩一玩(没错你的好友盗版狂魔又上线了),因为这是目前市面上能买到的最便宜的金融计算器了,也是能买到的最便宜的RPN计算器,顺手出个评测.这个计算器估计感兴趣的人比得力那款少的多,所以就简略一点,少放点图吧. 重要的写在最前面,这款计算器虽然是完全仿制的HP 12C白金版,但是挺多允许12C的考试据说不让带这款(道听途说,不保证真实性,据说原因是监考不认识这款计算器),所以买来仅仅为了考试的建议慎购. 首先我想说几句信利这个牌子.信利计算器存在

linux命令格式,获取帮助及其目录结构简要理解

我们都知道,一台计算机要是没通电,和一堆废铁没什么区别.那么,通电开机进入系统后,会进入交互界面,等待用户操作,人与计算机交互界面有两种: GUI:图形用户接口.如我们平时使用的Windows  ,linux的X window,有KDE和GOME. CLI:命令行接口,使用的SHELL类型有bash ,csh,tcshell,zshell等. 例如:[[email protected] ~]# commandbin root:当前登录的用户名. dxlcentOS:当前主机的主机名.@是一个分隔

【自动化__GUI自动化】__java__Windows应用程序识别__计算器

一.代码如下 package www.woniu.gui.one; import java.awt.AWTException; import java.awt.Robot; import java.awt.Toolkit; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.Transferable; import java.aw

bzoj2242: [SDOI2011]计算器.

2242: [SDOI2011]计算器 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 4353  Solved: 1679[Submit][Status][Discuss] Description 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p,计算满足Y^x ≡ Z ( mod P)的最小非负整数. In

j2ee-JSP之简单计算器

来源韩顺平.j2ee视频实战教程jsp第1讲(下集) -------------------------------------------------------------------------------------------------------- 简单计算器,可以控制输入的数(仅第一个数)不能为空且不能为字符串 myCal.jsp代码 1 <!--这是计算器的界面 --> 2 <!-- 可以控制输入的数不能为空且不能为字符串 --> 3 <%@ page co

通过键盘接收数值和字符,实现计算器功能。

import java.util.Scanner; /** * @author 蓝色以太 * 通过键盘接收数值和字符,实现计算器功能. */ public class Calculator { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("请输入第一个数值:"); double num1=sc.nextDouble(); System.out