Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Task : Make a simple project file which includes main, specification and impleme

ID: 3871265 • Letter: T

Question

Task: Make a simple project file which includes main, specification and implementation files. Write the program in C++. Use linked lists to represent two polynomials. Each polynomial will be an object of the Polynomial class. Each node in the linked list will represent a term of the polynomial, so data members of the nodes will include coefficient and exponent.

Processing: The program should accept appropriate values (i.e., coefficient and exponent values) from the user to populate two polynomials. Simple data checking should verify that the integer exponents are non-negative and that coefficients are not zero. Polynomials may have varying numbers of terms. The terms should be stored in the linked list in decreasing order of their exponents.

For example, valid polynomials might be:

3 x to power 7 - 1.5 x to power 4 + 3 (stored as 3 nodes)

7.1 x to power 2 - 6x (stored as 2 nodes)

12 (stored as 1 node)

The program will perform three basic operations on the polynomials: add the two original polynomials together; output the sum subtract one of the original polynomials from the other one; output the difference perform monomial multiplication on one of the original polynomials (i.e., multiply each polynomial term by a given monomial term, not necessarily a scalar); output the monomial and the result

Note: Do not change the original two polynomials during the addition, subtraction or multiplication operations. Include appropriate functions in the class (constructors, etc.) to produce an effective object-oriented program.

Input: Be sure the program is flexible enough that polynomial terms may be supplied by the user out of proper order, but still be stored in proper order.

Output: Test program should allow the user to input the two polynomials and the monomial multiplier. Then output the following:

a) each of the two original polynomials

b) the sum of the polynomials

c) the difference (first polynomial minus the second)

d) another difference (second polynomial minus the first)

e) the result for each of the two polynomials being multiplied by a (different) monomial

Make sure your program in program is well documented both internally and externally.

Explanation / Answer

# include <iostream>

using namespace std;

class Lnode{

public:

                Lnode();

                Lnode(int, double);

                double coefficient;

                int exponent;

                Lnode *next;

};

Lnode::Lnode(){

                coefficient = 0.0;

                exponent = 0;

                next = NULL;

}

Lnode::Lnode(int exp, double coef){

                coefficient = coef;

                exponent = exp;

                next = NULL;

}

class poly{

public:

                poly();

                poly(int);

                void setCoef(int exp, double coef);

                void print();

private:

                int size;

                Lnode *head, *tail;

               

};

# include <iostream>

# include "Polynomials.h"

using namespace std;

poly::poly(){

                head = tail = NULL;

}

poly::poly(int n){

                int i;

                for(i=0; i<=n+1; i++)

                                Lnode *newnode = new Lnode;

}

void poly::setCoef(int exp, double coef){

                Lnode *newnode = new Lnode(exp, coef);

                newnode->next = head;

                head = newnode;

                if (tail==NULL)

                                tail = head;

                size++;

}

void poly::print(){

                Lnode *current;

                current = head;

                while(current != NULL){

                                cout<<current->coefficient<<"x^"<<current->exponent<<" ";

                                current = current->next;

                }

}

//Test File

# include <iostream>

# include "Polynomials.h"

# include "poly.cpp"

using namespace std;

void main() {

                poly p(3);

                a.setCoef(0,1.1);

                a.setCoef(1,2.1);

                a.print();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote