标签:
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace jisuan { 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; } } 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; } } } using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace jisuan { public class OperationFactory { public static Operation createOperate(string operate) { Operation oper = null; switch (operate) { case "+": oper = new OperationAdd(); break; case "-": oper = new OperationSub(); break; case "*": oper = new OperationMul(); break; case "/": oper = new OperationDiv(); break; } return oper; } } }using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace jisuan { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); } } }
标签:
原文地址:http://www.cnblogs.com/gdss/p/5084052.html