C 编程 科学计算器.docx
《C 编程 科学计算器.docx》由会员分享,可在线阅读,更多相关《C 编程 科学计算器.docx(18页珍藏版)》请在冰豆网上搜索。
C编程科学计算器
usingSystem;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Text;
usingSystem.Windows.Forms;
namespaceCalculator
{
publicpartialclassCounter:
Form
{
publicCounter()
{
InitializeComponent();
}
doublenum1,num2;
doubleresult=0;
intop;
intflag=0;//开始标志
intsp=0;//判断除数为零时移除监听
intmax=0;//范围标识
inteq=0;
#region功能键
privatevoidon_Click(objectsender,EventArgse)//开始
{
flag=1;
sp=0;
max=0;
this.numInput.Text="0";
this.txtInput.Text="";
}
privatevoidoff_Click(objectsender,EventArgse)//关闭
{
flag=0;
sp=0;
max=0;
this.numInput.Text="";
this.txtInput.Text="";
}
privatevoidbutton9_Click(objectsender,EventArgse)//删除
{
max=0;
if(flag==1&&sp==0)
{
stringnumstring=this.numInput.Text;
if(numstring.Length>0)
{
stringtemp=numstring.Substring(0,numstring.Length-1);
this.numInput.Text=temp.ToString();
}
else
{
this.numInput.Text="0";
}
}
}
privatevoidclear_Click(objectsender,EventArgse)//c清零
{
max=0;
if(flag==1)
{
sp=0;
this.numInput.Text="0";
this.txtInput.Text="";
}
}
privatevoiddelete_Click(objectsender,EventArgse)//清零
{
max=0;
if(flag==1)
{
sp=0;
this.numInput.Text="0";
}
}
#endregion
#region运算符
privatevoidequal_Click(objectsender,EventArgse)//等号
{
eq=1;
if(flag==1&&sp==0)
{
max=0;
num2=Convert.ToDouble(this.numInput.Text);
this.txtInput.Text+=num2.ToString();
this.txtInput.Text+="=";
txtInput.Text=null;
switch(op)
{
case1:
result=num1+num2;
break;
case2:
result=num1-num2;
break;
case3:
result=num1*num2;
break;
case4:
result=num1/num2;
break;
case5:
result=Math.Pow(num1,num2);
break;
case6:
result=Mod(num1,num2);
break;
default:
return;
}
if(op==4&&num2==0)
{
this.numInput.Text="除数不能为0";
sp=1;
}else
//this.txtInput.Text+=result.ToString();
this.numInput.Text=result.ToString();
}
}
privatevoidsub_Click(objectsender,EventArgse)//减法
{
max=0;
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
this.txtInput.Text+=num1.ToString();
numInput.Text="";
this.txtInput.Text+="-";
op=2;
}
}
privatevoidmul_Click(objectsender,EventArgse)//乘法
{
max=0;
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
this.txtInput.Text+=num1.ToString();
this.numInput.Text="";
this.txtInput.Text+="*";
op=3;
}
}
privatevoiddivide_Click(objectsender,EventArgse)//除法
{
max=0;
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
this.txtInput.Text+=num1.ToString();
this.numInput.Text="";
this.txtInput.Text+="/";
op=4;
}
}
privatevoidplus_Click(objectsender,EventArgse)//加法
{
max=0;
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
this.txtInput.Text+=num1.ToString();
numInput.Text="";
this.txtInput.Text+="+";
op=1;
}
}
publicdoubleMod(doublex,doubley)//取模运算
{
max=0;
inttemp=Convert.ToInt32(x/y);
return(x-y*temp);
}
privatevoidpower_Click(objectsender,EventArgse)//幂运算
{
max=0;
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(numInput.Text);
this.txtInput.Text+=num1.ToString();
this.numInput.Text="";
this.txtInput.Text+="^";
op=5;
}
}
privatevoidrecip_Click(objectsender,EventArgse)//倒数
{
max=0;
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
doubletemp=0;
temp=1/num1;
this.txtInput.Text="1/"+num1.ToString()+"=";
this.numInput.Text=temp.ToString();
}
}
privatevoidpercent_Click(objectsender,EventArgse)
{
max=0;
if(flag==1&&sp==0)
{
//doubletemp=Convert.ToDouble(this.numInput.Text);
//this.txtInput.Text+=temp.ToString();
//temp=temp/100;
//this.numInput.Text=temp.ToString();
//this.txtInput.Text+="%=";
num1=Convert.ToDouble(this.numInput.Text);
this.txtInput.Text+=num1.ToString();
this.numInput.Text="";
this.txtInput.Text+="%";
op=6;
}
}
#endregion
#region数字
privatevoidone_Click(objectsender,EventArgse)//1
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="1";
eq=0;
}else
this.numInput.Text+="1";
}
}
privatevoidtwo_Click(objectsender,EventArgse)//2
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="2";
eq=0;
}
else
this.numInput.Text+="2";
//this.txtInput.Text+="2";
}
}
privatevoidthree_Click(objectsender,EventArgse)//3
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="3";
eq=0;
}
else
this.numInput.Text+="3";
//this.txtInput.Text+="3";
}
}
privatevoidfour_Click(objectsender,EventArgse)//4
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="4";
eq=0;
}
else
this.numInput.Text+="4";
//this.txtInput.Text+="4";
}
}
privatevoidfive_Click(objectsender,EventArgse)//5
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="5";
eq=0;
}
else
this.numInput.Text+="5";
//this.txtInput.Text+="5";
}
}
privatevoidsix_Click(objectsender,EventArgse)//6
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="6";
eq=0;
}
else
this.numInput.Text+="6";
//this.txtInput.Text+="6";
}
}
privatevoidseven_Click(objectsender,EventArgse)//7
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="7";
eq=0;
}
else
this.numInput.Text+="7";
//this.txtInput.Text+="7";
}
}
privatevoideight_Click(objectsender,EventArgse)//8
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="8";
eq=0;
}
else
this.numInput.Text+="8";
//this.txtInput.Text+="8";
}
}
privatevoidnight_Click(objectsender,EventArgse)//9
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="9";
eq=0;
}
else
this.numInput.Text+="9";
//this.txtInput.Text+="9";
}
}
privatevoidzero_Click(objectsender,EventArgse)//0
{
if(flag==1&&sp==0&&max==0)
{
if(this.numInput.Text=="0")
{
this.numInput.Text="";
}
if(eq==1)
{
this.numInput.Text="0";
eq=0;
}
else
this.numInput.Text+="0";
//this.txtInput.Text+="0";
}
}
privatevoiddian_Click(objectsender,EventArgse)//小数点
{
if(flag==1&&sp==0&&max==0)
{
if(eq==1)
{
this.numInput.Text=".";
eq=0;
}
else
this.numInput.Text+=".";
//this.txtInput.Text+=".";
}
}
#endregion
#region三角函数
privatevoidsin_Click(objectsender,EventArgse)//sin
{
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
doubletemp=Math.PI*(num1/180);
this.txtInput.Text+="sin("+num1+")=";
num1=Math.Sin(temp);
this.numInput.Text=num1.ToString();
//this.txtInput.Text+=num1.ToString();
}
}
privatevoidcos_Click(objectsender,EventArgse)//cos
{
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
doubletemp=Math.PI*(num1/180);
this.txtInput.Text+="cos("+num1+")=";
num1=Math.Cos(temp);
this.numInput.Text=num1.ToString();
}
}
privatevoidtan_Click(objectsender,EventArgse)//tan
{
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
doubletemp=Math.PI*(num1/180);
this.txtInput.Text+="tan("+num1+")=";
num1=Math.Tan(temp);
this.numInput.Text=num1.ToString();
}
}
#endregion
#region帮助
privatevoid关于产品ToolStripMenuItem_Click(objectsender,EventArgse)
{
MenuAboutabout=newMenuAbout();
about.Show();
}
privatevoidchange_Click(objectsender,EventArgse)
{
max=0;
if(flag==1&&sp==0)
{
num1=Convert.ToDouble(this.numInput.Text);
num1=-num1;
this.numInput.Text=num1.ToString();
}
}
privatevoid使用手册ToolStripMenuItem_Click(objectsender,EventArgse)
{
MenuUseuse=newMenuUse();
use.Show();
}
#endregion
#region皮肤
privatevoid皮肤1ToolStripMenuItem_Click(objectsender,EventArgse)
{
skinEngine1.SkinFile=Application.StartupPath+@"\Calmness.ssk";
}
privatevoid皮肤2ToolStripMenuItem_Click(objectsender,EventArgse)
{
skinEngine1.SkinFile=Application.StartupPath+@"\DeepCyan.ssk";
}
privatevoid皮肤3ToolStripMenuItem_Click(objectsender,EventArgse)
{
skinEngine1.SkinFile=Application.StartupPath+@"\Eighteen.ssk";
}
privatevoid皮肤4ToolStripMenuItem_Click(objectsender,EventArgse)
{
skinEngine1.SkinFile=Application.StartupPath+@"\GlassGreen.ssk";
}
privatevoid皮肤5ToolStripMenuItem_Click(objectsender,EventArgse)
{
skinEngine1.SkinFile=Application.StartupPath+@"\Silver.ssk";
}
#endregion
#region复制粘贴
privatevoid复制ToolStripMenuItem_