|
-
Dec 8th, 2003, 08:16 PM
#1
Thread Starter
Hyperactive Member
Any suggestion on Polynomial class design?
Hello everyone, I'm having troubles find the least messest way to make this program. I'm suppose to create a Polynomial class that can output the following:
Coefficients of the quadratics you created above, using the accessor functions, that is the get... functions.
How many roots each of them have
Real roots of each quadratic, if any
The result of the polynomial addition and subtraction using the overloaded operators + and -. Print out at least the sum and the difference of the quadratics given below
Q1+Q2
Q2+Q3
Q3+Q4
Q3+Q5
Q2-Q5
Q5-Q3
Q4-Q2
I got this program to work fine, it just looks messy. He told us:
Write two more member functions to return the real roots of the quadratic expression. If there are two distinct real roots one of the functions returns the smaller of the two roots, and the other returns the larger of the two roots. If every value of x is a real root, the both functions should return 10000
This makes no sense to me, why would you want 2 seperate member functions? it seems redudant to me. But my way isn't any better, I just use 1 member function, called smallerOfRoots, which finds the smaller of the roots and takes a reference parm to assign the other root.
the calling statement looks like this:
Code:
cout <<"Q2's real roots :" << Q2.smallerOfRoots(Q2.numOfRoots(),biggerRoot2) << endl;
cout <<"Q2's other root: " << biggerRoot2 << endl;
I was thinking about making another member variable, called numOfRoots, so the user doesn't have to call the Q1.numOfRoots. But thats the only cleaner thing I can think of at the moment. I was wondering if there was any way to find out if the function can see if the calling object has 2 real roots, if it does, some how print the small root and big root, but if it doens't, then jsut print the one root. the problem is, he wants us to make 2 seperate functions, why would you want to do that? then the user would have to call the smallerOfRoots function, then call the biggerOfRoots function, when the user doesn't even know if the quadratic will even have 2 roots at the time. any idea's?
Thanks.
C¤ry Sanchez
Computer Science/Engineering
@ Penn State
IBM.zSeries Intern
Mandriva 2007
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|