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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education