1、C课程设计仿照Windows设计计算器可视化编程技术课程设计 报告题目 仿照Windows系统计算器设计计算器1.引言计算器的产生和发展是建立在电子计算机基础之上的,现代社会很需要一个健全、高效率的计算器。为了提高自己的实践能力和将来开发一个更实用更全能更智能的计算器,以设计与实现计算器为课题。此次设计的计算器应用软件从visualstudio2012编程环境中开发,是一个简单的窗体应用程序,实现简单的计算器功能。以微软自带的计算器为模板,设计了简单易懂的计算器。这款计算器不仅实现了简单的四则运算的功能,还可以进行复杂数学运算,和进制转换(十进制转二进制、八进制、十六进制)。具有简洁的外观,即
2、时准确的获得所需要要计算的结果,充分降低了数字计算器的难度和所需要的时间,对人们生活和学习具有有很大的帮助。2. 系统设计(1)功能设计本计算器由四大模块,分别为:1.标准计算器(即为主窗口)2.科学型计算器3.程序员计算器(进制转换)4.开发者介绍(2)界面设计主窗口界面(from1)科学型计算器界面(from2)程序员界面(from3)开发者介绍(from4)2.程序实现1.文本框的设置:textBox1.Text = 0;窗口启动前 :Form1.x = 0;/point:1 ;nopoint: 0Form1.a = 0;/1:+ 2:- 3:* 4:/Form1.b = 0;/判D断?
3、是否执行过运算执行过运算Form1.shu1 = 0;Form1.shu2 = 0;Form1.result = 0;2.按键的设置:数字键及小数点:public static void number(object sender, TextBox textBox1) Button btn = (Button)sender; if (btn.Name = one) if (x = 1)/判断有小数点 textBox1.Text = textBox1.Text + 1; return; if (b != 0) textBox1.Text = 0; b = 0; if (double.Parse(t
4、extBox1.Text) = 0) textBox1.Text = 1; else textBox1.Text = (textBox1.Text + 1).ToString(); if (btn.Name = two) if (x = 1)/判断有无小数点 textBox1.Text = textBox1.Text + 2; return; if (b != 0) textBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 2; else textBox1.Text = (textBox1.Te
5、xt + 2).ToString(); if (btn.Name = three) if (x = 1)/判断有无小数点 textBox1.Text = textBox1.Text + 3; return; if (b != 0) textBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 3; else textBox1.Text = (textBox1.Text + 3).ToString(); if (btn.Name = four) if (x = 1)/判断有无小数点 textBox1.
6、Text = textBox1.Text + 4; return; if (b != 0) textBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 4; else textBox1.Text = (textBox1.Text + 4).ToString(); if (btn.Name = five) if (x = 1)/判断有无小数点 textBox1.Text = textBox1.Text + 5; return; if (b != 0) textBox1.Text = 0; b = 0
7、; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 5; else textBox1.Text = (textBox1.Text + 5).ToString(); if (btn.Name = six) if (x = 1)/判断有无小数点 textBox1.Text = textBox1.Text + 6; return; if (b != 0) textBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 6; else textBox1
8、.Text = (textBox1.Text + 6).ToString(); if (btn.Name = seven) if (x = 1)/判断有无小数点 textBox1.Text = textBox1.Text + 7; return; if (b != 0) textBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 7; else textBox1.Text = (textBox1.Text + 7).ToString(); if (btn.Name = eight) if (x =
9、 1)/判断有无小数点 textBox1.Text = textBox1.Text + 8; return; if (b != 0) textBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 8; else textBox1.Text = (textBox1.Text + 8).ToString(); if (btn.Name = nine) if (x = 1)/判断有无小数点 textBox1.Text = textBox1.Text + 9; return; if (b != 0) tex
10、tBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0) textBox1.Text = 9; else textBox1.Text = (textBox1.Text + 9).ToString(); if (btn.Name = zero) if (x = 1)/判断有无小数点 textBox1.Text = textBox1.Text + 0; return; if (b != 0)/两个数的界限判断? textBox1.Text = 0; b = 0; if (double.Parse(textBox1.Text) = 0)
11、textBox1.Text = 0; else textBox1.Text = (textBox1.Text + 0).ToString(); public void one_Click(object sender, EventArgs e) number(sender, textBox1); public void Form1_Load(object sender, EventArgs e) textBox1.Text = 0; public static void point(object sender, TextBox textBox1) if (double.Parse(textBox
12、1.Text) = 0) x = 1; textBox1.Text = (textBox1.Text + .).ToString(); public void xiaoshudian_Click(object sender, EventArgs e) point(sender, textBox1); 运算符号1(加减乘除、退格。清零):public static void fuhao2(object sender, TextBox textBox1) Button btnn = (Button)sender; if (btnn.Name = baifenbi) textBox1.Text =
13、(double.Parse(textBox1.Text) / 100).ToString() + %; if (btnn.Name = genhao) textBox1.Text = (Math.Sqrt(double.Parse(textBox1.Text).ToString(); if (btnn.Name = daoshu) if (double.Parse(textBox1.Text) = 0) MessageBox.Show(零没有倒数!); else textBox1.Text = (1 / double.Parse(textBox1.Text).ToString(); publi
14、c void baifenbi_Click(object sender, EventArgs e) fuhao2(sender, textBox1); public void 撤销_Click(object sender, EventArgs e) textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1); public void C清零Click(object sender, EventArgs e) textBox1.Clear(); public static void fuhao(object sender, Text
15、Box textBox1) Button bt = (Button)sender; if (bt.Name = add) x = 0; shu1 = double.Parse(textBox1.Text); a = 1; b = 1; if (bt.Name = subtract) x = 0; shu1 = double.Parse(textBox1.Text); a = 2; b = 2; if (bt.Name = multiply) x = 0; shu1 = double.Parse(textBox1.Text); a = 3; b = 3; if (bt.Name = 除y以) x
16、 = 0; shu1 = double.Parse(textBox1.Text); a = 4; b = 4; public void add_Click(object sender, EventArgs e) fuhao(sender, textBox1); public static void dengyu(object sender,TextBox textBox1) shu2=double.Parse( textBox1.Text); if(a=1) result = shu1 + shu2; textBox1.Text = result + ; if(a=2) result = sh
17、u1 - shu2; textBox1.Text = result + ; if(a=3) result = shu1 * shu2; textBox1.Text = result + ; if(a=4) result = shu1 / shu2; textBox1.Text = result + ; public void jieguo_Click(object sender, EventArgs e) dengyu (sender, textBox1); 运算符(科号2学型计算器中所用符号) private void one_Click(object sender, EventArgs e
18、) Form1.number(sender, textBox1); private void add_Click(object sender, EventArgs e) Form1.fuhao(sender, textBox1); private void jieguo_Click(object sender, EventArgs e) Form1.dengyu (sender, textBox1); if (Form1.a = 4)/sin textBox1.Text = (Math.Sin(Form1.shu1 * Math.PI / 180).ToString(); if (Form1.
19、a = 5)/cos textBox1.Text = (Math.Cos (Form1.shu1 * Math.PI / 180).ToString(); if (Form1.a = 6)/tan textBox1.Text = (Math.Tan (Form1.shu1 * Math.PI / 180).ToString(); if (Form1.a = 7)/n! double n = 1; for (double i = Form1.a; i 0; i-) n = n * i; textBox1.Text = (n).ToString(); if (Form1.a = 8)/pai te
20、xtBox1 .Text = (Math.PI) .ToString (); if (Form1 .a =9)/x2 textBox1 .Text =(Math .Pow(double.Parse (textBox1 .Text) ,2) ).ToString (); if (Form1 .a =10)/x3 textBox1 .Text =(Math .Pow(double .Parse (textBox1 .Text ),3) ).ToString (); if (Form1 .a =11)/次方 textBox1 .Text =(Math .Pow( Form1 .shu1 ,Form1
21、 .shu2 ) ).ToString (); textBox1.Text = Form1.result + ; if (Form1 .a =12)/10x textBox1 .Text =(Math .Pow(10,double .Parse (textBox1 .Text ) ) ).ToString (); if (Form1.a = 13)/3x textBox1.Text = (Math.Pow(double.Parse(textBox1.Text), 1.0 / 3.0).ToString(); / if (Form1 .a =14)/yx / textBox1 .Text = /
22、if (Form1 .a =15)/ln / textBox1 .Text =(Math .) if (Form1.a = 16)/log textBox1.Text = Math.Log(double.Parse(textBox1.Text), double.Parse(textBox1.Text).ToString(); / if (Form1 .a =17)/e / textBox1 .Text =Math.E private void xiaoshudian_Click(object sender, EventArgs e) Form1.point(sender, textBox1);
23、 private void 倒数_Click(object sender, EventArgs e) Form1.fuhao2(sender, textBox1); private void 撤消_Click(object sender, EventArgs e) textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length - 1); private void 清零_Click(object sender, EventArgs e) textBox1.Clear(); private void 正弦_Click(object sender
24、, EventArgs e) Button btn=(Button )sender ; if (btn.Name = 正弦) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 4;/表示sin 计算 Form1.b = 4; if (btn.Name = 余弦) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 5;/cos计算 Form1.b = 5; if (btn.Name = 正切) Form1.x = 0; Form1.shu
25、1 = double.Parse(textBox1.Text); Form1.a = 6;/表示tan 计算 Form1.b = 6; if (btn.Name = 阶乘) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 7;/ 表示n! Form1.b = 7; if (btn.Name = pai) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 8;/ 表示 Form1.b = 8; if (btn.Name = 平方) Fo
26、rm1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 9; /表示x2 Form1.b = 9; if (btn.Name = 三次方) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 10; /表示x3 Form1.b = 10; if (btn.Name = 次方) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 11; /表示xy Form1.b = 11
27、; if (btn.Name = 十的次方) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 12; /表示10x Form1.b = 12; if (btn.Name = 开三次方) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 13; /表示x3 Form1.b = 13; if (btn.Name = 开方) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 14; /表示 Form1.b = 14; if (btn.Name = ln) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 15; /表示ln Form1.b = 15; if (btn.Name = log) Form1.x = 0; Form1.shu1 = double.Parse(textBox1.Text); Form1.a = 16; /表示ln F