Hey all, I need a bit of help starting on a homework assignment. I'm not asking for you to do it for me, I just need a little help getting started on it.

Here is the site with information about the assignment: http://scidiv.bcc.ctc.edu/fl/cs210/Program4-S08.html

I really need just a little bit of help to get started on it.

// 
// Class Poly will manage and manipulate polynomials from x^0 to x^10.
// 
#include <iostream>
using namespace std; 

class Poly {

private: 

	bool state; // indicates if polynomial is valid


public:

	// constructors - set state=true
	Poly(void)
	{
		set Poly = 0
	}
	Poly(double c)
	{
		// set polynomial = c
	}

	Poly(double b, double a)
	{
		// set polynomial = bx+a
	}

	Poly(double c, double b, double a)
	{
		// set polynomial = cx^2+bx+a
	}

	Poly(double d, double c, double b, double a)
	{
		// set polynomial = dx^3+cx^2+bx+a
	}

	Poly(double e, double d, double c, double b, double a)
	{
		// set polynomial = ex^4+dx^3+cx^2+bx+a
	}

	Poly(double f, double e, double d, double c, double b, double a)
	{
		// set polynomial = fx^5+ex^4+dx^3+cx^2+bx+a
	}

	Poly(double g, double f, double e, double d, double c, double b, double a)
	{
		// set polynomial = gx^6+fx^5+ex^4+dx^3+cx^2+bx+a
	}

	Poly(double h, double g, double f, double e, double d, double c, double b, double a)
	{
		// set polynomial = hx^7+gx^6+fx^5+ex^4+dx^3+cx^2+bx+a
	}

	Poly(double i, double h, double g, double f, double e, double d, double c, double b, double a)
	{
		// set polynomial = ix^8+hx^7+gx^6+fx^5+ex^4+dx^3+cx^2+bx+a
	}

	Poly(double j, double i, double h, double g, double f, double e, double d, double c, double b, double a)
	{
		// set polynomial = jx^9+ix^8+hx^7+gx^6+fx^5+ex^4+dx^3+cx^2+bx+a
	}

	Poly(double k, double j, double i, double h, double g, double f, double e, double d, double c, double b, double a)
	{
		// set polynomial = kx^10+jx^9+ix^8+hx^7+gx^6+fx^5+ex^4+dx^3+cx^2+bx+a
	}

	// member functions
	bool setterm(int order, double coefficient)
	{
		// sets the coefficient for a specific term in the polynomial,
		// if there are problems make no change, return false
		// Example: setterm(3,5.4) assigns 5.4x^3
		//          setterm(0,-4) assigns -4
		//          setterm(11,1) returns false, x^10 is highest order
		//          setterm(-1,1) returns false, no decimal portion
	}

	void setpoly(double c[])
	{
		// sets the coefficient for the entire polynomial
		// c[i] is the coefficient for x^i
		// set state=true
	}

	double evaluate(double x)
	{
		// returns value of polynomial evaluated at x
		// returns 0 if state=false
	}
	
	void zero(void)
	{
		// sets all coefficients to 0
		// sets state=true
	}	

	Poly add(Poly a)
	{
		// adds this polynomial with a and returns result as a Poly	
	}

	Poly subract(Poly a)
	{
		// subtracts a from this polynomial and returns result as a Poly	
	}

	Poly multiply(Poly a)
	{
		// multiplies this polynomial with a and returns result as a Poly
		// if multiplication results in terms higher than x^10,
		// return Poly with state=false	
	}

	bool getstate(void)
	{
		// return state	
	}

	Poly polydivide(Poly a)
	{
		// divides this polynomial by a and returns only the polynomial result
		// Example: (x^3+2x^2-x+5)/(x-1) returns (x^2+3x+2)
		//          (2x^2-5x-12)/(2x+3) returns (x-4)	
	}

	Poly polymod(Poly a)
	{
		// divides this polynomial by a and returns only the remainder
		// Example: (3x^4-x^2+4x+2)/(x^2) returns (4x+2)
		//          (2x^2-5x-12)/(x-4) returns (0)	
	}

	string tostring(int i)
	{
		// returns string that expresses polynomial in following format
		// i (0<=i<=8) represents number of places after decimal to round to 
		// Example: (i=0) 5x^3-x^2-80x+5
		//          (i=2) -7.34x^4+8.02x
		// if state=false, return "Invalid Polynomial"
		// if i is outside of limits, return "Bad Decimal Setting"
	}

};

Recommended Answers

All 2 Replies

I'd add a private data member consisting of an array of 10 doubles to represent the possible coefficients of a polynomial. Then I'd get at least one constructor working and the tostring() method working so I could review/monitor results as I started to work on each of the other member functions. I'd do one member function (after the intial constructor and tostring() functions are done), at most, at a time, compiling and testing as I went.

This looks pretty straightforward...

Basically you're using a pattern.

Think of how you can use iteration (or recursion) to add the correct exponent and value to each section of the polynomial so you'll, only need a small block of code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.