3 Attachment(s)
Help with a Polynomial Program
College student here - I'm in Comp Sci II. Just switched professors and feel like I missed out on a lot!! I feel like I missed a big chunk by switching professors and now am very lost.
I'm only just learning about classes and objects, so sorry if some of my questions and mistakes are amateur.
I've put a couple hours into trying to figure out how all of this works for my assignment and attached is what I have so far, which I know is basically a skeleton of what I need. It has all the member functions that I'm suppose to implement and some of them have coding in them.
But man, pass that I'm just clueless!!
Any help will be majorly appreciated, since as I said, I feel extremely out of the loop right now.
Basically with what I have right now, I'm suppose to
~~~~
1)
Write a client program that tests my class Polynomial by allowing the user to input two polynomials P(x) and Q(x) and compute and display their sum, difference, product, and composition as well as evaluate the input polynomial P(x) at a value given by the user.
2)
Write a function that computes the derivative of a polynomial P(x):
Polynomial Derivative(const Polynomial &P)
3)
Write a member function that returns the remainder when the polynomial is divided by a polynomial Q:
Polynomial Modulo(const Polynomial &Q)
Also, include an auxiliary operator overload function for modulo, i.e., that overloads %.
~~~~~~
I'm fairly confident in my header and implementation file, but my main file is most likely wrong with what little is there.
I just need guidance on where to go from here :-\ I really want to understand what's going on here, as I know these are important components.
Thanks everyone!
Re: Help with a Polynomial Program
Sorry, but your header and implementation files are not correct. On a sidenote, don't be afraid of errors, we all get them.
Re: Help with a Polynomial Program
Yeah, I still need to figure out how to go about with the coding inside a lot of the member functions in my implementation.
Gah, lots of stuff going on in this stuff, hard to keep track of it
And yeah, errors are a part of programming - thanks for letting me know
Re: Help with a Polynomial Program
You started out properly defining member functions in your cpp...
Code:
returnType ClassName::MethodName(ParameterType paramValue,...) {}
but halfway down you started to declare raw functions.....
also in your header you have "using namespace std;". This should NEVER be used in a header file. The reason is simple. If anyone, anywhere, anytime includes your header the std namespace is activated. This may not be desired. You should always be explicit "std::string" in header files.
Get the code you have to compile clean. Remember that routines declared to return a value, must return a value, but just put dummies in for now.
Once you get the code to compile, then you can make sure that you instanciate the object properly from main() and can call the routines required to accomplist your tasks. Just put some simple tracing "cout<<"In methon xxx()"<<endl;" in the bodies of the routines to see who is calling who.
Then you can attack the mathematical aspects of each method independantly.
Good Luck.
Re: Help with a Polynomial Program
Thanks Wizard, you're right I'm trying to do too much at once. I'm still learning about how to best debug and start from the bottom up, building to a higher level and more complicated design from basic stuff.
I'm gonna keep working on this - any other help from people is welcome.
Thanks for everything so far!
Re: Help with a Polynomial Program
Re: Help with a Polynomial Program
Quote:
about how to best debug and start from the bottom up,
The techniques I outlined earlier are actually "top-down". Build the skeleton then fill in the details.
"bootom-up" would involve writing small little programs that proved the implementation for one very small specific detail This can be difficult to do, and typically involves duplication of effort.
Re: Help with a Polynomial Program
Ah ok, I gotcha--makes sense. Think we were thinking the same general thing, I just used the wrong terminology.
Re: Help with a Polynomial Program
u had not attached the completed program.
prioblems what i found
1.
Code:
// subtracting Polynomial
Polynomial operator-(const Polynomial &P,
const Polynomial &Q) {
return P.Add(-Q);
}
how can u use - operator as -Q for an object . I doubt't putting - sign does not make the coff. part of object -ve.
2.
Code:
Polynomial degree;
cout << "Enter the highest degree of your polynomial: ";
cin >> degree;
Polynomial coefficients[degree];
u overload the >> operator but u had not define Insert opeartor.
degree is object of Polynomial class how can u provede object degree as size of array coeeficients