greatcircle49's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
New Members
Active Posts:
5 (0.01 per day)
Joined:
31-October 12
Profile Views:
328
Last Active:
User is offline Apr 06 2013 11:09 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   greatcircle49 has not set their status

Posts I've Made

  1. In Topic: how to get data from context in stategy

    Posted 28 Mar 2013

    thank you very much for your help, I want to uses stategy to write OutputSupport, OPInfix,OPPrefix,OPSuffix
    this is original source
    Posted Image

    Expression
        public abstract class Expression
        {
            public abstract double Evaluate();
    
            public abstract Expression Derive();
    
            public abstract string OPInfixToString();
            public abstract string OPPrefixToString();
            public abstract string OPSuffixToString();
        }
    
    

    ConstExpr
     public class ConstExpr : Expression
        {
            private double c;
            private Expression cachedDerive = null;
    
            // CONSTRUCTORS
            public ConstExpr()
            {
                c = 0;
            }
    
            public ConstExpr(double _value)
            {
                c = _value;
            }
    
            public override double Evaluate()
            {
                return c;
            }
    
            public override Expression Derive()
            {
                if (cachedDerive == null)
                    cachedDerive = new ConstExpr(0);
    
                return cachedDerive;
            }
    
            
            public override string OPInfixToString()
            {
                return c.ToString();   
            }
            public override string OPPrefixToString()
            {
                //do something
                return null;
            }
            public override string OPSuffixToString()
            {
                //do some thing
                return null;
            }
        }
    
    

    NomialExpr
        public class NomialExpr : Expression
        {
            private double x;
            private double a;
            private double n;
            private Expression cachedDerive = null;
    
            // CONSTRUCTORS
            public NomialExpr()
            {
                a = 1;
                n = 1;
            }
            public static Expression Create(double _x, double _h, double _s)
            {
                if (_h == 0||_s==0)
                    return new ConstExpr(_h);
                else
                    return new NomialExpr(_x, _h, _s);
            }
            private NomialExpr(double _x, double _h, double _s)
            {
                x = _x;
                a = _h;
                n = _s;
            }
    
    
            public override double Evaluate()
            {
                return (a * Math.Pow(x, n));
            }
    
            public override Expression Derive()
            {
                if(cachedDerive==null)
                    cachedDerive = new NomialExpr(x, this.a * this.n, this.n - 1);
    
                return cachedDerive;
            }
    
            
            public override string OPInfixToString()
            {
                return (a + "X ^ " + n);
            }
            public override string OPPrefixToString()
            {
                //do some thing
                return null;
            }
            public override string OPSuffixToString()
            {
                //do some thing
                return null;
            }
        }
    
    

    BinaryExpr

      public abstract class BinaryExpr : Expression
        {
            protected Expression u;
            protected Expression v;
            protected Expression cachedDerive = null;
    
            public override string OPInfixToString()
            {
                return (u.ToString() + v.ToString());
            }
            public override string OPPrefixToString()
            {
                //do some thing
                return null;
            }
            public override string OPSuffixToString()
            {
                //do some thing
                return null;
            }
        }
    
    

    AdditiveExpr
       public class AdditiveExpr : BinaryExpr
        {
    
            private bool isAdditiveExpr = true;  
    
            // CONSTRUCTORS
            public AdditiveExpr(Expression _u, Expression _v, bool _isDaThucTong)
            {
                u = _u;
                v = _v;
                isAdditiveExpr = _isDaThucTong;
            }
    
            public override double Evaluate()
            {
                if (isAdditiveExpr)
                    return u.Evaluate() + v.Evaluate();
                return u.Evaluate() - v.Evaluate();
            }
    
            public override Expression Derive()
            {
                if(cachedDerive == null)
                    cachedDerive = new AdditiveExpr(u.Derive(), v.Derive(), isAdditiveExpr);
    
                return cachedDerive;
            }
    
            public override string OPInfixToString()
            {
                if (isAdditiveExpr) 
                    return ("(" + u.ToString() + " + " + v.ToString() + ")");
                return ("(" + u.ToString() + " - " + v.ToString() + ")");  
            }
            public override string OPPrefixToString()
            {
                //do some thing
                return null;
            }
            public override string OPSuffixToString()
            {
                //do some thing
                return null;
            }
        }
    
    
  2. In Topic: how to get data from context in stategy

    Posted 27 Mar 2013

    with ConstExp, NomialExpr, BinaryExp ( AdditiveExpr) has 3 way to write ToString()
    So I think I can use Stategy.
    I don't know how to OPInfix, OPPrefix, OPSuffix understand what is type of Expression(ConstExp, MonialExp....), don't use swith case
    Posted Image

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

greatcircle49 hasn't added any friends yet.

Comments

greatcircle49 has no profile comments yet. Why not say hello?