debbie_lee104

08-09-2007, 12:21 AM

i'm trying to create this class and i'm having trouble getting it together.

1. How do i get the degree of a polynomial?

2. I'm trying to implement a friend function but I'm not sure how.

3. Not sure how to implement the non-member output function.

Please help!

#ifndef Poly.h

#define Poly.h

#include <iostream> // Provides ostream

class Polynomial

{

public:

// CONSTANT

static const unsigned int CAPACITY=5;

static const unsigned int MAX_DEGREE=10;

//CONSTRUCTOR

Polynomial(int degree)

{

}

//MODIFICATION MEMBER FUNCTIONS

void Polynomial::add_to_coeff(double amount, unsigned int exponent)

{

coeff[exponent] += amount;

}

void clear() //Reset the polynomial to zero

{

float result;

result=0;

}

void degree() //Get the Polynomial degree

{

}

//CONSTANT MEMBER FUNCTION

void poly_eval(const Polynomial& poly)

{

double x_value;

cout << "Enter the x value: ";

cin >> x_value;

cout << "For the poly: ";

view(poly);

cout << "The evaluation returned is " << poly(x_value) << endl;

}

// FRIEND FUNCTION

friend ostream& operator >> (ostream& out, const Polynomial&

poly);

private:

// NON-MEMBER BINARY OPERATORs

static const Polynomial operator +(const Polynomial& PX, const

Polynomial& QX);

static const Polynomial operator -(const Polynomial& PX, const

// NON-MEMBER OUTPUT FUNCTIONS

std::ostream& operator << (std::ostream& out, const Polynomial&

poly);

};

#endif

1. How do i get the degree of a polynomial?

2. I'm trying to implement a friend function but I'm not sure how.

3. Not sure how to implement the non-member output function.

Please help!

#ifndef Poly.h

#define Poly.h

#include <iostream> // Provides ostream

class Polynomial

{

public:

// CONSTANT

static const unsigned int CAPACITY=5;

static const unsigned int MAX_DEGREE=10;

//CONSTRUCTOR

Polynomial(int degree)

{

}

//MODIFICATION MEMBER FUNCTIONS

void Polynomial::add_to_coeff(double amount, unsigned int exponent)

{

coeff[exponent] += amount;

}

void clear() //Reset the polynomial to zero

{

float result;

result=0;

}

void degree() //Get the Polynomial degree

{

}

//CONSTANT MEMBER FUNCTION

void poly_eval(const Polynomial& poly)

{

double x_value;

cout << "Enter the x value: ";

cin >> x_value;

cout << "For the poly: ";

view(poly);

cout << "The evaluation returned is " << poly(x_value) << endl;

}

// FRIEND FUNCTION

friend ostream& operator >> (ostream& out, const Polynomial&

poly);

private:

// NON-MEMBER BINARY OPERATORs

static const Polynomial operator +(const Polynomial& PX, const

Polynomial& QX);

static const Polynomial operator -(const Polynomial& PX, const

// NON-MEMBER OUTPUT FUNCTIONS

std::ostream& operator << (std::ostream& out, const Polynomial&

poly);

};

#endif