Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 19 of 19

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

  1. #1
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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.


    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;
    }

    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;
     
    }

    #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

    #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

    #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()
    {
     
     
    }

    #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;
    }

    #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
    Attached Files Attached Files


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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

    Polynomial.o: Polynomial.cpp Polynomial.h DoublyLinkedList.h
    g++ -c Polynomial.cpp

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

    clean:
    rm Test *.o
    Last edited by javapenguin; October 6th, 2011 at 03:22 PM.

  3. #3
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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?

    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;
    }

    Should I add
     
    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.

  4. #4
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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:

    #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

  5. #5
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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?

    #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

  6. #6
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

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

    #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

    #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));
     
     
    }

    #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

     
    #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;
     
    }
    Last edited by javapenguin; October 7th, 2011 at 02:16 AM. Reason: Updating code

  7. #7
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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

     

    DoublyLinkedList.h: In instantiation of ‘DoublyLinkedList<Term ()(float, int)>’:
    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
    DoublyLinkedList.h: At global scope:
    DoublyLinkedList.h: In instantiation of ‘DoublyLinkedList<Term ()(float, int)>::Node’:
    DoublyLinkedList.h:132: instantiated from ‘DoublyLinkedList<T>::~DoublyLinkedList() [with T = Term ()(float, int)]’
    Polynomial.cpp:47: instantiated from here
    DoublyLinkedList.h:100: error: function returning a function
    DoublyLinkedList.h:21: error: field ‘DoublyLinkedList<Term ()(float, int)>::Node::data’ invalidly declared function type
    DoublyLinkedList.h: In member function ‘T* DoublyLinkedList<T>::Node::getDataPointer() [with T = Term ()(float, int)]’:
    DoublyLinkedList.h:132: instantiated from ‘DoublyLinkedList<T>::~DoublyLinkedList() [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



  8. #8
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  9. The Following User Says Thank You to KevinWorkman For This Useful Post:

    copeg (October 7th, 2011)

  10. #9
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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.)
    #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.
    Last edited by javapenguin; October 7th, 2011 at 03:08 PM.

  11. #10
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Exclamation 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

    #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

     

    DoublyLinkedList.h: In instantiation of ‘DoublyLinkedList<Term ()(float, int)>’:
    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)>*’
    DoublyLinkedList.h: At global scope:
    DoublyLinkedList.h: In instantiation of ‘DoublyLinkedList<Term ()(float, int)>::Node’:
    DoublyLinkedList.h:132: instantiated from ‘DoublyLinkedList<T>::~DoublyLinkedList() [with T = Term ()(float, int)]’
    Polynomial.cpp:47: instantiated from here
    DoublyLinkedList.h:100: error: function returning a function
    DoublyLinkedList.h:21: error: field ‘DoublyLinkedList<Term ()(float, int)>::Node::data’ invalidly declared function type
    DoublyLinkedList.h: In member function ‘T* DoublyLinkedList<T>::Node::getDataPointer() [with T = Term ()(float, int)]’:
    DoublyLinkedList.h:132: instantiated from ‘DoublyLinkedList<T>::~DoublyLinkedList() [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? ^:)^:((:((:((

    Please help. I had hoped to get further than this. I need this done in about 8 hours.

    I still need to work on the overloaded opeartors + and * still after I fix all of these impossible to figure out errors.
    Last edited by javapenguin; October 7th, 2011 at 03:29 PM.

  12. #11
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

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

    Please help. I've done what you wanted. And this is due soon.

    What is wrong with

    DoublyLinkedList<Term(float, int)> *list;

    ?
    Last edited by javapenguin; October 7th, 2011 at 04:06 PM.

  13. #12
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  14. #13
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default 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?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  15. #14
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

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

    I'm really baffled about this type of message.

    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:olynomial(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’

  16. #15
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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.

    DoublyLinkedList.h
    #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
    #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
    #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
    #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
    #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
    #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.

     

    DoublyLinkedList.h: In instantiation of ‘DoublyLinkedList<Term ()(float, int)>’:
    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
    DoublyLinkedList.h: At global scope:
    DoublyLinkedList.h: In instantiation of ‘DoublyLinkedList<Term ()(float, int)>::Node’:
    DoublyLinkedList.h:132: instantiated from ‘DoublyLinkedList<T>::~DoublyLinkedList() [with T = Term ()(float, int)]’
    Polynomial.cpp:53: instantiated from here
    DoublyLinkedList.h:100: error: function returning a function
    DoublyLinkedList.h:21: error: field ‘DoublyLinkedList<Term ()(float, int)>::Node::data’ invalidly declared function type
    DoublyLinkedList.h: In member function ‘T* DoublyLinkedList<T>::Node::getDataPointer() [with T = Term ()(float, int)]’:
    DoublyLinkedList.h:132: instantiated from ‘DoublyLinkedList<T>::~DoublyLinkedList() [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


    Last edited by javapenguin; October 7th, 2011 at 08:23 PM.

  17. #16
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default 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!
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  18. #17
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default 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.)

  19. #18
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

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

    Quote Originally Posted by KevinWorkman View Post
    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.
    Last edited by newbie; October 9th, 2011 at 12:32 PM.
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  20. #19
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default 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.

  21. The Following User Says Thank You to copeg For This Useful Post:

    KevinWorkman (October 10th, 2011)

Similar Threads

  1. [SOLVED] Linked Lists
    By lieles in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 6th, 2011, 08:39 AM
  2. Array Lists help!!
    By lilika in forum What's Wrong With My Code?
    Replies: 17
    Last Post: January 4th, 2011, 09:21 AM
  3. Operations with lists
    By datreta in forum Collections and Generics
    Replies: 8
    Last Post: October 29th, 2010, 08:54 AM
  4. Linked Lists
    By Jnoobs in forum Java Theory & Questions
    Replies: 1
    Last Post: October 23rd, 2010, 04:09 PM
  5. Lists of Sets and Sets of Lists
    By Newoor in forum Collections and Generics
    Replies: 2
    Last Post: December 8th, 2009, 08:13 PM