Member Avatar

Hello Everyone , I have a Project at university to create term and polynomial class then calculate 2 derivatives I really need help for neccessery I have already started but I couldnt countinue , Hope to help !
Thanks ..

Note:The following attatchment contains project Details

Let's examine, step by step, what you have done so far:

  1. Posted your homework assignment.

I think I see your problem. You haven't actually tried to do it yourself. How about you show us what you have done.

Member Avatar

Reverend Jim
Sorry , I think that you have misunderstand me , I just Posted the Assignment to show Project Details So you can help me as required and I really tried hard but I couldnt complete on some points because I am Just a beginner in C++ I dont want Full code I just want a simple explain to a specific points (Derivative , set/get , to String) so I can complete work
Thank you for trying to help me ..

You will find my code in the Attatchment

Minimal code, in a format that we have to jump through hoops to look at and it is uncommented and right justified. When I load it up every line starts with a semi-colon. Please post the code properly using the code insert tool, </>.

Member Avatar

I cant understand how to deal with derivative and how to read the equation as a string
but the most confusing thing to me is data,, according to my information we define a pointer in the node class then use it in insert , delete and other functions as follow
pNew--> data = ..
but in the project we should identifiy coffiecnt and exponent How to deal with this?

    #include <iostream>
    using namespace std;

    template <typename E>

    class Polynomial {

    private: Term <E>* head;
           int count;

    public: Polynomial() {
        head = Null;
        count = 0;
    }

          void InsertOrder(int coffiecnt, int exponent) {
              Term <E>* pNew = new Term;
              pNew->data = coffiecnt;
              pNew->next = NULL;

              if (head == NULL) {
                  head = pNew;
                  count++;
                  return;
              }
              else {
                  pNew->next = head;
                  head = pNew;
                  count++;
              }

              bool  deletePoly(const T & coffiecnt , exponent) {
                  if (head == NULL) { cout << “ empty list “;   return false; }
                 Term<T>* prev = NULL;       Term <T>* cur = head;
                  while (cur && cur - > data !=coffiecnt) { prev = cur;    cur = cur->next; }
                  if (cur == NULL) { cout << “not fount to remove “;   return false; }
                  if (prev == NULL && cur != NULL) { removeFront();       return true; }
                  prev->next = cur->next;
                  delete cur;
                  count--;
                  return  true;

                  string toString() {

                  }

                  int Derivaite() {

                  }

    };

    template <typename E>
    class Term {
    private:
        E coffiecnt , exponent ;
        Term <E>* next; 
        template <typename E>

        friend class Polynomial;
    };

    int main() {

        Polynomial p; //4x^5+2x^8
        p.InsertOrder(4, 5);
        string S;
        cin >> S;
        cout << p.toString();
        Polynomial d = p.derivaite();
    };
commented: Fine example of uncommented code. +15

Fine example of uncommented code

I especially liked

if (head == NULL) { cout << “ empty list “;   return false; }
Term<T>* prev = NULL;       Term <T>* cur = head;
while (cur && cur - > data !=coffiecnt) { prev = cur;    cur = cur->next; }
if (cur == NULL) { cout << “not fount to remove “;   return false; }
if (prev == NULL && cur != NULL) { removeFront();       return true; }
prev->next = cur->next;
delete cur;
count--;
return  true;
Member Avatar

sorry sir , I couldnt understand !
I am just a beginner student not developer
this is what I understand from teacher and I am trying to find problems and solve it
because I really want to learn in the correct way not anything ...

I see Reverend Jim copy out a real doozie of a code passage which reminds me of an old saying:

When I wrote this only God and I understood this. Now, only God knows.

That code is a fine example where comments or more are mandatory since only the author may grasp what is going on.

Member Avatar

I think that I couldnt arrive my idea as required ,
anyway Thanks for all of you
I will find another way to solve it

No details here but two suggestions:

  1. Get yourself an editor with clang-format support, so that the people you discuss your code with can quickly understand what you did
  2. Separate the concerns of doing math stuff from the concern of keeping something in a list by creating a list class to store your information in and using that in your Polynomial class. That will make both parts of the project easier to test and implement

Good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.