#include <iostream>
#include "wielomian.h"
using namespace std;

Wielomian::Wielomian()
{
	st=0;
	wsp=new double[1];
	*wsp=0;
}

Wielomian::Wielomian(int st, double *wsp)
{
	this->st=st;
	this->wsp=new double[st+1];
	for(int i=0; i<=st; i++)
		*(this->wsp+i)=*(wsp+i);
}

Wielomian::Wielomian(const Wielomian & w)
{
	this->st=w.st;
	wsp=new double[st+1];
	for(int i=0; i<=st; i++)
		wsp[i]=w.wsp[i];
}

Wielomian  Wielomian::Pochodna(int st)
{
  /* pochodna - metoda nie zaimplementowana */
	return *this;

}

ostream &operator<<(ostream &o,  Wielomian &w)
{
	o << "f(x) = ";
	for(int i=w.st; i>0; i--)
		if(w.wsp[i]!=0) 
		{
			 if(w.wsp[i]!=1.0) o << showpos << w.wsp[i] << noshowpos ;
			 if(i!=1) o << " x^"  << i  << " "; else cout << " x " ;
		}
	
	if (w.wsp[0]!=0 || w.st==0) o << showpos << w.wsp[0] << noshowpos << endl;
	return o;
}

Wielomian::~Wielomian()
{
	delete [] wsp;
}

Wielomian& Wielomian::Wczytaj()
{
   int st;
   cout << "Stopien wielomianu ?" << endl ;
   cin >> st;
   this->st=st;
   this->wsp=new double[st+1];

	for(int i=st; i>=0; i--)
   {
      cout << "a[" << i << "]= " ;
      cin >> this->wsp[i];
   }
   return *this;
}
