簡(jiǎn)易計(jì)算器C#_第1頁(yè)
簡(jiǎn)易計(jì)算器C#_第2頁(yè)
簡(jiǎn)易計(jì)算器C#_第3頁(yè)
簡(jiǎn)易計(jì)算器C#_第4頁(yè)
簡(jiǎn)易計(jì)算器C#_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、簡(jiǎn)易計(jì)算器 實(shí)驗(yàn)報(bào)告簡(jiǎn)易計(jì)算器實(shí)驗(yàn)報(bào)告院系: 信息工程學(xué)院 專(zhuān)業(yè): 計(jì)算機(jī)科學(xué)與技術(shù) 學(xué)號(hào): 2013 姓名: 2015年12月一:功能實(shí)現(xiàn) 實(shí)現(xiàn)簡(jiǎn)單的加減乘除運(yùn)算,平方開(kāi)方運(yùn)算(含小數(shù)點(diǎn)) 回刪功能,清零功能 輸入字符無(wú)長(zhǎng)度限制,輸出結(jié)果保留16位有效數(shù)字。超出16位數(shù)字按科學(xué)計(jì)數(shù)法表示 運(yùn)算結(jié)果清零前可以保留繼續(xù)進(jìn)行運(yùn)算,解決無(wú)法多次連算問(wèn)題二:主要控件 label 用于顯示框前提示 textbox 用于顯示輸入和輸出的字符 button 用于盛放數(shù)字和運(yùn)算符,點(diǎn)擊后觸發(fā)相應(yīng)事件三:主要代碼 public partial class Form1 : Form double a = 0; d

2、ouble b = 0; bool c = false; string d; double x;a用來(lái)存放結(jié)果,b用來(lái)存放第一個(gè)輸入的數(shù)據(jù),d用來(lái)存放運(yùn)算符,x存放當(dāng)前textbox中的數(shù)據(jù)。數(shù)字鍵1-9對(duì)應(yīng)代碼為(用數(shù)字1舉例): private void button1_Click(object sender, EventArgs e)/按鈕1 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "1" 數(shù)字0增加部分代碼,用于辨別除數(shù)不能為0: private void butt

3、on10_Click(object sender, EventArgs e)/按鈕0 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "0" if (d = "/") textBox1.Clear(); MessageBox.Show("除數(shù)不能為0", "錯(cuò)誤提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); 加、減、乘、除、開(kāi)方、平方按鈕對(duì)應(yīng)代碼如下(以加號(hào)鍵舉例):

4、 private void button13_Click(object sender, EventArgs e)/加號(hào)按鈕 c = true; b = double.Parse(textBox1.Text); d = "+" 小數(shù)點(diǎn)按鈕: private void button20_Click(object sender, EventArgs e)/小?數(shù)簓點(diǎn)? if (textBox1.Text = "") textBox1.Text = "0." else if (textBox1.Text.IndexOf(".&quo

5、t;) >= 0) MessageBox.Show("已經(jīng)添加了小數(shù)點(diǎn)!", "提示"); else textBox1.Text = textBox1.Text + "." 回刪按鈕: private void button12_Click(object sender, EventArgs e)/回刪按鈕 x = Convert.ToDouble(textBox1.Text); textBox1.Text = Convert.ToString(x - x % 10) / 10);/實(shí)現(xiàn)逐個(gè)刪除的功能 清零按鈕: private

6、void button17_Click(object sender, EventArgs e)/清零按鈕 textBox1.Text = "" 等號(hào)按鈕: private void button11_Click(object sender, EventArgs e)/按恪?鈕¥= switch (d) case "+": a = b + double.Parse(textBox1.Text); break; case "-": a = b - double.Parse(textBox1.Text); break; case "

7、;*": a = b * double.Parse(textBox1.Text); break; case "/": a = b /double.Parse(textBox1.Text); break; case "x²": a = b * double.Parse(textBox1.Text); break; case "":a = Math.Sqrt(b); break; textBox1.Text = a + "" c = true; 四:運(yùn)行結(jié)果運(yùn)行后第一個(gè)界面加法 乘法(16位有效數(shù)字

8、) (減法和除法不再贅述)回刪:開(kāi)方: 平方: 源代碼: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 計(jì)算器 public partial class Form1 : Form double a = 0; double b = 0; bool c = false; stri

9、ng d; double x; public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) textBox1.Text = "歡迎使用!" c =true; private void button1_Click(object sender, EventArgs e)/按鈕1 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "1" private

10、 void button2_Click(object sender, EventArgs e)/按鈕2 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "2" private void button3_Click(object sender, EventArgs e)/按鈕3 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "3" private void button

11、4_Click(object sender, EventArgs e)/按鈕4 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "4" private void button5_Click(object sender, EventArgs e)/按鈕5 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "5" private void button6_Click(obje

12、ct sender, EventArgs e)/按鈕6 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "6" private void button7_Click(object sender, EventArgs e)/按鈕7 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "7" private void button8_Click(object sender, E

13、ventArgs e)/按鈕8 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "8" private void button9_Click(object sender, EventArgs e)/按鈕9 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "9" private void button10_Click(object sender, EventArgs e)

14、/按鈕0 if (c = true) textBox1.Text = "" c = false; textBox1.Text += "0" if (d = "/") textBox1.Clear(); MessageBox.Show("除數(shù)不能為0", "錯(cuò)誤提示", MessageBoxButtons.OK, MessageBoxIcon.Warning); private void button11_Click(object sender, EventArgs e)/按鈕= switch (

15、d) case "+": a = b + double.Parse(textBox1.Text); break; case "-": a = b - double.Parse(textBox1.Text); break; case "*": a = b * double.Parse(textBox1.Text); break; case "/": a = b /double.Parse(textBox1.Text); break; case "x²": a = b * double.P

16、arse(textBox1.Text); break; case "ì阾":a = Math.Sqrt(b); break; textBox1.Text = a + "" c = true; private void button19_Click(object sender, EventArgs e)/平方按鈕 c = true; b = double.Parse(textBox1.Text); d = "x²" private void button18_Click(object sender, EventArg

17、s e)/開(kāi)平方按鈕 c = true; b = double.Parse(textBox1.Text); d = "ì阾" private void button12_Click(object sender, EventArgs e)/回刪按鈕 x = Convert.ToDouble(textBox1.Text); textBox1.Text = Convert.ToString(x - x % 10) / 10);/實(shí)現(xiàn)逐個(gè)刪除的功能 private void button17_Click(object sender, EventArgs e)/清零按鈕 t

18、extBox1.Text = "" private void button13_Click(object sender, EventArgs e)/加號(hào)按鈕 c = true; b = double.Parse(textBox1.Text); d = "+" private void button14_Click(object sender, EventArgs e)/減號(hào)按鈕 c = true; b = double.Parse(textBox1.Text); d = "-" private void button15_Click(object sender, EventArgs e)/乘號(hào)按鈕 c = true; b = double.Parse(textBox1.Text); d = "*" private void button16_Click(object sender, EventArgs e)/除號(hào)按鈕 c = true; b = double.Parse(textBox1.Text); d = "/" pr

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論