c Design your class using both the interface header file and

c++ Design your class using both the interface (header) file and the implementation (.cpp) file

capture the output given below. please give the same as the output. Thank you

1. MAIN OBJECTIVE
Develop the class Polynomial.

2. DESCRIPTION
The internal representation of a Polynomial is an array of terms. Each term contains a coefficient and an exponent, e.g., the term

2x4
has the coefficient 2 and the exponent 4.

Develop a complete class containing proper constructor and destructor functions as well as set, get, and print functions. The class should also provide the following overloaded operator capabilities:
a) Overload the addition operator (+) to add two Polynomials.

b) Overload the subtraction operator (-) to subtract two Polynomials.

c) Overload the assignment operator to assign one Polynomial to another.

d) Overload the multiplication operator (*) to multiply two Polynomials.

e) Overload the addition assignment operator (+=), subtraction assignment operator (-=), and multiplication assignment operator (*=).
Write an application that tests all the functionality provided by class Polynomial:
• create three Polynomials

• add two Polynomials, using + and += operators

• subtract two Polynomials, using – and -= operators

• assign one Polynomial to another Polynomial

• multiply two Polynomials, using * and *= operators.

For every operation performed, display the corresponding result using class Polynomial’s function print.

output:

Solution

This is the program designed according to the data you have given you please execute and let me know if any errors occurs

#include <iostream>

using namespace std;

class Polynomial

{

private:

int coef[100];

coef[n] = x^n ...

int deg; // degree of polynomial (0 for the zero polynomial)

public:

Polynomial::Polynomial()

{

for ( int i = 0; i < 100; i++ )

{

coef[i] = 0;

}

}

void set ( int a , int b ) //setter function

{

//coef = new Polynomial[b+1];

coef[b] = a;

deg = degree();

}

int degree()

{

int d = 0;

for ( int i = 0; i < 100; i++ )

if ( coef[i] != 0 ) d = i;

return d;

}

void print()

{

for ( int i = 99; i >= 0; i-- ) {

if ( coef[i] != 0 ) {

cout << coef[i] << \"x^\" << i << \" \";

}

}

}

int evaluate ( int x )

{

int p = 0;

for ( int i = deg; i >= 0; i-- )

p = coef[i] + ( x * p );

return p;

}

Polynomial differentiate()

{

if ( deg == 0 ) {

Polynomial t;

t.set ( 0, 0 );

return t;

}

Polynomial deriv;// = new Polynomial ( 0, deg - 1 );

deriv.deg = deg - 1;

for ( int i = 0; i < deg; i++ )

deriv.coef[i] = ( i + 1 ) * coef[i + 1];

return deriv;

}

Polynomial plus ( Polynomial b )

{

Polynomial a = *this; //a is the poly on the L.H.S

Polynomial c;

for ( int i = 0; i <= a.deg; i++ ) c.coef[i] += a.coef[i];

for ( int i = 0; i <= b.deg; i++ ) c.coef[i] += b.coef[i];

c.deg = c.degree();

# return c;

}

Polynomial minus ( Polynomial b )

{

Polynomial a = *this; //a is the poly on the L.H.S

Polynomial c;

for ( int i = 0; i <= a.deg; i++ ) c.coef[i] += a.coef[i];

for ( int i = 0; i <= b.deg; i++ ) c.coef[i] -= b.coef[i];

c.deg = c.degree();

return c;

}

Polynomial times ( Polynomial b )

{

Polynomial a = *this; //a is the poly on the L.H.S

Polynomial c;

for ( int i = 0; i <= a.deg; i++ )

for ( int j = 0; j <= b.deg; j++ )

c.coef[i+j] += ( a.coef[i] * b.coef[j] );

c.deg = c.degree();

return c;

}

};

int main()

{

Polynomial a, b, c, d;

a.set ( 7, 4 ); //7x^4

a.set ( 1, 2 ); //x^2

b.set ( 6, 3 ); //6x^3

b.set ( -3, 2 ); //-3x^2

c = a.minus ( b ); // (7x^4 + x^2) - (6x^3 - 3x^2)

c.print();

cout << \"\ \";

c = a.times ( b ); // (7x^4 + x^2) * (6x^3 - 3x^2)

c.print();

cout << \"\ \";

d = c.differentiate().differentiate();

d.print();

cout << \"\ \";

cout << c.evaluate ( 2 ); //substitue x with 2

cin.get();

}

c++ Design your class using both the interface (header) file and the implementation (.cpp) file capture the output given below. please give the same as the outp
c++ Design your class using both the interface (header) file and the implementation (.cpp) file capture the output given below. please give the same as the outp
c++ Design your class using both the interface (header) file and the implementation (.cpp) file capture the output given below. please give the same as the outp
c++ Design your class using both the interface (header) file and the implementation (.cpp) file capture the output given below. please give the same as the outp

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site