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

📄 polynomial.h

📁 我写的多项式操作代码
💻 H
字号:
/*
	A head file for c++ programming and polynomial calculation.
	Copyright @ Tony.v.sh Tsinghua University
*/

/*
	A fetal mistake was discovered on Aug 11th 2003.
	When using "Polynomial b = c"
	The overloaded function operator = is NOT run.

	soluted Aug.13th 2003.use Polynomial( Polynomial & )
*/

#include<iostream>
#include<cassert>
#include<math.h>

using namespace std;

class Polynomial
{
	friend ostream &operator <<( ostream &in, const Polynomial &source );
		//It can't be omitted! Although the function doesn't use the private
		//part of class Polynomial.
	friend Polynomial operator+( const double, const Polynomial& );
	
	private:
		int _degree;
		double * _a;
		void condense();
		Polynomial &operator = ( const Polynomial & ) const; 
		
		static int _accuracy; //Max degrees after point.

	public:
		Polynomial(){ _degree = -1; _a = 0; };
			//degree is equal to -1 means a NULL polynomial.
		Polynomial( double );
		Polynomial( int , double * );
		Polynomial( Polynomial & );
			//Fetal!! if you type Polynomial b = c; This function is called.
		~Polynomial();

		static void setAccuracy( int i ){ _accuracy = i; }
		static int getAccuracy(){ return _accuracy; }

		inline int degree() const{ return _degree; };
			//degree is equal to -1 means a NULL polynomial.

		Polynomial &operator = ( const Polynomial & );
		bool operator == ( const Polynomial & ) const;
		
		Polynomial operator * ( double ) const;
		Polynomial operator + ( const Polynomial & ) const;
			//You can use (Polynomial)a + 2, but not 2+(Polynomial)a!
		Polynomial operator - ( const Polynomial & ) const;
		Polynomial operator * ( const Polynomial & ) const;
		Polynomial divide( const Polynomial &, Polynomial & ) const;
			//Polynomial division, return quotient and arithmatical compliment. 
		double function( double );
		
		Polynomial diff() const;
		Polynomial integrate() const;
			//Return without a const number.
		int root( double * );
			//You must make sure the volumn of the pointer is enough
			//if Polynomial == 0, return -1
		
		void display( char * = "x" ) const;
		
};






⌨️ 快捷键说明

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