Link List help

So I've been trying to fix this program for the past month. Its a semester long program project. The basic requirements of this link list is that it must accept a polynomial from the user and be able to add, subtract, and multiply it with a second polynomial also taken from the user. I have the program down to one problem on bloodshed but its not making any sense to me as to what it wants me to do.



link list header file

#indef LINKLIST_H
#define LINKLIST_H
#include <iostream>
using namespace std;


template <class Polynomial>
class link_node
{
public:
Polynomial value;
link_node<Polynomial> *next;

link_node (Polynomial nodeValue)
{ value=nodeValue;
next=NULL;
};

template <class Polynomial>
class LinkedList
{
private:
list_node<Polynomial> *head;

public:
LinkedList()
{ head=NULL;}

~LinkedList();

void append_node(Polynomial);
void insert_node(Polynomial);
void delete_node(Polynomial);
void show_list() const;
};

template <class Polynomial>
void LinkedList<Polynomial>::append_node(Polynomial newValue)
{
link_node<Polynomial> *newNode;
link_node<Polynomial> *nodePtr;

newNode= new link_node<Polynomial>(newValue);

if(!head)
head=newNode;

else
{
nodePtr=head;

while (nodePtr->next)
nodePtr=nodePtr->next;
nodePtr->next=newNode;
}
}


template <class Polynomial>
void LinkedList<Polynomial>::show_list() const
{
link_node<Polynomial> *nodePtr;

nodePtr= head
while(nodePtr)
{
cout<<nodePtr->value<<endl;
nodePtr=nodePtr->next;
}
}

template <class Polynomial>
void LinkedList<Polynomial>::insert_node(Polynomail newValue)
{
ListNode<Polynomial> *newNode;
ListNode<Polynomial> *nodePtr;
ListNode<Polynomial> *previousNode=NULL;

newNode=new link_node<poly>(newValue);
if(!head)
{
head=newNode;
newNode->next=NULL;
}
else
{
nodePtr=head;
previousNode=NULL;

while (nodePtr != NULL && nodePtr->value <newValue)
{
previousNode=nodePtr;
nodePtr=nodePtr->next;
}

if (previousNode==NULL)
{
head=newNode;
newNode->next=nodePtr;
}
else
{
previousNode->next=newNode;
newNode->next=nodePtr;
}
}
}

template <class Polynomial>
void LinkedList<Polynomial>::delete_node(Polynomial searchValue)
{
link_node<Polynomial> *nodePtr;
link_node<Polynomial> *previousNode;

if (!head)
return;

if (head->value==searchValue)
{
nodePtr=head->next;
delete head;
head=nodePtr;
}
else
{
nodePtr=head;

while(nodePtr != NULL && nodePtr->value != searchValue)
{
previousNode=nodePtr;
nodePtr=nodePtr->next;
}

if (nodePtr)
{
previousNode->next=nodePtr->next;
delete nodePtr;
}
}
}

template <class Polynomial>
LinkedList<T>::~LinkedList()
{
link_node<Polynomial> *nodePtr;
link_node<Polynomial> *nextNode;

nodePtr=head;
while (nodePtr != NULL)
{
nextNode=nodePtr->next;
delete nodePtr;
nodePtr=nextNode;
}
}

#endif



Continued code


polynomial header file
#ifndef POLYNOMIAL_H
#define POLYNOMIAL_H
#include <iostream>
using namespace std;

class Polynomial {
public:

Polynomial();
Polynomial(int numer, int denom = 1);

void Insert(ostream &sout) const;
void Extract(istream &sin);
Polynomial Add(const Polynomial &Q) const;
Polynomial Multiply(const Polynomial &Q) const;
int Degree();
double Coefficient;
int I;
double Evaluate(double Value);
Polynomial Compose(const Polynomial &P);
private:


double coefficients[1000];
};

Polynomial operator+(const Polynomial &P,
const Polynomial &R);
Polynomial operator*(const Polynomial &P,
const Polynomial &R);
ostream& operator<<(ostream &sout, const Polynomial &Q);
istream& operator>>(istream &sin, Polynomial &P);

#endif
}

Polynomial::Polynomial() {

}

void Polynomial::Insert(ostream &sout) const {
cout << Coefficient (I) << "x^" << Degree();
return;
}

void Polynomial::Extract(istream &sin) {

}

Polynomial Polynomial::Add(const Polynomial &Q) const {

}

Polynomial Polynomial::Multiply(const Polynomial &Q) const {

}

int Polynomial::Degree(){


}

double Coefficient(int I)
{


}

double Evaluate(double Value){


}

Polynomial Compose(const Polynomial &P){


}



Polynomial operator+(const Polynomial &P,
const Polynomial &Q) {
return P.Add(Q);
}



Polynomial operator*(const Polynomial &P,
const Polynomial &Q) {
return P.Multiply(Q);


}


main function



#include <iostream>
#include "polynomial.h"
#include "linklist.h"

using namespace std;

int main()
{ int *degree,
s;
int numdeg;


cout << "Enter the highest degree of your polynomial: ";
cin >> numdeg;
degree= new int [numdeg];

Polynomial coefficients[numdeg];
for(int i = 0; i <= numdeg; i++){
cout << "Enter each coefficient individually, starting with the one with the highest degree(press enter after each)";
cin >> s;





system ("pause");
return 0;
}


First of all, when you paste code, please use the code tags. They show up in the Format box as "<>". They make it much easier to read your code.

I have the program down to one problem on bloodshed but its not making any sense to me as to what it wants me to do.

Second, what is the problem you are having? Nobody has time to look through hundreds of lines of code to find random problems. Give us a hint as to what the problem is. Your description request doesn't give us much to go on.
Sorry. I didn't know. The problem is in polynomial.h right after the #endif. It keeps saying expecting declaration.
In polynomial.h you have a #endif followed by a '}' The #endif is for the header guard , so I don't know what the '}' is for.

The definitions of the Polynomial constructor, and the functions Insert, Extract, etc. appear to be in the polynomial.h file after the #endif statement. If they are in the .h file they should be (1) before the #endif statement and (2) inline functions. If more than 1 .cpp file includes the definitions of the functions and they are not inline, you will get a multiply defined function. You might want to consider writing a polynomial.cpp file for these function definitions.

Topic archived. No new replies allowed.