欢迎来到天天文库
浏览记录
ID:57167995
大小:26.50 KB
页数:5页
时间:2020-08-05
《计算器编程代码复习进程.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、计算器编程代码精品文档usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespacecalculator{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidForm1_Load(objectsend
2、er,EventArgse){}privatevoidbtn_Add_Click(objectsender,EventArgse){Buttonbtn=(Button)sender;//空格用来分隔数值和运算符txt_Result.Text=txt_Result.Text+""+btn.Text+"";}privatevoidbtn_Result_Click(objectsender,EventArgse){//保存计算结果doubled_result;//保存文本框中的算术表达式strings_txt=txt_Result.Text;//查找空格位置intspace=s_txt.Ind
3、exOf('');//s1保存第一个运算数strings1=s_txt.Substring(0,space);//operation用来保存运算数charopoperation=Convert.ToChar(s_txt.Substring((space+1),1));//s2保存第二个运算数strings2=s_txt.Substring(space+3);//将运算数从string转成Double型doublearg1=Convert.ToDouble(s1);doublearg2=Convert.ToDouble(s2);//根据运算符进行计算switch(opoperation){
4、case'+':d_result=arg1+arg2;break;case'-':d_result=arg1-arg2;收集于网络,如有侵权请联系管理员删除精品文档break;case'*':d_result=arg1*arg2;break;case'/':if(arg2==0){//抛出异常thrownewApplicationException();}else{d_result=arg1/arg2;}break;default:thrownewApplicationException();}//将计算结果显示在文本框中txt_Result.Text=d_result.ToString
5、();}privatevoidbtn_Clear_Click(objectsender,EventArgse){//将文本清空txt_Result.Text="";}privatevoidbutton0_Click(objectsender,EventArgse){Buttonbtn=(Button)sender;txt_Result.Text+=btn.Text;}privatevoidbut1_Click(objectsender,EventArgse){Buttonbtn=(Button)sender;//空格用来分隔数值和运算符txt_Result.Text=txt_Result
6、.Text+""+btn.Text+"";}privatevoidbut2_Click(objectsender,EventArgse){Buttonbtn=(Button)sender;//空格用来分隔数值和运算符txt_Result.Text=txt_Result.Text+""+btn.Text+"";}privatevoidbut3_Click(objectsender,EventArgse){Buttonbtn=(Button)sender;//空格用来分隔数值和运算符txt_Result.Text=txt_Result.Text+""+btn.Text+"";}private
7、voidbutton1_Click(objectsender,EventArgse)收集于网络,如有侵权请联系管理员删除精品文档{Buttonbtn=(Button)sender;txt_Result.Text+=btn.Text;}privatevoidbutton2_Click(objectsender,EventArgse){Buttonbtn=(Button)sender;txt_Result.Text+=btn.Text;
此文档下载收益归作者所有