Ok, I have an assignment that involves lists, it's in C+, and also polynomials

• October 6th, 2011, 02:11 PM
javapenguin
Ok, I have an assignment that involves lists, it's in C+, and also polynomials
It was working on bits and pieces of it and have the code in jumbles. I can fix it but I'm going to just add it as is to make it easier to add.

Code :

```Polynomial Polynomial::operator + (const Polynomial& poly, const Polynomial& poly2) const {   Polynomial poly3;   if (poly.list.get(0).getExponent() == poly2.list.get(0).getExponent()) poly3.list.addFirst(Term((poly.list.get(0).getCoefficient() + poly2.list.get(0).getCoefficient()), poly.list.get(0).getExponent()));     }   // the overloaded () method replaces all variables in polynomial with f and evaluates them and returns the answer   float Polynomial::operator () (float f) {     if (list.empty()) return 0;   float answer; for(int i = 0; i < list.Size(); i++) { answer = answer + (list.get(i).getCoefficient() * pow(f, list.get(i).getExponent()));   }   return answer; }```

Code :

```Term Term::derivative() { if (getExponent() == 0) return Term(0.0f, 1);   else return Term((getCoefficient() * getExponent()), (getExponent()-1));     }   Polynomial Polynomial::derivative() {   Polynomial poly;   for (int i = 0; i < Size(); i++) { poly.list.add(list.get(i).derivative(), i);   }   return poly;   }```

Code :

```#ifndef DOUBLY_LINKED_LIST_H #define DOUBLY_LINKED_LIST_H   template <class T>   class DoublyLinkedList {     class Node {   friend class DoublyLInkedList; private: T data; Node *next; Node *previous;   public: Node(const T& data, Node *next, Node *previous); T getData(); T* getDataPointer(); void setData(const T& data);   inline Node *getNext() { return next; }   inline Node *getPrevious() { return previous; }   Node<T> getPrevious() const; void setNext(Node<T> next); void setPrevious(Node<T> previous);           };   private:   unsigned int size; Node *head; Node *tail;   public:   DoublyLinkedList(); ~DoublyLinkedList();   void add(unsigned int index, const T data); void addFirst(const T& data); void addLast(const T& data); T get(unsigned int index) const; T getFirst() const; T getLast() const; void remove(unsigned int index); void removeFirst(); void removeLast(); unsigned int Size(); bool isEmpty(); string toString(); int find(const T& data);       };   #endif```

Code :

```#ifndef POLYNOMIAL_H #define POLYNOMIAL_H #include "DoublyLinkedList.h" #include "Term.h"   class Polynomial {   public: Polynomial(); Polynomial(float[] arr, int degree); Polynomial(const Polynomial& poly); ~Polynomial();   Polynomial operator +(const Polynomial& poly1, const Polynomial& poly2) const; Polynomial operator * (const Polynomial& poly1, const Polynomial& poly2) const; float operator () (float f); Polynomial operator = (const Polynomial& poly) const; Polynomial derivative() const; string toString();     private: DoublyLinkedList<Term(float, int)> list(); // is this legal? float *array;     };   #endif```

Code :

```#include <iostream> #include "Polynomial.h" #include "Term.h" #include "DoublyLinkedList.h"   using namespace std;   Polynomial::Polynomial() {     }   Polynomial::Polynomial(float *array, int degree) {       }   Polynomial::Polynomial(const Polynomial& poly) {   }   Polynomial::~Polynomial() { delete[] array;     }       Polynomial Polynomial::operator = (const Polynomial& poly) const {   }   Polynomial Polynomial::operator +(const Polynomial& poly, const Polynomial& poly2) const {   }   Polynomial Polynomial::operator *(const Polynomial& poly, const Polynomial& poly2) const {   }   float Polynomial:: operator () () {   }   Polynomial Polynomial::derivative() const {   }   Polynomial Polynomial::operator = (const Polynomial& poly) const {   }   string Polynomial::toString() {     }```

Code :

```#include "Term.h" #include<iostream> using namesspace std;   Term::Term(float coefficient, int power) { setCoefficient(coefficient); setPower(power);     }   void Term::setCoefficient(float coefficient) { this -> coefficent = coefficient; }   float Term::getCoefficient() const { return coefficient; }   void Term::setPower(int power) { this ->power = power; }   int Term::getPower() const { return power; }```

Code :

```#ifndef _TERM_H_ #define _TERM_H_   class Term {   public:   Term(float coefficient, int power); void setCoefficient(float coefficient); float getCoefficient() const; void setPower(int power); int getPower() const;     private: float coefficient; int power;   };   #endif```
• October 6th, 2011, 02:20 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
I know for the overloaded + operator, I'm supposed to basically do this:

1.) Compare exponents of the first Term in each of the Polynomial lists. If they are equal, then add and advance both (i.e. compare second Term with second Term.)
2.) If it is greater, then just include it and advance the first one to compare.
3.) If it is less than, include the second and advance the second one to compare.

So for (X^3 + 3X^2+3X + 1) + (2X^3 + 8X + 9)

1.) First two are same power, so add them and compare the "3X^2" and "8X"
2.) 3X^2 has greater power so add that one to polynomial list and then compare the next one (3X) with 8X.
3.) They are equal power so add them and compare 1 and 9.
4.) Those are equal power so add both and add to list.

Will make new Polynomial object returned

[Term(3.0, 3), Term(3.0, 2), Term(11.0, 1), Term(9.0, 0)]

The problem is, I'm not quite sure how to set that up.

Makefile:

Test: Test.o Polynomial.o Term.o
g++ -o Test Test.o Polynomial.o Term.o

Test.o: Test.cpp
g++ -c Test.cpp

g++ -c Polynomial.cpp

Term.o: Term.cpp Term.h
g++ -c Term.cpp

clean:
rm Test *.o
• October 6th, 2011, 05:05 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Will this code here deal with all of the pointers to previous?

Code :

```template <class T> DoublyLinkedList<T>::~DoublyLinkedList() { Node *curr, *curr2, *temp, *temp2;     curr = head; curr->getDataPointer(); while (curr!=NULL) { temp = curr; curr = curr->next; delete temp; } head = NULL; tail = NULL; }```

Code :

```  curr2 = tail; curr2-> getDatePointer(); while (curr!=NULL) { temp2 = curr; curr = curr->previous; delete temp2; }```

Or will that be deleting twice or cause an error, etc?

I must have lost some of my code that I thought I had saved for DoublyLinkedList so some things might need recoding.

:(

I'm working on that right now.
• October 6th, 2011, 06:03 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
As I'm worried about the stability of my hard drive, I will be posting code here quite frequently:

Code :

```#ifndef DOUBLY_LINKED_LIST_H #define DOUBLY_LINKED_LIST_H   template <class T>   class DoublyLinkedList {     class Node {   friend class DoublyLinkedList; private: T data; Node *next; Node *previous;   public: Node(const T& data, Node *next, Node *previous); T getData(); T* getDataPointer(); void setData(const T& data);   inline Node *getNext() { return next; }   inline Node *getPrevious() { return previous; }   Node<T> getPrevious() const; void setNext(Node<T> next); void setPrevious(Node<T> previous);           };   private:   unsigned int size; Node *head; Node *tail;   public:   DoublyLinkedList(); ~DoublyLinkedList();   void add(unsigned int index, const T& data); void addFirst(const T& data); void addLast(const T& data); T get(unsigned int index) const; T getFirst() const; T getLast() const; void remove(unsigned int index); void removeFirst(); void removeLast(); unsigned int Size(); bool empty(); string toString(); int find(const T& data);       };   template <class T> DoublyLinkedList<T>::~DoublyLinkedList() { Node *curr, *curr2, *temp;     curr = head; curr->getDataPointer(); while (curr!=NULL) { temp = curr; curr = curr->next; delete temp; } head = NULL; tail = NULL; }   template <class T> bool DoublyLinkedList<T>::empty() { return (Size() == 0);   }   template <class T> unsigned int DoublyLinkedList<T>::Size() { return size; }   template <class T> void DoublyLinkedList<T>::addFirst(const T& data) { Node *temp = new Node(data, head, null);   if (head == NULL) { tail = temp; }   if (head != NULL) head -> previous = temp;   head = temp;       size++;   }   template <class T>   void DoublyLinkedList<T>::addLast(const T& data) { if (tail == NULL) { addFirst(data); return; }   Node *temp = new Node(data, null, tail);   tail->next = temp; tail = temp; size++; }   template <class T> void DoublyLinkedList<T>::add(unsigned int index, const T&   data) {   } #endif```
• October 6th, 2011, 10:49 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
DoublyLinkedList.h is completed! How does it look? Do I need to clear up all the previous pointers in the DoublyLinkedList destructor or is that already taken care of?

Code :

```#ifndef DOUBLY_LINKED_LIST_H #define DOUBLY_LINKED_LIST_H   include <iostream>   using namespace std;   template <class T>   class DoublyLinkedList {     class Node {   friend class DoublyLinkedList; private: T data; Node *next; Node *previous;   public: Node(); Node(const T& data, Node *next, Node *previous); ~Node(); T getData(); T* getDataPointer(); void setData(const T& data);   inline Node *getNext() { return next; }   inline Node *getPrevious() { return previous; }   };   private:   unsigned int size; Node *head; Node *tail;   public:   DoublyLinkedList(); ~DoublyLinkedList();   void add(unsigned int index, const T& data); void addFirst(const T& data); void addLast(const T& data); T get(unsigned int index) const; T getFirst() const; T getLast() const; void remove(unsigned int index); void removeFirst(); void removeLast(); unsigned int Size(); bool empty(); string toString(); int find(const T& data); void removeRange(unsigned int from, unsigned int to); void removeAll();       };   template <class T>   DoublyLinkedList<T>::Node::Node() { next = NULL; previous = NULL; }   template <class T> DoublyLinkedList<T>::Node::Node(const T& data,Node *next, Node *previous) { this->data = data; this->next = next; this->previous = previous; }   template <class T> DoublyLinkedList<T>::Node::~Node() { this->next = NULL; this->previous = NULL; }   template <class T> T DoublyLinkedList<T>::Node::getData() { return data; }   template <class T> void DoublyLinkedList<T>::Node::setData(const T& data) { this->data = data; }   template<class T> T * DoublyLinkedList<T>::Node::getDataPointer() { return &data; }   template <class T> DoublyLinkedList<T>::DoublyLinkedList() { head = NULL; tail = NULL; size = 0; }   template <class T> DoublyLinkedList<T>::~DoublyLinkedList() { Node *curr, *curr2, *temp;     curr = head; curr->getDataPointer(); while (curr!=NULL) { temp = curr; curr = curr->next; delete temp; } head = NULL; tail = NULL; }   template <class T> bool DoublyLinkedList<T>::empty() { return (Size() == 0);   }   template <class T> unsigned int DoublyLinkedList<T>::Size() { return size; }   template <class T> void DoublyLinkedList<T>::addFirst(const T& data) { Node *temp = new Node(data, head, NULL);   if (head == NULL) { tail = temp; }   if (head != NULL) head -> previous = temp;   head = temp;       size++;   }   template <class T>   void DoublyLinkedList<T>::addLast(const T& data) { if (tail == NULL) { addFirst(data); return; }   Node *temp = new Node(data, NULL, tail);   tail->next = temp; tail = temp; size++; }   template <class T> void DoublyLinkedList<T>::add(unsigned int index, const T& data) { if (index < 0 || index >= Size()) { cout <<"You cannot do that. \n"; return; }   if (index ==0) { addFirst(data); return; }   else if (index == (Size() - 1)) { addLast(data); return; }   else { Node *current = new Node();   if (index < static_cast<int>(Size() /2)) {   for (int i =0; i < index -1; i++) { current = current->next; }   Node *newnode = new Node(data,current.getNext(), current.getPrevious());       current->next = newnode;       }   else { current = tail; for (int i = Size() -1; i > index -3 ; i--) { current = current->previous; } Node *newnode = new Node(data,current.getNext(), current.getPrevious());       current->next = newnode; }     } size++;     }   template<class T>   T DoublyLinkedList<T>::get(unsigned int index) {   if (index < 0 || index >=Size()) { return NULL; }   if (index ==0) return (head.getData());   if (index == (Size() -1)) return (tail.getData());   if (index < static_cast<int>(Size()/2)) { Node *specialNode = head;   for (int i =1; i < (index +1); i++) { specialNode = specialNode->next;   } return specialNode.getData(); }   else { Node *specialNode = tail;   for (int i = (Size() -2); i > (index -1); i--) { specialNode = specialNode->previous;   } return specialNode.getData();   }   }   template <class T>   string DoublyLinkedList<T>::toString() { string str = "[";   for (int i = 0; i < Size() -1; i++) { str = str + get(i).toString() + ",";   }   str = str + get(Size() -1) + "]";   return str;     }   template <class T>   int DoublyLinkedList<T>::find(const T& data) { int i; Node *curr;   i = 0; curr = head; while ((i<size) && (curr->getData()!=data)) { curr = curr->next; i++; }   if (i<size) return i; else return -1; }   template <class T> T DoublyLinkedList<T>::getFirst() const { if (empty()) return NULL; return head.getData(); }   template <class T>   T DoublyLinkedList<T>::getLast() const { if (empty()) return NULL;   return tail.getData(); }   template <class T>   void DoublyLinkedList<T>::remove(unsigned int index) {   if ((index<0) || (index>=Size())) { cout <<"You cannot do this."; return; }   Node *nodeToRemove = new Node(); Node *next2, *previous2;     nodeToRemove = head;   for (int v = 0; v < index; v++) { nodeToRemove = nodeToRemove->next; }   previous2 = nodeToRemove->previous; next2 = bodeToRemove->next;   if (previous2 == NULL) { if (next2 == NULL) { head = NULL; tail = NULL; }   else { head = next2; } }   else { previous2->next = next2; }   if (next2 == NULL) { if (previous2 == NULL) { head = NULL; tail = NULL; }   else { tail = previous2; } } else { next2->previous =previous2; }     size--;   }   template <class T> void DoublyLinkedList<T>::removeFirst() { remove(0);   }   template <class T>   void DoublyLinkedList<T>::removeLast() { remove(Size() -1);   }   template <class T>   void DoublyLinkedList<T>::removeRange(unsigned int from, unsigned int to) { if (from < 0 || from >= Size() || to < 0 || to >=Size()) { return; }   if (from >=to) { for (int j = from; j >= to; j--) { remove(j); } return; }   for (int i = from; i <=to; i++) { remove(i); }   }   template <class T>   void DoublyLinkedList<T>::removeAll() { removeRange(0, Size() -1);   }   #endif```
• October 6th, 2011, 11:25 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Code :

```#ifndef _TERM_H_ #define _TERM_H_   class Term {   public:   Term(float coefficient, int power); Term(const Term& term); Term derivative(); void setCoefficient(float coefficient); float getCoefficient() const; void setPower(int power); int getPower() const;       private: float coefficient; int power;   };   #endif```

Code :

```#include "Term.h" #include<iostream> using namesspace std;   Term::Term(float coefficient, int power) { setCoefficient(coefficient); setPower(power);     }   void Term::setCoefficient(float coefficient) { this -> coefficent = coefficient; }   float Term::getCoefficient() const { return coefficient; }   void Term::setPower(int power) { this ->power = power; }   int Term::getPower() const { return power; }   Term::Term(const Term& term) { setCoefficient(term.getCoefficient(); setPower(term.getPower());   }   Term Term::derivative() { if (getPower() == 0) return Term(0.0f, 1); if (getCoefficient() == 0) return Term(0.0f, 1);   else return Term((getCoefficient() * getPower()), (getPower()-1));     }```

Code :

```#ifndef POLYNOMIAL_H #define POLYNOMIAL_H #include "DoublyLinkedList.h" #include "Term.h"   class Polynomial {   public: Polynomial(); Polynomial(float[] arr, int degree); Polynomial(const Polynomial& poly); ~Polynomial();   Polynomial operator +(const Polynomial& poly1, const Polynomial& poly2) const; Polynomial operator * (const Polynomial& poly1, const Polynomial& poly2) const; float operator () (float f); Polynomial operator = (const Polynomial& poly) const; Polynomial derivative() const; string toString();     private: DoublyLinkedList<Term(float, int)> *list; // is this legal? float *array;     };   #endif```

Code :

```  #include <iostream> #include <cmath> #include "Polynomial.h" #include "Term.h" #include "DoublyLinkedList.h"   using namespace std;   Polynomial::Polynomial() { list = new DoublyLinkedList<Term(float, int)>();     }   Polynomial::Polynomial(float *array, int degree) {   list = new DoublyLinkedList<Term(float, int)>();   for (int i =0; i <= degree; i++) { if (array[i] != 0) list.addLast(Term(array[i], degree - i));   }     }   Polynomial::Polynomial(const Polynomial& poly) {   for (int i =0; i < poly.list.Size(); i++) { this->list.add(i, Term(poly.get(i).getCoefficient(), poly.get(i).getPower()));   }     }   Polynomial::~Polynomial() { delete[] array; delete list;     }       Polynomial Polynomial::operator = (const Polynomial& poly) const {   Polynomial poly3;   for (int i =0; i < poly.list.Size(); i++) { poly3.list.add(i, Node(poly.list.get(i).getCoefficient(), poly.list.get(i).getPower()));   }   return poly3;   }   Polynomial Polynomial::operator +(const Polynomial& poly, const Polynomial& poly2) const {   }   Polynomial Polynomial::operator *(const Polynomial& poly, const Polynomial& poly2) const {   }   float Polynomial:: operator () (float f) { if (list.empty()) return 0;   float answer; for(int i = 0; i < list.Size(); i++) { answer = answer + (list.get(i).getCoefficient() * pow(f, list.get(i).getExponent()));   }   return answer; }   Polynomial Polynomial::derivative() const { Polynomial poly;   for (int i = 0; i < Size(); i++) {   if (list.get(i).derivative().getCoefficient() != 0) poly.list.add(list.get(i).derivative(), i);   }       return poly;   }     string Polynomial::toString() {   string str = ""; if (list.Size() == 0) return "0"; if (list.Size() == 1) { if (list.getFirst().getCoefficient() < 0 ) { str = str + " + " + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); |   else { str = str + " - " + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } }     for (int i = 1; i < list.Size(); i++) {   if (list.get(i).getCoefficient() < 0 ) { str = str + " + " + list.get(i).getCoefficient(); if (list.get(i).getPower() < 1) str = str; else str = str + "X^" + list.get(i).getPower(); |   else { str = str + " - " + list.get(i).getCoefficient(); if (list.get(i).getPower() < 1) str = str; else str = str + "X^" + list.get(i).getPower(); }       } return str;   }```
• October 7th, 2011, 12:41 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
I fixed a ton of errors, but am still getting all of these

```
Polynomial.cpp:12:   instantiated from here
DoublyLinkedList.h:260: error: function returning a function
DoublyLinkedList.h:342: error: function returning a function
DoublyLinkedList.h:351: error: function returning a function
Polynomial.cpp: In constructor ‘Polynomial::Polynomial(float*, int)’:
Polynomial.cpp:25: error: request for member ‘addLast’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp: In copy constructor ‘Polynomial::Polynomial(const Polynomial&)’:
Polynomial.cpp:35: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:37: error: request for member ‘add’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:37: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:37: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘Polynomial Polynomial::operator=(const Polynomial&) const’:
Polynomial.cpp:59: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:61: error: request for member ‘add’ in ‘poly3.Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:61: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:61: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘float Polynomial::operator()(float)’:
Polynomial.cpp:81: error: request for member ‘empty’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:85: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:87: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:87: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp: In member function ‘Polynomial Polynomial::derivative() const’:
Polynomial.cpp:98: error: ‘Size’ was not declared in this scope
Polynomial.cpp:101: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:102: error: request for member ‘add’ in ‘poly.Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:102: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘std::string Polynomial::toString()’:
Polynomial.cpp:117: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:119: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:121: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:123: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:124: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:127: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:128: error: expected primary-expression before ‘|’ token
Polynomial.cpp:130: error: expected primary-expression before ‘else’
Polynomial.cpp:130: error: expected `;' before ‘else’
Polynomial.cpp:141: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:144: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:146: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:147: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:150: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:155: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:156: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:159: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:167: error: expected `}' at end of input
Polynomial.cpp:47:   instantiated from here
DoublyLinkedList.h:100: error: function returning a function
DoublyLinkedList.h: In member function ‘T* DoublyLinkedList<T>::Node::getDataPointer() [with T = Term ()(float, int)]’:
Polynomial.cpp:47:   instantiated from here
DoublyLinkedList.h:114: error: cannot convert ‘Term (**)(float, int)’ to ‘Term (*)(float, int)’ in return
```
• October 7th, 2011, 01:17 PM
KevinWorkman
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Remember all that stuff we told you about asking Java questions? You know, keeping the code to a minimum, asking a specific question, not just posting stuff as you think it.. well, that advice applies to other languages, too.
• October 7th, 2011, 02:17 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
What's causing all the

Polynomial.cpp:[insert line here]: error: request for member ‘(insert name here)’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’

?

Here are the two problem areas.

(I assume nothing is wrong with the Term class.)
Code :

```#ifndef DOUBLY_LINKED_LIST_H #define DOUBLY_LINKED_LIST_H   #include <iostream> #include <string>     using namespace std;   template <class T>   class DoublyLinkedList {     class Node {   friend class DoublyLinkedList; private: T data; Node *next; Node *previous;   public: Node(); Node(const T& data, Node *next, Node *previous); ~Node(); T getData(); T* getDataPointer(); void setData(const T& data);   inline Node *getNext() { return next; }   inline Node *getPrevious() { return previous; }   };   private:   unsigned int size; Node *head; Node *tail;   public:   DoublyLinkedList(); ~DoublyLinkedList();   void add(unsigned int index, const T& data); // not the problem void addFirst(const T& data); // not the problem void addLast(const T& data); // not the problem T get(unsigned int index); T getFirst() const; T getLast() const; void remove(unsigned int index); // not the problem void removeFirst(); // not the problem void removeLast(); // not the problem unsigned int Size(); // not the problem bool empty(); // not the problem string toString(); // not the problem int find(const T& data); // not the problem void removeRange(unsigned int from, unsigned int to); // not the problem void removeAll(); // not the problem       };   template <class T>   DoublyLinkedList<T>::Node::Node() { next = NULL; previous = NULL; }   template <class T> DoublyLinkedList<T>::Node::Node(const T& data,Node *next, Node *previous) { this->data = data; this->next = next; this->previous = previous; }   template <class T> DoublyLinkedList<T>::Node::~Node() { this->next = NULL; this->previous = NULL; }   template <class T> T DoublyLinkedList<T>::Node::getData() { return data; }   template <class T> void DoublyLinkedList<T>::Node::setData(const T& data) { this->data = data; }   template<class T> T * DoublyLinkedList<T>::Node::getDataPointer() { return &data; }   template <class T> DoublyLinkedList<T>::DoublyLinkedList() { head = NULL; tail = NULL; size = 0; }   template <class T> DoublyLinkedList<T>::~DoublyLinkedList() { Node *curr, *curr2, *temp;     curr = head; curr->getDataPointer(); while (curr!=NULL) { temp = curr; curr = curr->next; delete temp; } head = NULL; tail = NULL; }   template <class T> bool DoublyLinkedList<T>::empty() { return (Size() == 0);   }   template <class T> unsigned int DoublyLinkedList<T>::Size() { return size; }       template<class T>   // Claims that a function is returning a function. T DoublyLinkedList<T>::get(unsigned int index) {   if (index < 0 || index >=Size()) { return NULL; }   if (index ==0) return (head.getData());   if (index == (Size() -1)) return (tail.getData());   if (index < static_cast<int>(Size()/2)) { Node *specialNode = head;   for (int i =1; i < (index +1); i++) { specialNode = specialNode->next;   } return (specialNode.getData()); }   else { Node *specialNode = tail;   for (int i = (Size() -2); i > (index -1); i--) { specialNode = specialNode->previous;   } return (specialNode.getData());   }   }   template <class T> // claims a function is returning a function T DoublyLinkedList<T>::getFirst() const { if (empty() == true) return NULL; return (head.getData()); }   template <class T> // claims a function is returning a function T DoublyLinkedList<T>::getLast() const { if (empty() == true) return NULL;   return (tail.getData()); }   #endif```

Let's figure this one out.
• October 7th, 2011, 03:23 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Anybody there? ~X(~X(~X(:!!:!!:!

I've also get a bunch of errors in Polynomial.cpp

Code :

```#include <iostream> #include <cmath> #include <string> #include "Polynomial.h" #include "Term.h" #include "DoublyLinkedList.h"   using namespace std;   Polynomial::Polynomial() { list = new DoublyLinkedList<Term(float, int)>();     }   Polynomial::Polynomial(float *array, int degree) {   list = new DoublyLinkedList<Term(float, int)>();   for (int i =0; i <= degree; i++) { if (array[i] != 0) list.addLast(Term(array[i], degree - i));   }     }   Polynomial::Polynomial(const Polynomial& poly) {   for (int i =0; i < poly.list.Size(); i++) { this->list.add(i, Term(poly.list.get(i).getCoefficient(), poly.list.get(i).getPower()));   }     }   Polynomial::~Polynomial() { delete[] array; delete list;     }       Polynomial Polynomial::operator = (const Polynomial& poly) const {   Polynomial poly3;   for (int i =0; i < poly.list.Size(); i++) { poly3.list.add(i, Term(poly.list.get(i).getCoefficient(), poly.list.get(i).getPower()));   }   return poly3;   }   Polynomial Polynomial::operator +(const Polynomial& poly) const {   }   Polynomial Polynomial::operator *(const Polynomial& poly) const {   }   float Polynomial:: operator () (float f) { if (list.empty()) return 0;   float answer; for(int i = 0; i < list.Size(); i++) { answer = answer + (list.get(i).getCoefficient() * pow(f, list.get(i).getExponent()));   }   return answer; }   Polynomial Polynomial::derivative() const { Polynomial poly;   for (int i = 0; i < list.Size(); i++) {   if (list.get(i).derivative().getCoefficient() != 0) poly.list.add(list.get(i).derivative(), i);   }       return poly;   }     string Polynomial::toString() { // begin method   string str = ""; if (list.Size() == 0) return "0"; if (list.Size() == 1) { // begin if if (list.getFirst().getCoefficient() > 0 ) { // begin if str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end if   else { // begin else str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end else return str; } // end if   if (list.getFirst().getCoefficient() > 0 ) { // begin if str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end if   else { // begin else str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end else         for (int i = 1; i < list.Size(); i++) { // begin for   if (list.get(i).getCoefficient() < 0 ) { // begin if str = str + " + " + list.get(i).getCoefficient(); if (list.get(i).getPower() < 1) str = str; else str = str + "X^" + list.get(i).getPower(); } // end if   else { // begin else str = str + " - " + list.get(i).getCoefficient(); if (list.get(i).getPower() < 1) str = str; else str = str + "X^" + list.get(i).getPower(); } //end else       } // end for return str;   } // end method```

```
Polynomial.cpp:12:   instantiated from here
Polynomial.cpp: In constructor ‘Polynomial::Polynomial(float*, int)’:
Polynomial.cpp:25: error: request for member ‘addLast’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp: In copy constructor ‘Polynomial::Polynomial(const Polynomial&)’:
Polynomial.cpp:35: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:37: error: request for member ‘add’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:37: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:37: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘Polynomial Polynomial::operator=(const Polynomial&) const’:
Polynomial.cpp:59: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:61: error: request for member ‘add’ in ‘poly3.Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:61: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:61: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘float Polynomial::operator()(float)’:
Polynomial.cpp:81: error: request for member ‘empty’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:85: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:87: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:87: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp: In member function ‘Polynomial Polynomial::derivative() const’:
Polynomial.cpp:98: error: request for member ‘Size’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:101: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:102: error: request for member ‘add’ in ‘poly.Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:102: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘std::string Polynomial::toString()’:
Polynomial.cpp:117: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:119: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:121: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:123: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:124: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:127: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:132: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:133: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:136: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:141: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:143: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:144: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:147: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:152: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:153: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:156: error: request for member ‘getFirst’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:162: error: request for member ‘Size’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:165: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:167: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:168: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:171: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:176: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:177: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:180: error: request for member ‘get’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:47:   instantiated from here
DoublyLinkedList.h:100: error: function returning a function
DoublyLinkedList.h: In member function ‘T* DoublyLinkedList<T>::Node::getDataPointer() [with T = Term ()(float, int)]’:
Polynomial.cpp:47:   instantiated from here
DoublyLinkedList.h:114: error: cannot convert ‘Term (**)(float, int)’ to ‘Term (*)(float, int)’ in return
```

What's going on? ^:)^:((:((:((

I still need to work on the overloaded opeartors + and * still after I fix all of these impossible to figure out errors.
• October 7th, 2011, 04:04 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials

What is wrong with

?
• October 7th, 2011, 04:47 PM
KevinWorkman
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
You should know by now that bumping your thread, doing everything you've been told not to, and writing about your deadline in big bold letters is not going to get you help faster. It's Friday afternoon, so you might have to wait for some attention. Being obnoxious about it is only going to make you wait longer- think about it, how many people are going to want to wade through two pages of stream-of-consciousness posts? Should have kept it to one short one instead, like you've been asked to countless times in the past.

Not to mention the fact that this is a Java programming forum, so you're probably going to have to wait more than a couple minutes for an answer.
• October 7th, 2011, 04:50 PM
KevinWorkman
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Also, please do not multipost the same question. I've deleted your duplicate thread. If you keep this stuff up, I'm going to ban you. Is it really that hard to follow directions?
• October 7th, 2011, 04:56 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials

Code :

```Polynomial::Polynomial(float *array, int degree) {   list = new DoublyLinkedList<Term(float, int)>();     for (int i =0; i <= degree; i++) { if (array[i] != 0) list.addLast(Term(array[i], degree - i));   }     }```

Polynomial.cpp: In copy constructor ‘Polynomial::Polynomial(const Polynomial&)’:
Polynomial.cpp:36: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:38: error: request for member ‘add’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:38: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:38: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
• October 7th, 2011, 08:13 PM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Ok, now all the program is written(I mean coded, not correct, or even correctly coded probably for that matter). Now please help me figure out the errors.

Code :

```#ifndef DOUBLY_LINKED_LIST_H #define DOUBLY_LINKED_LIST_H   #include <iostream> #include <string>     using namespace std;   template <class T>   class DoublyLinkedList {     class Node {   friend class DoublyLinkedList; private: T data; Node *next; Node *previous;   public: Node(); Node(const T& data, Node *next, Node *previous); ~Node(); T getData(); T* getDataPointer(); void setData(const T& data);   inline Node *getNext() { return next; }   inline Node *getPrevious() { return previous; }   };   private:   unsigned int size; Node *head; Node *tail;   public:   DoublyLinkedList(); ~DoublyLinkedList();   void add(unsigned int index, const T& data); void addFirst(const T& data); void addLast(const T& data); T get(unsigned int index); T getFirst(); T getLast(); void remove(unsigned int index); void removeFirst(); void removeLast(); unsigned int Size(); bool empty(); string toString(); int find(const T& data); void removeRange(unsigned int from, unsigned int to); void removeAll();       };   template <class T>   DoublyLinkedList<T>::Node::Node() { next = NULL; previous = NULL; }   template <class T> DoublyLinkedList<T>::Node::Node(const T& data,Node *next, Node *previous) { this->data = data; this->next = next; this->previous = previous; }   template <class T> DoublyLinkedList<T>::Node::~Node() { this->next = NULL; this->previous = NULL; }   template <class T> T DoublyLinkedList<T>::Node::getData() { return data; }   template <class T> void DoublyLinkedList<T>::Node::setData(const T& data) { this->data = data; }   template<class T> T * DoublyLinkedList<T>::Node::getDataPointer() { return &data; }   template <class T> DoublyLinkedList<T>::DoublyLinkedList() { head = NULL; tail = NULL; size = 0; }   template <class T> DoublyLinkedList<T>::~DoublyLinkedList() { Node *curr, *curr2, *temp;     curr = head; curr->getDataPointer(); while (curr!=NULL) { temp = curr; curr = curr->next; delete temp; } head = NULL; tail = NULL; }   template <class T> bool DoublyLinkedList<T>::empty() { return (Size() == 0);   }   template <class T> unsigned int DoublyLinkedList<T>::Size() { return size; }   template <class T> void DoublyLinkedList<T>::addFirst(const T& data) { Node *temp = new Node(data, head, NULL);   if (head == NULL) { tail = temp; }   if (head != NULL) head -> previous = temp;   head = temp;       size++;   }   template <class T>   void DoublyLinkedList<T>::addLast(const T& data) { if (tail == NULL) { addFirst(data); return; }   Node *temp = new Node(data, NULL, tail);   tail->next = temp; tail = temp; size++; }   template <class T> void DoublyLinkedList<T>::add(unsigned int index, const T& data) { if (index < 0 || index >= Size()) { cout <<"You cannot do that. \n"; return; }   if (index ==0) { addFirst(data); return; }   else if (index == (Size() - 1)) { addLast(data); return; }   else { Node *current = new Node();   if (index < static_cast<int>(Size() /2)) {   for (int i =0; i < index -1; i++) { current = current->next; }   Node *newnode = new Node(data,current.getNext(), current.getPrevious());       current->next = newnode;       }   else { current = tail; for (int i = Size() -1; i > index -3 ; i--) { current = current->previous; } Node *newnode = new Node(data,current.getNext(), current.getPrevious());       current->next = newnode; }     } size++;     }   template<class T>   T DoublyLinkedList<T>::get(unsigned int index) {   if (index < 0 || index >=Size()) { return NULL; }   if (index ==0) return (head.getData());   if (index == (Size() -1)) return (tail.getData());   if (index < static_cast<int>(Size()/2)) { Node *specialNode = head;   for (int i =1; i < (index +1); i++) { specialNode = specialNode->next;   } return (specialNode.getData()); }   else { Node *specialNode = tail;   for (int i = (Size() -2); i > (index -1); i--) { specialNode = specialNode->previous;   } return (specialNode.getData());   }   }   template <class T>   string DoublyLinkedList<T>::toString() { string str = "[";   for (int i = 0; i < Size() -1; i++) { str = str + get(i).toString() + ",";   }   str = str + get(Size() -1) + "]";   return str;     }   template <class T>   int DoublyLinkedList<T>::find(const T& data) { int i; Node *curr;   i = 0; curr = head; while ((i<size) && (curr->getData()!=data)) { curr = curr->next; i++; }   if (i<size) return i; else return -1; }   template <class T> T DoublyLinkedList<T>::getFirst() { if (empty() == true) return NULL; return (head.getData()); }   template <class T>   T DoublyLinkedList<T>::getLast() { if (empty() == true) return NULL;   return (tail.getData()); }   template <class T>   void DoublyLinkedList<T>::remove(unsigned int index) {   if ((index<0) || (index>=Size())) { cout <<"You cannot do this."; return; }   Node *nodeToRemove = new Node(); Node *next2, *previous2;     nodeToRemove = head;   for (int v = 0; v < index; v++) { nodeToRemove = nodeToRemove->next; }   previous2 = nodeToRemove->previous; next2 = nodeToRemove->next;   if (previous2 == NULL) { if (next2 == NULL) { head = NULL; tail = NULL; }   else { head = next2; } }   else { previous2->next = next2; }   if (next2 == NULL) { if (previous2 == NULL) { head = NULL; tail = NULL; }   else { tail = previous2; } } else { next2->previous =previous2; }     size--;   }   template <class T> void DoublyLinkedList<T>::removeFirst() { remove(0);   }   template <class T>   void DoublyLinkedList<T>::removeLast() { remove(Size() -1);   }   template <class T>   void DoublyLinkedList<T>::removeRange(unsigned int from, unsigned int to) { if (from < 0 || from >= Size() || to < 0 || to >=Size()) { return; }   if (from >=to) { for (int j = from; j >= to; j--) { remove(j); } return; }   for (int i = from; i <=to; i++) { remove(i); }   }   template <class T>   void DoublyLinkedList<T>::removeAll() { removeRange(0, Size() -1);   }   #endif```

Term.h
Code :

```#ifndef _TERM_H_ #define _TERM_H_   class Term {   public:   Term(float coefficient, int power); void setCoefficient(float coefficient); float getCoefficient() const; void setPower(int power); int getPower() const; Term(const Term& term); Term derivative();   private: float coefficient; int power;   };   #endif```

Term.cpp
Code :

```#include "Term.h" #include<iostream> using namesspace std;   Term::Term(float coefficient, int power) { setCoefficient(coefficient); setPower(power);     }   void Term::setCoefficient(float coefficient) { this -> coefficent = coefficient; }   float Term::getCoefficient() const { return coefficient; }   void Term::setPower(int power) { this ->power = power; }   int Term::getPower() const { return power; }   Term::Term(const Term& term) { setCoefficient(term.getCoefficient(); setPower(term.getPower());   }   Term Term::derivative() { if (getPower() == 0) return Term(0.0f, 1); if (getCoefficient() == 0) return Term(0.0f, 1);   else return Term((getCoefficient() * getPower()), (getPower()-1));     }```

Polynomial.h
Code :

```#ifndef POLYNOMIAL_H #define POLYNOMIAL_H #include "DoublyLinkedList.h" #include "Term.h" #include <string>   using namespace std; class Polynomial {   public: Polynomial(); Polynomial(float *arr, int degree); Polynomial(const Polynomial& poly); ~Polynomial();   Polynomial operator +(const Polynomial& poly) const; Polynomial operator * (const Polynomial& poly) const; float operator () (float f); Polynomial operator = (const Polynomial& poly) const; Polynomial derivative() const; string toString(); DoublyLinkedList<Term(float, int)> getList();       private: DoublyLinkedList<Term(float,int)> *list; // is this legal? float *array;     };   #endif```

Polynomial.cpp
Code :

```#include <iostream> #include <cmath> #include <string> #include "Polynomial.h" #include "Term.h" #include "DoublyLinkedList.h"   using namespace std;   Polynomial::Polynomial() { list = new DoublyLinkedList<Term(float,int)>();     }   Polynomial::Polynomial(float *array, int degree) {   list = new DoublyLinkedList<Term(float, int)>();     for (int i =0; i <= degree; i++) { if (array[i] != 0) { Term t(array[i], degree - i); list.addLast(t);   }   }     }   Polynomial::Polynomial(const Polynomial& poly) {   for (int i =0; i < poly.list.Size(); i++) { Term t(poly.list.get(i).getCoefficient(), poly.list.get(i).getPower()); list.add(i, t);   }     }   Polynomial::~Polynomial() { delete[] array; delete list;     }       Polynomial Polynomial::operator = (const Polynomial& poly) const {   Polynomial poly3;   for (int i =0; i < poly.list.Size(); i++) { poly3.list.add(i, Term(poly.list.get(i).getCoefficient(), poly.list.get(i).getPower()));   }   return poly3;   }   Polynomial Polynomial::operator +(const Polynomial& poly) const { Polynomial poly3; Term *temp, *temp2;   temp = list.get(0); temp2 = poly.list.get(0);   int i =0; int j = 0; while ((temp !=NULL) && (temp2 !=NULL)) {   if (temp.getPower() == temp2.getPower()) { poly3.addLast(Term((temp.getCoefficient() + temp2.getCoefficient()), temp.getPower());   i++; j++; }   else if (temp.getPower() > temp2.getPower()) { poly3.addLast(Term((temp.getCoefficient(), temp.getPower()); i++; }   else { poly3.addLast(Term((temp2.getCoefficient(), temp2.getPower())); j++;   } temp = list.get(i); temp2 = poly.list.get(j); }   if ((temp == NULL) && (temp2 != NULL)) { while (temp2 != NULL) { poly3.addLast(Term(temp2.getCoefficient(), temp2.getPower())); j++; temp2 = list.get(j);   }   }   else if ((temp != NULL) && (temp2 == NULL)) { while (temp != NULL) { poly3.addLast(Term(temp.getCoefficient(), temp.getPower())); i++; temp = list.get(i);   }   }   else {   }   return poly3;   }   Polynomial Polynomial::operator *(const Polynomial& poly) const { Polynomial poly3; Polynomial pArray[poly.list.Size()];   for (int i = 0; i < list.Size(); i++) {   for (int j = 0; j < poly.list.Size(); j++) { pArray[i].list.addLast(Term((list.get(i).getCoefficient() * poly.list.get(j).getCoefficient()), (list.get(i).getPower() + poly.list.get(j).getPower())));   |   }   for (int v = 0; v < poly.list.Size(); v++) { poly3 = poly3 + pArray[v];   }   return poly3;   }   float Polynomial:: operator () (float f) { if (list.empty()) return 0;   float answer; for(int i = 0; i < list.Size(); i++) { answer = answer + (list.get(i).getCoefficient() * pow(f, list.get(i).getExponent()));   }   return answer; }   Polynomial Polynomial::derivative() const { Polynomial poly;   for (int i = 0; i < list.Size(); i++) {   if (list.get(i).derivative().getCoefficient() != 0) poly.list.add(list.get(i).derivative(), i);   }       return poly;   }     string Polynomial::toString() { // begin method   string str = ""; if (list.Size() == 0) return "0"; if (list.Size() == 1) { // begin if if (list.getFirst().getCoefficient() > 0 ) { // begin if str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end if   else { // begin else str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end else return str; } // end if   if (list.getFirst().getCoefficient() > 0 ) { // begin if str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end if   else { // begin else str = str + list.getFirst().getCoefficient(); if (list.getFirst().getPower() < 1) str = str; else str = str + "X^" + list.getFirst().getPower(); } // end else         for (int i = 1; i < list.Size(); i++) { // begin for   if (list.get(i).getCoefficient() < 0 ) { // begin if str = str + " + " + list.get(i).getCoefficient(); if (list.get(i).getPower() < 1) str = str; else str = str + "X^" + list.get(i).getPower(); } // end if   else { // begin else str = str + " - " + list.get(i).getCoefficient(); if (list.get(i).getPower() < 1) str = str; else str = str + "X^" + list.get(i).getPower(); } //end else       } // end for return str;   } // end method   DoublyLinkedList<Term(float,int)> Polynomial::getList() { return list;   }```

Test.cpp
Code :

```#include "DoublyLinkedList.h" #include "Term.h" #include "Polynomial.h" #include<iostream>   using namespace std;   int main() {     float *array; array = new float[5]; array[0] = 2.0; array[1] = -1.8; array[2] = 0; array[3] = 9.3; array[4] = -10.0;       //Polynomial poly(array, 4); Polynomial poly;   cout << poly.toString();   delete array;     return 0; }```

Now here's all of my errors, most of them of three of the same kind of mistake. What I'd like to know is how to fix that mistake so I can correct all of them. The three errors are that it complains that something is of a non-class type, it complains a method is returning a method, and I can't recall the third.

```
Polynomial.cpp:12:   instantiated from here
DoublyLinkedList.h:260: error: function returning a function
DoublyLinkedList.h:342: error: function returning a function
DoublyLinkedList.h:351: error: function returning a function
Polynomial.cpp: In constructor ‘Polynomial::Polynomial(float*, int)’:
Polynomial.cpp:28: error: request for member ‘addLast’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp: In copy constructor ‘Polynomial::Polynomial(const Polynomial&)’:
Polynomial.cpp:40: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:42: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:42: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:43: error: request for member ‘add’ in ‘((Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp: In member function ‘Polynomial Polynomial::operator=(const Polynomial&) const’:
Polynomial.cpp:65: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:67: error: request for member ‘add’ in ‘poly3.Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>*’
Polynomial.cpp:67: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:67: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘Polynomial Polynomial::operator+(const Polynomial&) const’:
Polynomial.cpp:80: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:81: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:88: error: request for member ‘getPower’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:88: error: request for member ‘getPower’ in ‘temp2’, which is of non-class type ‘Term*’
Polynomial.cpp:90: error: ‘class Polynomial’ has no member named ‘addLast’
Polynomial.cpp:90: error: request for member ‘getCoefficient’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:90: error: request for member ‘getCoefficient’ in ‘temp2’, which is of non-class type ‘Term*’
Polynomial.cpp:90: error: request for member ‘getPower’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:96: error: request for member ‘getPower’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:96: error: request for member ‘getPower’ in ‘temp2’, which is of non-class type ‘Term*’
Polynomial.cpp:98: error: ‘class Polynomial’ has no member named ‘addLast’
Polynomial.cpp:98: error: request for member ‘getCoefficient’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:98: error: request for member ‘getPower’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:104: error: ‘class Polynomial’ has no member named ‘addLast’
Polynomial.cpp:104: error: request for member ‘getCoefficient’ in ‘temp2’, which is of non-class type ‘Term*’
Polynomial.cpp:104: error: request for member ‘getPower’ in ‘temp2’, which is of non-class type ‘Term*’
Polynomial.cpp:108: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:109: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:116: error: ‘class Polynomial’ has no member named ‘addLast’
Polynomial.cpp:116: error: request for member ‘getCoefficient’ in ‘temp2’, which is of non-class type ‘Term*’
Polynomial.cpp:116: error: request for member ‘getPower’ in ‘temp2’, which is of non-class type ‘Term*’
Polynomial.cpp:118: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:128: error: ‘class Polynomial’ has no member named ‘addLast’
Polynomial.cpp:128: error: request for member ‘getCoefficient’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:128: error: request for member ‘getPower’ in ‘temp’, which is of non-class type ‘Term*’
Polynomial.cpp:130: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp: In member function ‘Polynomial Polynomial::operator*(const Polynomial&) const’:
Polynomial.cpp:148: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:150: error: request for member ‘Size’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:153: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:155: error: ‘pArray’ was not declared in this scope
Polynomial.cpp:155: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:155: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:155: error: request for member ‘get’ in ‘((const Polynomial*)this)->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:155: error: request for member ‘get’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:157: error: expected primary-expression before ‘|’ token
Polynomial.cpp:159: error: expected primary-expression before ‘}’ token
Polynomial.cpp:159: error: expected `;' before ‘}’ token
Polynomial.cpp:161: error: request for member ‘Size’ in ‘poly->Polynomial::list’, which is of non-class type ‘DoublyLinkedList<Term ()(float, int)>* const’
Polynomial.cpp:163: error: ‘pArray’ was not declared in this scope
Polynomial.cpp:172: error: a function-definition is not allowed here before ‘{’ token
Polynomial.cpp:286: error: expected `}' at end of input
Polynomial.cpp:53:   instantiated from here
DoublyLinkedList.h:100: error: function returning a function
DoublyLinkedList.h: In member function ‘T* DoublyLinkedList<T>::Node::getDataPointer() [with T = Term ()(float, int)]’:
Polynomial.cpp:53:   instantiated from here
DoublyLinkedList.h:114: error: cannot convert ‘Term (**)(float, int)’ to ‘Term (*)(float, int)’ in return
make: *** [Polynomial.o] Error 1
```
• October 8th, 2011, 04:44 PM
newbie
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Lol! Someone is really pushing their luck.

ban-HAMMER TIME!
• October 9th, 2011, 12:37 AM
javapenguin
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
How am I pushing my luck? I posted all the code that was needed. I've already had to submit it but can't find the button to mark the thread solved.

If you mean earlier, I'm done trying to be obnoxious. (One, I found it doesn't help me any. And two, it gets the mods mad, which I don't want.)
• October 9th, 2011, 06:49 AM
newbie
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Quote:

Originally Posted by KevinWorkman
Remember all that stuff we told you about asking Java questions? You know, keeping the code to a minimum, asking a specific question, not just posting stuff as you think it.. well, that advice applies to other languages, too.

In my reality, posting 3 header files and 3 cpp files is not keeping the code to a minimum.
What I'm sure people would have appreciated is if you had tried figure to out approximately where 1 of the three errors were occurring,
then posted a snippet of of that code along with the relating error.

That way, it would have be much easier to work your way through your problems.
• October 9th, 2011, 11:40 AM
copeg
Re: Ok, I have an assignment that involves lists, it's in C+, and also polynomials
Quote:

Originally Posted by javapenguin
If you mean earlier, I'm done trying to be obnoxious.

I've heard that before. You've been told countless times in the past, you have been warned countless times and banned at least once, but have yet to rectify your behavior. Sending multiple private messages, posting large fonts as you did above, not following the advice that is found (ironically) in a link in your signature - this by definition is obnoxious, and what I would call trolling - all the more reason for me to agree with Newbie's 'hammer-time' advice above.