Author | Message |
---|---|
jpascua
Posts: 197
|
Posted 20:03 Feb 20, 2015 |
Overload the * operator to do scalar multiplication between a value and a Polynomial. Example: Poly * x would multiply the value of x to each term of the Polynomial. The operator should be overloaded in such a way that Poly * x and x * Poly both work.
Automatic type casting isn't involved right? Is it fine to overload the operator twice: first operand being x, second being the polynomial and first operand being polynomial, second being x?
• One constructor to take the highest degree of the polynomial. The degree will be the size of the dynamic array + 1.
Using the same polynomial x^3 + 2x + 1; since the highest degree is 3, the size of the dynamic array is 2?
|
jpascua
Posts: 197
|
Posted 21:09 Feb 20, 2015 |
I'm still unsure of how to create new polynomials based on the lab instructions. Is the user supposed to choose the coefficients? How? Are we to use our imagination or follow the lab instructions entirely? |
kknaur
Posts: 540
|
Posted 22:26 Feb 20, 2015 |
The constructor is used to specify the highest degree of the polynomial. If i choose a degree 4 polynomial then the highest exponent will be x^4 but you add one to the degree to calculate the size of the array (because there is an x^0 term you need to account for). You can overload the * operator and use Automatic Type Conversion, or you can overload the operator twice as you have already suggested. As far as how to initialize a Polynomial object...pay attention to what values the array actually holds, as well as what you are supposed to use the >> operator for.... |
jpascua
Posts: 197
|
Posted 22:32 Feb 20, 2015 |
Oh right, I forgot about the >> operator. Thanks for clarifying. |
harry_520
Posts: 76
|
Posted 01:44 Feb 21, 2015 |
Shouldn't the highest degree be the size of the dynamic array - 1 instead? For the example of the highest degree being 4, we should have 5 terms which makes the size of the dynamic array be 5. Last edited by harry_520 at
01:50 Feb 21, 2015.
|
jpascua
Posts: 197
|
Posted 14:46 Feb 21, 2015 |
Can I have an example for adding two polynomials together? Will it be similar to adding two vectors? Do these polynomials need the same number of terms? Last edited by jpascua at
14:46 Feb 21, 2015.
|
raywu64
Posts: 44
|
Posted 15:42 Feb 21, 2015 |
I'd assume it's the same thing as normal algebra. So all like terms are added right? |
jpascua
Posts: 197
|
Posted 16:27 Feb 21, 2015 |
Got it. Is our lab supposed to work as a dynamic class? Are we also supposed to overload the = operator (to preserve the big three)? Last edited by jpascua at
23:51 Feb 21, 2015.
|
jwarren6
Posts: 56
|
Posted 21:22 Feb 21, 2015 |
Yes, that is totally correct. Keenan's initial instruction on the lab description is wrong, but he did correct himself as described in a prior post above.
|