资源描述:
《C#程序设计计算器编程代码》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Windows.Forms;namespace计算器{staticclassProgram{//////应用程序的主入口点。///[STAThread]staticvoidMain(){Application.EnableVisualStyles();Application.SetCompatibleTextRenderingDefault(false);Application.Run(newForm1()
2、);}}}usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;namespace计算器{publicpartialclassForm1:Form{publicForm1(){InitializeComponent();}privatevoidbutton1_Click(objectsender,EventArgse){intfirst=0,second=0,result=0;stringsymb
3、ol;first=Convert.ToInt16(textBox1.Text.Trim());second=Convert.ToInt16(textBox3.Text.Trim());symbol=comboBox1.Text;switch(symbol){case"+":result=first+second;break;//方法的封装case"-":result=first-second;break;case"*":result=first*second;break;case"/":result=first/second;break;}textBox2.Text=result.ToS
4、tring();}privatevoidbutton3_Click(objectsender,EventArgse){intfir=0,sec=0,result=0;stringsymbol;fir=Convert.ToInt16(textBox1.Text.Trim());sec=Convert.ToInt16(textBox3.Text.Trim());symbol=comboBox1.Text;工厂.creatopertion(fir,sec,symbol).getresult();//静态方法不需要(暂时)实例化直接调用textBox2.Text=工厂.creatopertion
5、(fir,sec,symbol).getresult().ToString();}privatevoidbutton2_Click(objectsender,EventArgse){intfir=0,sec=0,result=0;stringsymbol;fir=Convert.ToInt16(textBox1.Text.Trim());sec=Convert.ToInt16(textBox3.Text.Trim());symbol=comboBox1.Text;封装cal=new封装(fir,sec,symbol);result=cal.getresult();textBox2.Tex
6、t=result.ToString();}}}usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace计算器{class多态和继承{publicintfir;publicintsec;publicstringsyb;public多态和继承(intfir,intsec,stringsyb)//构造函数名称和类的名称相等{this.fir=fir;this.sec=sec;this.syb=syb;}publicvirtualintgetresult()//继承{intres
7、ult=0;returnresult;}}}usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;namespace计算器{class工厂{publicstatic多态和继承creatopertion(intfir,intsec,stringsyb){多态和继承muti=null;//muti是从父类实列出来的一个对象switch(