Help about the linklist read polynomial

How to modify the void addterm and add polynomial...


#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H

#include "linkedListType.h"


class term
{
friend ostream& operator<<(ostream& osObject, term& t);

private:
double coef;
int exp;

public:
term(){
coef = 0;
exp =0;}

term(double c, int e){
coef =c;
exp =e;}

~term(){}

void setCoef(double c){coef = c;}
void setExp(int e){exp = e;}
// double getCoef(){return coef;}
// int getExp(){return exp;}

term(const term& other){
coef =other.coef;
exp = other.exp;}

// precondition: exp == other.exp
// the operation for *this + other

term operator+ (const term& other){
term add;
add.coef = coef + other.coef;
add.exp = other.exp;
return add;
}

// precondition: exp == other.exp
// operation for *this - other

term operator- (const term& other){
term sub;
sub.coef = coef + other.coef;
sub.exp = other.exp;
return sub;
}

bool operator!= (const term& other){
if(exp != other.exp)
return true;
else
return false;
}

bool operator== (const term& other){
if (exp = other.exp)
return true;
else
return false;
}

//print a term
void print(){
cout<<coef<<" x^ "<<exp;
}


};

ostream& operator<<(ostream& osObject, term& t)
{
osObject << "(" << t.coef << ", " << t.exp << ") ";
return osObject;
}

//###########################################################


class polynomial
{
private:
linkedListType<term> *poly;

public:
polynomial(){ //default constructor
poly = NULL;
}

~polynomial(){}



polynomial(const polynomial &other){ //copy constructor
poly = other.poly;

}

const polynomial& operator= (const polynomial& other){
if(this != &other)
polynomial(other);
return *this;
}

//append a term to the polynomial

void addTerm(term item){




}

//print the polynomial
void print(){
cout<< endl;

cout<<" + ";
}

//return a new polynomial that is equal to *this + other
//the contents of this and other should not be modified
polynomial& add(polynomial& other){

return *this;

}

//return a new polynomial that is equal to *this - other
//the contents of this and other should not be modified
polynomial& sub(polynomial& other){

return *this;

}
};



#endif
Topic archived. No new replies allowed.