1、C 编程 科学计算器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;
2、 int op; int 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; th
3、is.numInput.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
4、.numInput.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 vo
5、id equal_Click(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; brea
6、k; case 3: 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.
7、Text = result.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)/乘法
8、 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 = 3; private void divide_Click(object sender, EventArgs e)/除法 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.
9、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.Text += num1.ToString(); numInput.Text = ; this.txtI
10、nput.Text += +; op = 1; public double Mod(double x, double y)/取模运算 max = 0; int temp = Convert.ToInt32(x / y); return (x - y * temp); private void power_Click(object sender, EventArgs e)/幂运算 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(numInput.Text); this.txtInput.Text += num1.ToString()
11、; this.numInput.Text = ; this.txtInput.Text += ; op = 5; private void recip_Click(object sender, EventArgs e)/倒数 max = 0; if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = 0; temp = 1 / num1; this.txtInput.Text = 1/ + num1.ToString() + =; this.numInput.Text = temp.ToS
12、tring(); private void percent_Click(object sender, EventArgs e) max = 0; if (flag = 1 & sp = 0) /double temp = Convert.ToDouble(this.numInput.Text); /this.txtInput.Text += temp.ToString(); /temp = temp / 100; /this.numInput.Text = temp.ToString(); /this.txtInput.Text += %=; num1 = Convert.ToDouble(t
13、his.numInput.Text); this.txtInput.Text += num1.ToString(); this.numInput.Text = ; this.txtInput.Text += %; op = 6; #endregion #region 数字 private void one_Click(object sender, EventArgs e)/1 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.
14、Text = 1; eq = 0; else this.numInput.Text += 1; private void two_Click(object sender, EventArgs e)/2 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.Text = 2; eq = 0; else this.numInput.Text += 2; /this.txtInput.Text += 2; private void th
15、ree_Click(object sender, EventArgs e)/3 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.Text = 3; eq = 0; else this.numInput.Text += 3; /this.txtInput.Text += 3; private void four_Click(object sender, EventArgs e)/4 if (flag = 1 & sp = 0
16、& max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.Text = 4; eq = 0; else this.numInput.Text += 4; / this.txtInput.Text += 4; private void five_Click(object sender, EventArgs e)/5 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ;
17、 if (eq = 1) this.numInput.Text = 5; eq = 0; else this.numInput.Text += 5; /this.txtInput.Text += 5; private void six_Click(object sender, EventArgs e)/6 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.Text = 6; eq = 0; else this.numInput
18、.Text += 6; /this.txtInput.Text += 6; private void seven_Click(object sender, EventArgs e)/7 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.Text = 7; eq = 0; else this.numInput.Text += 7; /this.txtInput.Text += 7; private void eight_Clic
19、k(object sender, EventArgs e)/8 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.Text = 8; eq = 0; else this.numInput.Text += 8; /this.txtInput.Text += 8; private void night_Click(object sender, EventArgs e)/9 if (flag = 1 & sp = 0 & max =
20、 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq = 1) this.numInput.Text = 9; eq = 0; else this.numInput.Text += 9; /this.txtInput.Text += 9; private void zero_Click(object sender, EventArgs e)/0 if (flag = 1 & sp = 0 & max = 0) if (this.numInput.Text = 0) this.numInput.Text = ; if (eq
21、= 1) this.numInput.Text = 0; eq = 0; else this.numInput.Text += 0; /this.txtInput.Text += 0; private void dian_Click(object sender, EventArgs e)/小数点 if (flag = 1 & sp = 0 & max = 0) if (eq = 1) this.numInput.Text = .; eq = 0; else this.numInput.Text += .; /this.txtInput.Text += .; #endregion #region
22、 三角函数 private void sin_Click(object sender, EventArgs e)/sin if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = Math.PI * (num1 / 180); this.txtInput.Text += sin( + num1 + )=; num1 = Math.Sin(temp); this.numInput.Text = num1.ToString(); /this.txtInput.Text += num1.ToSt
23、ring(); private void cos_Click(object sender, EventArgs e)/cos if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = Math.PI * (num1 / 180); this.txtInput.Text += cos( + num1 + )=; num1 = Math.Cos(temp); this.numInput.Text = num1.ToString(); private void tan_Click(object
24、sender, EventArgs e)/tan if (flag = 1 & sp = 0) num1 = Convert.ToDouble(this.numInput.Text); double temp = Math.PI * (num1 / 180); this.txtInput.Text += tan( + num1 + )=; num1 = Math.Tan(temp); this.numInput.Text = num1.ToString(); #endregion #region 帮助 private void 关于产品ToolStripMenuItem_Click(objec
25、t sender, EventArgs e) MenuAbout about = new MenuAbout(); about.Show(); private void change_Click(object sender, EventArgs e) max = 0; if (flag = 1&sp = 0) num1 = Convert.ToDouble(this.numInput.Text); num1 = -num1; this.numInput.Text = num1.ToString(); private void 使用手册ToolStripMenuItem_Click(object
26、 sender, EventArgs e) MenuUse use = new MenuUse(); use.Show(); #endregion #region 皮肤 private void 皮肤1ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.SkinFile = Application.StartupPath + Calmness.ssk; private void 皮肤2ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.Skin
27、File = Application.StartupPath + DeepCyan.ssk; private void 皮肤3ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.SkinFile = Application.StartupPath + Eighteen.ssk; private void 皮肤4ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.SkinFile = Application.StartupPath + GlassGreen.ssk; private void 皮肤5ToolStripMenuItem_Click(object sender, EventArgs e) skinEngine1.SkinFile = Application.StartupPath + Silver.ssk; #endregion #region 复制粘贴 private void 复制ToolStripMenuItem_
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1