C# 编程 科学计算器

上传人:mg****2 文档编号:145470953 上传时间:2020-09-20 格式:DOC 页数:13 大小:77KB
返回 下载 相关 举报
C# 编程 科学计算器_第1页
第1页 / 共13页
C# 编程 科学计算器_第2页
第2页 / 共13页
C# 编程 科学计算器_第3页
第3页 / 共13页
C# 编程 科学计算器_第4页
第4页 / 共13页
C# 编程 科学计算器_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《C# 编程 科学计算器》由会员分享,可在线阅读,更多相关《C# 编程 科学计算器(13页珍藏版)》请在金锄头文库上搜索。

1、using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace Calculator public partial class Counter : Form public Counter() InitializeComponent(); double num1, num2; double result=0; int op; i

2、nt flag=0;/开始标志 int sp = 0;/判断除数为零时移除监听 int max = 0;/范围标识 int eq=0; #region 功能键 private void on_Click(object sender, EventArgs e)/开始 flag = 1; sp = 0; max = 0; this.numInput.Text = 0; this.txtInput.Text = ; private void off_Click(object sender, EventArgs e)/关闭 flag = 0; sp = 0; max = 0; this.numInpu

3、t.Text = ; this.txtInput.Text = ; private void button9_Click(object sender, EventArgs e)/删除 max = 0; if (flag = 1&sp=0) string numstring = this.numInput.Text; if (numstring.Length 0) string temp = numstring.Substring(0, numstring.Length - 1); this.numInput.Text = temp.ToString(); else this.numInput.

4、Text = 0; private void clear_Click(object sender, EventArgs e)/c清零 max = 0; if (flag = 1) sp = 0; this.numInput.Text = 0; this.txtInput.Text = ; private void delete_Click(object sender, EventArgs e)/清零 max = 0; if (flag = 1) sp = 0; this.numInput.Text = 0; #endregion #region 运算符 private void equal_C

5、lick(object sender, EventArgs e)/等号 eq = 1; if (flag = 1 & sp = 0) max = 0; num2 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num2.ToString(); this.txtInput.Text += =; txtInput.Text = null; switch (op) case 1: result = num1 + num2; break; case 2: result = num1 - num2; break; case 3:

6、 result = num1 * num2; break; case 4: result = num1 / num2; break; case 5: result = Math.Pow(num1, num2); break; case 6: result = Mod(num1, num2); break; default: return; if (op = 4&num2 = 0) this.numInput.Text = 除数不能为0; sp = 1; else /this.txtInput.Text += result.ToString(); this.numInput.Text = res

7、ult.ToString(); private void sub_Click(object sender, EventArgs e)/减法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num1.ToString(); numInput.Text = ; this.txtInput.Text += -; op = 2; private void mul_Click(object sender, EventArgs e)/乘法 max = 0;

8、if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num1.ToString(); this.numInput.Text = ; this.txtInput.Text += *; op = 3; private void divide_Click(object sender, EventArgs e)/除法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Text += num1.ToString(); this.numInput.Text = ; this.txtInput.Text += /; op = 4; private void plus_Click(object sender, EventArgs e)/加法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); this.txtInput.Tex

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号