Question: B . Create a new class called Term to represent a term in a polynomial such as 2 x 4 or 9 x 2 .

B. Create a new class called Term to represent a term in a polynomial such as 2x4 or 9x2.
The Term class should have the following capabilities:
It should have two private data members of type int called coefficient and exponent.
It should have exactly one constructor with 2 parameters (the first parameter for a coefficient value and the
second parameter for an exponent value) that enables an object of Term class to be initialized when it is
declared. The constructor should contain default values which would initialize coefficient and exponent to 0s if
no values are provided in a constructor call.
The class should have getter and setter methods for coefficient and exponent: setCoefficiend, setExponent,
getCoefficient, getExponent.
Overload the addition, subtraction, and multiplication operators for this class: operatort, operator-,
operator*. The overloaded operators should be implemented as member functions of the class.
For the purpose of this assignment:
Adding Terms can only be done if the exponents are the same: axn+bxa=(a+b)xn
Subtracting Terms can only be done if the exponents are the same: axn-bxn=(a-b)xn
If the exponents aren't the same, the addition and subtraction operators should return a Term with 0
as the coefficient and 0 as the exponent.
Multiplication: axn**bxn=(a**b)x(n+a)
Overload the binary stream extraction and stream insertion operators (see how to do it in section 18.5 of the
textbook). Declare stream extraction and stream insertion operators as friends of the class. Stream extraction
operator should allow to input Term objects in the following customary format:
2x4or9x2
where ?? is used to indicate the exponent (instead of a superscript).
Stream insertion operator should allow to output Term object in the same customary format, e.g.
2x4or9x2
(coefficient followed by x?, followed by exponent).
C. Separate interface and implementation for Term class. Create two files: Term.h (class definition containing
function prototypes) and Term.cpp (implementations of member functions and overloaded stream insertion and
stream extraction operators). Make sure to use include guard in Term.h.
D. Write a test program named Labl0.cpp that will test all the functions of Term class and overloaded stream
insertion and stream extraction operators.
Your test program should contain statements such as:
Note that for the addition and subtraction operators you need to have at least 2 tests for each: one test for the
terms with the same exponents and one test for the terms with different exponents.
B . Create a new class called Term to represent a

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!