⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 term.cs

📁 Data Structures and Algorithms with Object-Oriented Design Patterns in C# 这本书的范例代码dll自己反编译的source
💻 CS
字号:
namespace Opus6
{
    using System;

    [Version("$Id: Term.cs,v 1.4 2001/10/28 19:50:09 brpreiss Exp $"), Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng.")]
    public class Term : ComparableObject
    {
        public Term(Term term) : this(term.coefficient, term.exponent)
        {
        }

        public Term(double coefficient, int exponent)
        {
            this.coefficient = coefficient;
            this.exponent = exponent;
        }

        public override int CompareTo(object obj)
        {
            Term term1 = (Term) obj;
            if (this.exponent == term1.exponent)
            {
                if (this.coefficient < term1.coefficient)
                {
                    return -1;
                }
                if (this.coefficient > term1.coefficient)
                {
                    return 1;
                }
                return 0;
            }
            return (this.exponent - term1.exponent);
        }

        public void Differentiate()
        {
            if (this.exponent > 0)
            {
                this.coefficient *= this.exponent;
                this.exponent--;
            }
            else
            {
                this.coefficient = 0;
            }
        }

        public static Term operator +(Term t1, Term t2)
        {
            if (t1.exponent != t2.exponent)
            {
                throw new ArgumentException("unequal exponents");
            }
            return new Term(t1.coefficient + t2.coefficient, t1.exponent);
        }

        public override string ToString()
        {
            return (this.coefficient + "x^" + this.exponent);
        }


        public double Coefficient
        {
            get
            {
                return this.coefficient;
            }
        }

        public int Exponent
        {
            get
            {
                return this.exponent;
            }
        }


        protected double coefficient;
        protected int exponent;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -