Create a class for an algebraic formula in a single variable. As a reminder, such a formula has the form: n n-1 2 1 0 a x + a x + ... a x + a x + a x n n-1 2 1 0 Or: n ----- \ i > a x / i ----- i=0 (Same formula, different format...) Construct the formula from the variable name (char or String?) and the number of terms. Overload subscript to allow your user to set/access the coefficients. (Coefficients should start as 0by default.) Overload output to print the formula as neatly as possible (you won't need the subscripts; you may use ^instead of the superscripts). Ignore input for now...that can get pretty twisted. Overload addition to add two such formulas (if you take the variable name into account, adding two formulas in different variables should result in an empty formula; that's a head-ache we don't need right now) — element-wise add the coefficients (a0of the first formula plus a0of the second formula). You should be able to add formulas with a different number of coefficients.
Create a class for an algebraic formula in a single variable. As a reminder, such a formula has the form:
n n-1 2 1 0 a x + a x + ... a x + a x + a x n n-1 2 1 0
Or:
n ----- \ i > a x / i ----- i=0
(Same formula, different format...)
Construct the formula from the variable name (char or String?) and the number of terms. Overload subscript to allow your user to set/access the coefficients. (Coefficients should start as 0by default.)
Overload output to print the formula as neatly as possible (you won't need the subscripts; you may use ^instead of the superscripts). Ignore input for now...that can get pretty twisted.
Overload addition to add two such formulas (if you take the variable name into account, adding two formulas in different variables should result in an empty formula; that's a head-ache we don't need right now) — element-wise add the coefficients (a0of the first formula plus a0of the second formula). You should be able to add formulas with a different number of coefficients.
Overload multiplication between a formula and a scalar (single real number value) so that the programmer can multiply either 'scalar * formula' or 'formula * scalar'. The result (either way) should be the scalar multiplied element-wise by all the coefficients.
Addition, subtraction, and division by a scalar should be done as well. (You may find having an operator - in unary form handy for the subtraction implementation...*wink,wink* *nudge,nudge* Say no more...) (Warning! 'formula / scalar' is well defined, but 'scalar / formula' is waybeyond the scope of this programming assignment!)
While overloading assignment, do +=, -=, *=, and /= similarly to above.
Include any other constructors, destructors, or methods that seem necessary/useful. (Maybe one for returning the order — highest power — of the formula would be nice. And for returning the variable name? *shrug*)
Write a driver to show off your formula class' abilities.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 1 images