Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a class called polynomial for performing arithmetic with polynomials. The class can be used to add, subtract, multiply, divide, finds the remainder of two

Create a class called polynomial for performing arithmetic with polynomials. The class can be used to add, subtract, multiply, divide, finds the remainder of two polynomials.

code:

#include

#include

using namespace std;

class polynomial

{

friend ostream& operator

friend istream& operator>>(istream& isObject, polynomial& cObject);

public:

void set(int, double*);

int getDegree() const;

double* getPointer() const;

polynomial operator+(const polynomial&) const;

polynomial operator-(const polynomial&) const;

polynomial operator*(const polynomial&) const;

polynomial operator/(const polynomial&) const;

polynomial operator%(const polynomial&) const;

polynomial& operator=(const polynomial&);

polynomial(const polynomial &otherObject);

polynomial(int, double*);

polynomial();

~polynomial();

private:

int degree;

double *p;

};

void printMenu();

int main()

{

polynomial poly1, poly2;

polynomial polyAdd, polySub, polyMult, polyDiv, polyRemainder;

int selection = 0;

cin >> poly1;

cin >> poly2;

while (true)

{

system("cls");

cout

switch (selection)

{

case 0:

printMenu();

break;

case 1:

cout

cout

cout

cout

printMenu();

break;

case 2:

polyAdd = poly1 + poly2;

cout

cout

printMenu();

break;

case 3:

polySub = poly1 - poly2;

cout

cout

printMenu();

break;

case 4:

polyMult = poly1 * poly2;

cout

cout

printMenu();

break;

case 5:

polyDiv = poly1 / poly2;

cout

cout

printMenu();

break;

case 6:

polyRemainder = poly1 % poly2;

cout

cout

printMenu();

break;

case 9:

cout

return 0;

default:

cout

printMenu();

}

cin >> selection;

}

}

void printMenu()

{

cout

cout

cout

cout

cout

cout

cout

cout

cout

cout

}

void polynomial::set(int nDegree, double *q)

{

degree = nDegree;

p = new double[degree+1];

assert(p != NULL);

for(int i=0; i

p[i] = q[i];

}

int polynomial::getDegree() const

{

return degree;

}

double* polynomial::getPointer() const

{

return p;

}

polynomial& polynomial::operator=(const polynomial &pObject)

{

}

polynomial polynomial::operator+(const polynomial &pObject) const

{

}

polynomial polynomial::operator-(const polynomial &pObject) const

{

}

polynomial polynomial::operator*(const polynomial &pObject) const

{

}

polynomial polynomial::operator/(const polynomial &pObject) const

{

}

polynomial polynomial::operator%(const polynomial &pObject) const

{

}

polynomial::polynomial(int nDegree, double *q)

{

set(nDegree, q);

}

polynomial::polynomial(const polynomial &pObject )

{

}

polynomial::polynomial()

{

degree = 0;

p = new double[degree+1];

assert(p != NULL);

p[0] = 0;

}

polynomial::~polynomial()

{

delete [] p;

p = NULL;

}

ostream& operator

{

}

istream& operator>>(istream& isObject, polynomial& cObject)

{

}

image text in transcribed

Sample input / output: nter the degree of the polynomial: nter the coefficients of x 0: 3 nter the coefficients of x^1: -2 nter the coefficients of x 2: 5 nter the coefficients of x 3 4 nter the coefficients of x4: 1 nter the coefficients of x 5: 9 he first polynomial is: he second polynomial is: nter the degree ofthe polynomial: 2 nter the coefficients of x0: 4 nter the coefficients of x1 3 nter the coefficients of x2: -1 The menu d. Print this menu again 1. Print the two polynomials 2. Add the two polynomials 3. Subtract the two polynomials 4. Multiply the two polynomials 5. Divide the two polynomials 6. Remainder of dividing the two polynomials 9. Quit program Enter selection now 2 he sum of the two polynomials is: +1^1 +4^2 + 4x^3 + 1 x^4 + 9 x*S The menu 0. Print this nenu again 1. Print the to polynomials 2. Add the two polynomials 3. Subtract the two polynomials 4. Multiply the two polynomials 5. Divide the two polynomials 6. Remainder of dividing the two polynonials. 9. Quit progran The menu 0. Print this menu again 1. Print the two polynomials 2. Add the two polynomials 3. Subtract the two polynonials 4. Multiply the two polynonials 5. Divide the two polynonials 6. Remainder of dividing the two polynomials. 9. Quit program Enter selection now: 1 Enter selection now

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Hands-On Database

Authors: Steve Conger

2nd Edition

0133024415, 978-0133024418

More Books

Students also viewed these Databases questions

Question

List some key areas relating to investment objectives.

Answered: 1 week ago