//*****************************************************************************
// ICS 211 Data Structures 2001 Spring Semester
// Project : HW 4
//
// File : poly.h
// Date : 23/04/2001
// Author : Seniz Demir
// 	    Hakan Kul
//
// Description: Definition of expcoef and Polynom classes
//
// ---------------------------------------------------------------------------
//  Copyright (C) 2001 Yeditepe University
//  		       Computer Engineering Department
//  		       All rights reserved
// ---------------------------------------------------------------------------

#ifndef POLY_H
#define POLY_H

#include <iostream.h>
#include "list.h"
#include "listnd.h"
// expcoef class
// ---------------------------------------------------------------------------
// Implementation Notes: Each polynom will be stored as a link list. Each node
// of the link list stores one term of the polynom. Each term has a coefficient
// and an exponent. expcoef class is for the terms of the polynom so for the 
// nodes of the link list
// --------------------------------------------------------------------------

class expcoef {
	public :
		expcoef(); 
		void read(); 
		void print();
		int getexp();
		int getcoef();
		void setcoef(int );
		void setexp(int );
	private:	
		int exponent;
		int coefficient;
};

// Constructor of the class. 
// -------------------------------------------------------------------------
expcoef::expcoef()
{
	exponent=0;
	coefficient=0;
}

// read function reads the coefficient and the exponent of the term from the 
// user
// -------------------------------------------------------------------------
void expcoef::read()
{
	cout <<"Coefficient of the term: " ;
        cin>>coefficient;	
	cout <<"Exponent of the term: " ;
	cin>>exponent;
}

// print function prints the term to the screen
// -------------------------------------------------------------------------
void expcoef::print()
{
	cout<<coefficient;
	cout<<"x"<<"^"<<exponent;
}

// getexp function returns the exponent of the term
// ------------------------------------------------------------------------ 
int expcoef::getexp()
{
	return exponent;
}

// getcoef function returns the coefficient of the term
//-------------------------------------------------------------------------
int expcoef::getcoef()
{
	return coefficient;
}

// setexp function sets the exponent of the term
// -----------------------------------------------------------------------
void  expcoef::setexp(int y)
{
	exponent=y;
}

// setcoef function sets the coefficient of the term
void expcoef::setcoef(int y)
{
	coefficient=y;
}

// Polynom class
// This class is inherited from the List class. Remember that each polynom 
// will be stored as a link list. Therefore a polynom is a link list

template <class NODETYPE>
class Polynom : public List<NODETYPE>
{

	public:
		Polynom();
		void print();
		void init();
		void read();	
		Polynom<NODETYPE>  operator+(Polynom <NODETYPE> &);
                Polynom<NODETYPE>   operator-(Polynom <NODETYPE> &);
};

// Constructor. Calls the List class's constructor.
// ------------------------------------------------------------------------
template <class NODETYPE>
Polynom <NODETYPE> ::Polynom():List<NODETYPE>()
{}

// YOU WILL IMPLEMENT THE FOLLOWING FUNCTION
// Prints the terms of the polynom.
//-------------------------------------------------------------------------
template <class NODETYPE>
void Polynom<NODETYPE>::print ()
{
}
		
 
template <class NODETYPE>
void Polynom<NODETYPE>::init()
{
	firstPtr=0;
}

// YOU WILL IMPLEMENT THE FOLLOWING FUNCTION
// read function. This function reads the polynom from the user, Remember that
// each node of the list is one term of the polynom. Therefore each node is 
// an object of the expcoef class.
// All nodes are inserted at back of the list. (You can use the read function of expcoef class)
// -------------------------------------------------------------------------	
template <class NODETYPE>
void Polynom<NODETYPE>::read()
{
}

// YOU WILL IMPLEMENT THE FOLLOWING FUNCTION
// + operator adds the polynom given as a parameter to the object 
// itself and returns the result.
// --------------------------------------------------------------------------
template<class NODETYPE>
Polynom<NODETYPE>  Polynom<NODETYPE>::operator+(Polynom<NODETYPE> &p2)
 {
   Polynom<NODETYPE> polynom1;
   
  // Do something in here 
   
   return polynom1;
 }

// YOU WILL IMPLEMENT THE FOLLOWING FUNCTION
// - operator subtracts  the polynom given as a parameter from the object 
// itself and returns the result.
// --------------------------------------------------------------------------
template<class NODETYPE>
Polynom<NODETYPE>  Polynom<NODETYPE>::operator-(Polynom<NODETYPE> &p2)
{
	Polynom<NODETYPE> polynom1;
	
        // Do something in here 
	
	return polynom1;
}
#endif

