C#計(jì)算器實(shí)驗(yàn)報(bào)告_第1頁(yè)
C#計(jì)算器實(shí)驗(yàn)報(bào)告_第2頁(yè)
C#計(jì)算器實(shí)驗(yàn)報(bào)告_第3頁(yè)
C#計(jì)算器實(shí)驗(yàn)報(bào)告_第4頁(yè)
C#計(jì)算器實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩14頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、一 實(shí)驗(yàn)?zāi)康暮鸵?二 功能模塊設(shè)計(jì)2三 設(shè)計(jì)界面3四 詳細(xì)設(shè)計(jì)過(guò)程3五 詳細(xì)代碼5六 實(shí)驗(yàn)總結(jié)18一 實(shí)驗(yàn)?zāi)康暮鸵笤O(shè)計(jì)一個(gè)簡(jiǎn)單計(jì)算器,具有一般計(jì)算功能,能進(jìn)行基本的加減乘除運(yùn)算,還具有求根號(hào),倒數(shù)等功能。特點(diǎn)是能進(jìn)行不同進(jìn)制的運(yùn)算和不同進(jìn)制間的轉(zhuǎn)換。主要的工作主要是操作數(shù)與被操作數(shù)進(jìn)行簡(jiǎn)單的加、減、乘、除運(yùn)算來(lái)完成基本的,而且還可以進(jìn)行簡(jiǎn)單的科學(xué)運(yùn)算例如計(jì)算一個(gè)數(shù)的平方、開(kāi)方、等操作還可以計(jì)算面積、周長(zhǎng)、體積和表面積等。通過(guò)新的技術(shù)和新方法來(lái)實(shí)現(xiàn)計(jì)算功能顯示界面為Windows From窗體。二 功能模塊設(shè)計(jì)計(jì)算器功能通過(guò)Windows Form窗體中的對(duì)應(yīng)按鈕接受用戶輸入數(shù)據(jù)提交對(duì)應(yīng)的方

2、法中來(lái)完成相應(yīng)的功能計(jì)算再將結(jié)果顯示在顯示框內(nèi)。顯示界面為Windows From窗體。 1加法 兩個(gè)數(shù)據(jù)進(jìn)行加操作可以為小數(shù)。 2減法 兩個(gè)數(shù)據(jù)進(jìn)行減操作可以為負(fù)數(shù)相減。 3乘法 兩個(gè)數(shù)相乘4除法兩個(gè)數(shù)相除5 倒數(shù)可以求得一個(gè)數(shù)的倒數(shù)6開(kāi)方 開(kāi)方后的結(jié)果可以精確到16位。8 平方 接收的數(shù)相乘結(jié)果保留一位小數(shù)。 2 立方 接收的數(shù)相乘兩次9 二進(jìn)制二進(jìn)制數(shù)的運(yùn)算10 八進(jìn)制八進(jìn)制數(shù)的運(yùn)算11 十進(jìn)制十進(jìn)制數(shù)的運(yùn)算12 十六進(jìn)制十六進(jìn)制的運(yùn)算三 設(shè)計(jì)界面四 詳細(xì)設(shè)計(jì)過(guò)程(一) 打開(kāi)VS2008創(chuàng)建項(xiàng)目(二)界面設(shè)計(jì) 1.進(jìn)入界面2.菜單設(shè)計(jì) (1)選擇VS201的菜單欄中的“視圖|工具箱”單擊

3、,調(diào)出工具箱(出現(xiàn)在VS用戶區(qū)左側(cè)。 (2)在工具箱中選擇“菜單和工具欄|MenuStrip”,拖到程序界面用戶區(qū),并根據(jù)自己的喜好在“屬性窗口”(可以使用“視圖|屬性窗口”調(diào)出,一般在用戶區(qū)右下角)設(shè)置菜單欄寬度、顏色等。 (3)在菜單欄中“請(qǐng)?jiān)诖颂庢I入”編輯第一個(gè)菜單 選項(xiàng)及其下拉子菜單選項(xiàng)“編輯”“復(fù)制”“粘貼”。(4)按上述操作,依次完成第二、三個(gè)菜單選項(xiàng)及其下拉子 菜單選項(xiàng)。 3.顯示條設(shè)計(jì) (1)在VS用戶區(qū)左側(cè)工具箱中找到TextBox控件拖到計(jì)算器用區(qū)合適的位置,按住鼠標(biāo)左鍵在相應(yīng)調(diào)整點(diǎn)設(shè)置其長(zhǎng)度,設(shè)置其 高度時(shí)需要首先在屬性窗口把該控件的Mutiline屬性設(shè)置為T(mén)rue,

4、才可以使用鼠標(biāo)調(diào)整其高度。(2)在屬性窗口設(shè)置顯示條屬性:(Name)屬性為txt_Result;Text 屬性為0.(即:控件上顯示的內(nèi)容);TextAlign屬性為Right;4.其它控件設(shè)計(jì) 向窗體上添加控件,計(jì)算器分為3個(gè)模塊,分別是Textbox:顯示區(qū):顯示數(shù)字和計(jì)算結(jié)果的功能 button:計(jì)算區(qū):提供運(yùn)算符和數(shù)字,與用戶交互進(jìn)行運(yùn)算 radioButton:轉(zhuǎn)換區(qū): 用于進(jìn)制之間的轉(zhuǎn)換五 詳細(xì)代碼標(biāo)準(zhǔn)型using System;using System.Collections.Generic;using System.ComponentModel;using System.Da

5、ta;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication6 public partial class Form1 : Form public Form1() InitializeComponent();public string number;public int x;public double number1;private string a;private string abc;private void bu

6、tton0_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text += btn.Text;private void button1_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text;private void button2_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.T

7、ext += btn.Text;private void button3_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text += btn.Text;private void button4_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text += btn.Text;private void button9_Click(object sender, EventArgs e)Button btn

8、 = (Button)sender;txt_Result.Text += btn.Text;private void button8_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text += btn.Text;private void button7_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text += btn.Text;private void button6_Click(object

9、sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text += btn.Text;private void button5_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text += btn.Text;private void C_Click(object sender, EventArgs e)txt_Result.Text = ""this.btn_Result.Focus();private void

10、 sqrt_Click(object sender, EventArgs e) if (Convert.ToDouble(txt_Result.Text) < 0) this.txt_Result.Text = "error" else number1 = Convert.ToDouble(txt_Result.Text); number = "" txt_Result.Text = Convert.ToString(System.Math.Sqrt(number1); this.btn_Result.Focus();private void da

11、o_Click(object sender, EventArgs e) if (Convert.ToDouble(txt_Result.Text) = 0) this.txt_Result.Text = "error" else number1 = Convert.ToDouble(txt_Result.Text); number = "" txt_Result.Text = Convert.ToString(1 / number1); this.btn_Result.Focus();private void dian_Click(object send

12、er, EventArgs e) trynumber = Convert.ToString(number + "."); txt_Result.Text = Convert.ToString(number + ""); catch this.btn_Result.Focus();private void Backspace_Click(object sender, EventArgs e) if (txt_Result.Text = "" | txt_Result.Text = "0") txt_Result.Te

13、xt = "" else number1 = Convert.ToDouble(txt_Result.Text); number = Convert.ToString(number1 - number1 % 10) / 10); txt_Result.Text = number; this.btn_Result.Focus();private void bai_Click(object sender, EventArgs e) number = Convert.ToString(Convert.ToDouble(txt_Result.Text) / 100); txt_Re

14、sult.Text = number; number = "" this.btn_Result.Focus();private void zhengfu_Click(object sender, EventArgs e) number1 = Convert.ToDouble(txt_Result.Text); txt_Result.Text = Convert.ToString(0 - number1); this.btn_Result.Focus();private void X2_Click(object sender, EventArgs e) if (txt_Res

15、ult.TextLength > 0) number1 = Convert.ToDouble(number); number = Convert.ToString(number1 * number1); txt_Result.Text = number; number = "" this.btn_Result.Focus();private void 幫助ToolStripMenuItem_Click(object sender, EventArgs e) MessageBox.Show(“這是一個(gè)仿照windows的計(jì)算器應(yīng)用程序,功能雖然不齊但基本能運(yùn)行”);pr

16、ivate void 退出ToolStripMenuItem_Click(object sender, EventArgs e) Close();private void btn_Add_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void btn_Minus_Click(object sender, EventArgs e) Button btn

17、 = (Button)sender;txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void btn_Multiply_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void tn_Divide_Click(object send

18、er, EventArgs e) Button btn = (Button)sender; txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void btn_Result_Click(object sender, EventArgs e) double d_result;string s_txt = txt_Result.Text;int space = s_txt.IndexOf(' ');string s1 = s_txt.Substring(0, sp

19、ace);char operation = Convert.ToChar(s_txt.Substring(space + 1), 1);string s2 = s_txt.Substring(space + 3);double arg1 = Convert.ToDouble(s1);double arg2 = Convert.ToDouble(s2); switch (operation) case '+':d_result = arg1 + arg2;break;case '-':d_result = arg1 - arg2;break;case '*

20、':d_result = arg1 * arg2;break;case '/':if (arg2 = 0)throw new ApplicationException();elsed_result = arg1 / arg2; break;default:throw new ApplicationException(); txt_Result.Text = d_result.ToString(); private void 標(biāo)準(zhǔn)型TToolStripMenuItem_Click(object sender, EventArgs e) Form1 frm = new Fo

21、rm1(); frm.Show(); this.Hide();private void 粘貼ToolStripMenuItem_Click(object sender, EventArgs e) if (a = null) this.txt_Result.Text = this.abc; this.a += this.abc; else if (a != null && txt_Result.Text != null) this.txt_Result.Text = null; a = null; this.txt_Result.Text = this.abc; this.a +

22、= this.abc; private void 復(fù)制CToolStripMenuItem_Click(object sender, EventArgs e) if (abc = null) this.abc += this.txt_Result.Text; else abc = null; this.abc += this.txt_Result.Text; private void 科學(xué)型SToolStripMenuItem_Click(object sender, EventArgs e) Form fm2 = new Form2();fm2.Show(); this.Hide(); 科學(xué)

23、型using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace WindowsFormsApplication6 public partial class Form2 : Form public Form2() InitializeComponent(); private void rBt

24、n16_CheckedChanged(object sender, EventArgs e) this.btn_per.Enabled = false; this.btn_down.Enabled = false; this.btn_log.Enabled = false; this.btn_tan.Enabled = false;this.btn_sin.Enabled = false; this.btn_cos.Enabled = false; this.btn_Pi.Enabled = false; this.button9.Enabled = true; this.button8.En

25、abled = true; this.button7.Enabled = true; this.button6.Enabled = true; this.button5.Enabled = true; this.button4.Enabled = true; this.button3.Enabled = true; this.button2.Enabled = true; this.buttonA.Enabled = true; this.buttonB.Enabled = true; this.buttonC.Enabled = true; this.buttonD.Enabled = tr

26、ue; this.buttonE.Enabled = true; this.buttonF.Enabled = true;if (txt_Result.Text != "") int d1;string d2;string s_txt = txt_Result.Text; string s1 = s_txt.Substring(0); if (this.rBtn8.Checked) int a = System.Convert.ToInt32(s1, 16);d1 = a;d2 = System.Convert.ToString(d1, 8);txt_Result.Text

27、 = d2.ToString();else if (this.rBtn10.Checked) int a = System.Convert.ToInt32(s1, 16);d1 = a; txt_Result.Text = d1.ToString();else if (this.rBtn2.Checked) int a = System.Convert.ToInt32(s1, 16);d1 = a;d2 = System.Convert.ToString(d1, 2);txt_Result.Text = d2.ToString(); private void rBtn10_CheckedCha

28、nged(object sender, EventArgs e) this.btn_down.Enabled = false;this.btn_log.Enabled = false; this.btn_tan.Enabled = false; this.btn_sin.Enabled = false; this.btn_cos.Enabled = false; this.btn_Pi.Enabled = false; this.button9.Enabled = true; this.button8.Enabled = true; this.button7.Enabled = true; t

29、his.button6.Enabled = true; this.button5.Enabled = true; this.button4.Enabled = true; this.button3.Enabled = true; this.button2.Enabled = true; this.buttonA.Enabled = false; this.buttonB.Enabled = false; this.buttonC.Enabled = false; this.buttonD.Enabled = false; this.buttonE.Enabled = false; this.b

30、uttonF.Enabled = false; if (txt_Result.Text != "") int d1; string d2; string s_txt = txt_Result.Text; string s1 = s_txt.Substring(0); if (this.rBtn8.Checked) double a = Convert.ToDouble(s1); d1 = (int)a;d2 = System.Convert.ToString(d1, 8); txt_Result.Text = d2.ToString();else if (this.rBtn

31、16.Checked) double a = Convert.ToDouble(s1); d1 = (int)a; d2 = System.Convert.ToString(d1, 16); txt_Result.Text = d2.ToString(); else if (this.rBtn2.Checked) d1 = (int)a; double a = Convert.ToDouble(s1);d2 = System.Convert.ToString(d1, 2); txt_Result.Text = d2.ToString();private void rBtn8_CheckedCh

32、anged(object sender, EventArgs e) this.btn_per.Enabled = false; this.btn_down.Enabled = false; t his.btn_log.Enabled = false; this.btn_tan.Enabled = false;this.btn_sin.Enabled = false;this.btn_cos.Enabled = false; this.btn_Pi.Enabled = false; this.button9.Enabled = false; this.button9.Enabled = fals

33、e; this.button7.Enabled = true; this.button6.Enabled = true; this.button5.Enabled = true; this.button4.Enabled = true; this.button3.Enabled = true; this.button2.Enabled = true; this.buttonA.Enabled = false; this.buttonB.Enabled = false; this.buttonC.Enabled = false; this.buttonD.Enabled = false;this

34、.buttonE.Enabled = false;this.buttonF.Enabled = false;if (txt_Result.Text != "") int d1;string d2;string s_txt = txt_Result.Text;string s1 = s_txt.Substring(0);if (this.rBtn16.Checked) int a = System.Convert.ToInt32(s1, 8);d1 = a;d2 = System.Convert.ToString(d1, 16);txt_Result.Text = d2.To

35、String();else if (this.rBtn10.Checked) int a = System.Convert.ToInt32(s1, 8);d1 = a;txt_Result.Text = d1.ToString();else if (this.rBtn2.Checked) int a = System.Convert.ToInt32(s1, 8);d1 = a;d2 = System.Convert.ToString(d1, 2); txt_Result.Text = d2.ToString();private void rBtn2_CheckedChanged(object

36、sender, EventArgs e) this.btn_per.Enabled = false; this.btn_down.Enabled = false; this.btn_log.Enabled = false; this.btn_tan.Enabled = false; this.btn_sin.Enabled = false; this.btn_cos.Enabled = false; this.btn_Pi.Enabled = false; this.button9.Enabled = false; this.button8.Enabled = false; this.butt

37、on7.Enabled = false; this.button6.Enabled = false; this.button5.Enabled = false; his.button4.Enabled = false; this.button3.Enabled = false; this.button2.Enabled = false; this.buttonA.Enabled = false; this.buttonB.Enabled = false; this.buttonC.Enabled = false; this.buttonD.Enabled = false; this.butto

38、nE.Enabled = false; this.buttonF.Enabled = false; if (txt_Result.Text != "") int d1; string d2; string s_txt = txt_Result.Text; string s1 = s_txt.Substring(0); if (this.rBtn8.Checked) int a = System.Convert.ToInt32(s1, 2); d1 = a; d2 = System.Convert.ToString(d1, 8); txt_Result.Text = d2.T

39、oString(); else if (this.rBtn10.Checked) int a = System.Convert.ToInt32(s1, 2); d1 = a; txt_Result.Text = d1.ToString(); else if (this.rBtn16.Checked) int a = System.Convert.ToInt32(s1, 2); d1 = a; d2 = System.Convert.ToString(d1, 16);txt_Result.Text = d2.ToString(); private void radioButton8_Checke

40、dChanged(object sender, EventArgs e) this.txt_Result.ForeColor = Color.Black; private void rBtnBlue_CheckedChanged(object sender, EventArgs e) this.txt_Result.ForeColor = Color.Blue; private void rBtnRed_CheckedChanged(object sender, EventArgs e) this.txt_Result.ForeColor = Color.Red; private void r

41、BtnYellow_CheckedChanged(object sender, EventArgs e) this.txt_Result.ForeColor = Color.Yellow;private void button0_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void button1_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.

42、Text += btn.Text; private void button2_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void button3_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void button4_Click(object sender, EventArgs e) But

43、ton btn = (Button)sender;txt_Result.Text += btn.Text; private void button5_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void button6_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void button7_C

44、lick(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void button8_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void button9_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text

45、 += btn.Text; private void buttonA_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void buttonB_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void buttonC_Click(object sender, EventArgs e) Button

46、btn = (Button)sender;txt_Result.Text += btn.Text; private void buttonD_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void buttonE_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void buttonF_Click

47、(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void btn_neg_Click(object sender, EventArgs e) string s_txt = txt_Result.Text;double a = Convert.ToDouble(s_txt);double b = -a;txt_Result.Text = b.ToString(); private void btn_per_Click(object sender, Event

48、Args e) string s_txt = txt_Result.Text;double a = Convert.ToDouble(s_txt);double b = a / 100.0;txt_Result.Text = b.ToString();private void btn_Dot_Click(object sender, EventArgs e) Button btn = (Button)sender;txt_Result.Text += btn.Text; private void btn_Add_Click(object sender, EventArgs e)Button b

49、tn = (Button)sender;txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void btn_Sub_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void btn_mul_Click(object sender, Ev

50、entArgs e)Button btn = (Button)sender;txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void btn_div_Click(object sender, EventArgs e)Button btn = (Button)sender;txt_Result.Text = txt_Result.Text + " " + btn.Text + " " private void btn_sqr_Click

51、(object sender, EventArgs e) double d1;string d2; string s_txt = txt_Result.Text;string s1 = s_txt.Substring(0);if (this.rBtn2.Checked) int a = System.Convert.ToInt32(s1, 2);d1 = System.Math.Sqrt(double)a);d2 = System.Convert.ToString(int)d1, 2);txt_Result.Text = d2.ToString();else if (this.rBtn8.Checked) int a = System.Convert.ToInt32(s1, 8);d1 = System.Math.Sqrt(double)a);d2 = System.Convert.ToString(int)d1, 8);txt_Result.Text = d2.ToString();else if (this.rBtn16.Checked) int a

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論