Question
This is C++ programming. Use separate compilation to implement a polynomial ADT that manipulates polynomials in a single variable x (e.g., p = 4 x^5
This is C++ programming.
Use separate compilation to implement a polynomial ADT that manipulates polynomials in a single variable x (e.g., p = 4 x^5 + 7 x^3 x^2 + 9 ). For this problem, consider only polynomials whose exponents are non-negative integers. You are required to identify a proper data representation schema to store such polynomials and hide such data from external users of this ADT. Additionally, your ADT will at least include the following member functions:
One default constructor, which creates a polynomial with no terms.
Ex: Polynomial p; // This should create a polynomial with no terms.
One method allowing one to get an entire polynomial by interacting with the user (by writing to cout and reading from cin) to obtain the degree and coefficient of each term in a polynomial. If the user enters nonsense, your program should not crash! It is up to you how to handle this case. The method can look something like this when called:
myPolynomial.readFromUser(); // prompts the user for the degree and // coefficients and stores the // results in myPolynomial
degree() // Returns the degree of a polynomial, which is the highest power of a term with a nonzero coefficient.
E.g: int deg = myPolynomial.degree();
coefficient(power) // Returns the coefficient of the x p o w e r term.
changeCoefficient(newCoefficient, power) // Replaces the coefficient of the x p o w e r term with newCoefficient. (Note: This method should handle the invalid case too. what happens if the power is out of range?? )
A method that multiplies a polynomial by an integer (make this a normal named method - do not overload the multiplication (*) operator).
A method that adds two polynomials ( overload the addition(+) operator as a standalone function).
Overload the division operator (/) as a member function to multiple divide a polynomial by a scalar variable.
A method that prints out a polynomial. Ex: cout<
Here you have to overload the "<<" put operator as a friend function. Because you cannot overload it as a member function)
Overload the subtraction operator(-) as a member function to subtract two polynomials.
Example: p1 = 3 x^3 - 2 x^2 - 3; p2 = 4 x^4 - x^2 + 3 x^1 - 5;
p3 = p1 - p2; // p3 should result in: - 4 x^4 + 3 x^3 - x^2 - 3 x + 2;
Overload the negation operator (-) as a member function to negate a polynomial. (NOTE: This is different from the subtraction operator! The subtraction operator takes an argument - the polynomial you are subtracting - whereas the negation operator takes no arguments.)
Example: p1 = 3 x^3 - 2 x^2 - 3; // -p1 should result in - 3 x^3 + 2 x^2 +3;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started