示例#1
0
        public static FractionList ReadFromFile(string name)
        {
            string[]     ints;
            FractionList result = new FractionList();

            foreach (string str in File.ReadAllLines(name))
            {
                ints = str.Split();
                int num = int.Parse(ints[0]);
                int den = int.Parse(ints[1]);

                result.Add(new Rational(num, den));
            }

            return(result);
        }
示例#2
0
        private static FractionList PlusMinusImpl(FractionList lhs, FractionList rhs, Operation op)
        {
            if (lhs == null)
            {
                return(rhs);
            }

            if (rhs == null)
            {
                return(lhs);
            }

            FractionList shorter = (lhs.vals.Count <= rhs.vals.Count ? lhs : rhs);
            FractionList longer  = (lhs.vals.Count > rhs.vals.Count ? lhs : rhs);
            FractionList result  = new FractionList();

            if (op == Operation.Plus)
            {
                for (int i = 0; i < shorter.vals.Count; ++i)
                {
                    result.Add(lhs.vals[i] + rhs.vals[i]);
                }
            }
            else
            {
                for (int i = 0; i < shorter.vals.Count; ++i)
                {
                    result.Add(lhs.vals[i] - rhs.vals[i]);
                }
            }


            if (shorter.vals.Count < longer.vals.Count)
            {
                for (int i = shorter.vals.Count; i < longer.vals.Count; ++i)
                {
                    result.Add(longer.vals[i]);
                }
            }

            return(result);
        }
 public Polynomial(FractionList mults)
 {
     this.mults = mults;
 }