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 or
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 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 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:
Subtracting Terms can only be done if the exponents are the same:
If the exponents aren't the same, the addition and subtraction operators should return a Term with
as the coefficient and as the exponent.
Multiplication:
Overload the binary stream extraction and stream insertion operators see how to do it in section 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:
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, eg
coefficient followed by 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 Lablcpp 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 tests for each: one test for the
terms with the same exponents and one test for the terms with different exponents.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
