# 面向对象编写一个计算器

namespace Program
{
//显示抽象类
public abstract class Print
{
public decimal Result { get; set; }
public Print(decimal result)
{
this.Result = result;
}
public abstract void print();
}
public class shuchu1 : Print
{
public shuchu1(decimal result) : base(result) { }
public override void print()
{
Console.WriteLine("输出方式1输出" + Result);
}
}
public class shuchu2 : Print
{
public shuchu2(decimal result) : base(result) { }
public override void print()
{
Console.WriteLine("输出方式2输出" + Result);
}
}
//计算抽象类
public abstract class Opreation
{
public decimal Num1 { get; set; }
public decimal Num2 { get; set; }
public virtual decimal OpreationNum()
{
decimal result = 0;
return result;
}
}
#region CalculateMode
//加法运算
{
public override decimal OpreationNum()
{
return this.Num1 + this.Num2;
}
}

//减法
public class subtraction : Opreation
{
public override decimal OpreationNum()
{
return this.Num1 - this.Num2;
}
}
public class multiplication : Opreation
{
public override decimal OpreationNum()
{
return this.Num1 * this.Num2;
}
}
public class division : Opreation
{
public override decimal OpreationNum()
{
return this.Num1 / this.Num2;
}
}
#endregion

public abstract class CalculateFactory
{
public abstract Opreation Calculate();
}
#region CalculateFactory
{
public override Opreation Calculate()
{
}
}
public class SubtractionFactory : CalculateFactory
{
public override Opreation Calculate()
{
return new subtraction();
}
}
public class MultiplicationFactory : CalculateFactory
{
public override Opreation Calculate()
{
return new multiplication();
}
}
public class DivisionFactory : CalculateFactory
{
public override Opreation Calculate()
{
return new division();
}
}
#endregion
//取模计算
public class Molding : Opreation
{
public override decimal OpreationNum()
{
return this.Num1 % this.Num2;
}
}
//取模工厂
public class MoldingFactory : CalculateFactory
{
public override Opreation Calculate()
{
return new Molding();
}
}
//取模值显示方式
public class shuchu3 : Print
{
public shuchu3(decimal result) : base(result) { }
public override void print()
{
Console.WriteLine("显示方式3输出" + Result);
}
}
public class Calculator
{
static void Main(string[] args)
{
print1.print();

CalculateFactory opreationSubtraction = new SubtractionFactory();
Opreation Subtraction = opreationSubtraction.Calculate();
Subtraction.Num1 = 30;
Subtraction.Num2 = 10;
Subtraction.OpreationNum();
Print print2 = new shuchu2(Subtraction.OpreationNum());
print2.print();

CalculateFactory opreationMolding = new MoldingFactory();
Opreation molding = opreationMolding.Calculate();
molding.Num1 = 10;
molding.Num2 = 8;
Print print3 = new shuchu3(molding.OpreationNum());
print3.print();
}
}
}