求C#计算器完整代码!!!谢谢!!!
望高手发给本人邮箱 sunle0710@126.com
希望窗体和控制台各一份!
只需要实现 简单的加减乘除,以及符号问题就ok!
谢谢!
------解决方案--------------------
public class Operation
{
private double _numberA = 0;
private double _numberB = 0;
public double NumberA
{
get
{
return _numberA;
}
set
{
_numberA = value;
}
}
public double NumberB
{
get
{
return _numberB;
}
set
{
_numberB = value;
}
}
public virtual double GetResult()
{
double result = 0;
return result;
}
public static string checkNumberInput(string currentNumber, string inputString)
{
string result = "";
if (inputString == ".")
{
if (currentNumber.IndexOf(".") < 0)
{
if (currentNumber.Length == 0)
result = "0" + inputString;
else
result = currentNumber + inputString;
}
}
else if (currentNumber == "0")
{
result = inputString;
}
else
{
result = currentNumber + inputString;
}
return result;
}
}
class OperationAdd : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA + NumberB;
return result;
}
}
class OperationSub : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA - NumberB;
return result;
}
}
class OperationMul : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberA * NumberB;
return result;
}
}
class OperationDiv : Operation
{
public override double GetResult()
{
double result = 0;
if (NumberB == 0)
throw new Exception("除数不能为0。");
result = NumberA / NumberB;
return result;
}
}
class OperationSqr : Operation
{
public override double GetResult()
{
double result = 0;
result = NumberB * NumberB;
return result;
}
}
class OperationSqrt : Operation
{
public override double GetResult()
{