📄 term.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 + -