Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This project will require you to create a program that will take a mathematical expression in a single variable ( x ) and either evaluate
This project will require you to create a program that will take a mathematical expression in a single variable x and either
evaluate the expression for a given value of x or
calculate the derivative with respect to x of the expression
The purpose of this project is to demonstrate a working knowledge of
Class creation
Inheritance
Polymorphism
You will need the following subclasses of AbstractTerm:
A ConstantTerm object will represent a term of the form
pm a
where a is of type int. The derivative of a constant term is always
A LinearTerm object will represent a term of the form
pm ax
where a is of type int and x is the independent variable. The derivative of a linear term is a constant term of the form
pm a
A PolynomialTerm object will represent a term of the form
pm axb
where a is of type int, b is a positive int greater than one, and x is the independent variable. If b the derivative of the polynomial term is a polynomial term of the form
pm abxb
If b the derivative of the polynomial term is a linear term of the form
pm ax
A TrigTerm object will represent a term of the form
pm a cosx
or
pm a sinx
where a is of type int and x is the independent variable. The derivative of the sine term is a trigonometric term of the form
pm a cosx
The derivative of the cosine term is a sine term of the form
a sinx
Note that the sign flips when taking the derivative of cos Evaluation of trigonometric functions should be done in degrees.
Each subclass of AbstractTerm will need to override the following pure virtual functions:
derivative returns a new AbstractTerm that represents the derivative of the current term
evaluatedouble returns the evaluation of the term with the double value substituted for x
toString returns a string representation of the term see below for examples
TrigType Enumeration
The TrigType enumeration should have two values used to distinguish between the trigonometric functions:
COSINE
SINE
Expression class
The Expression class will need to contain an array or vector of AbstractTerms. It will also need the following functions:
getDerivative returns a new Expression object containing the derivative of each term of the original object. Zerovalued constant terms should not be included.
getEvaluationdouble returns the sum of the evaluations of the individual terms.
toString returns a string version of the expression. The polynomial terms should be displayed in descending exponential order, followed by linear, constant, sine and cosine
An overloaded operator that will add an AbstractTerm to the expression
A destructor that will delete all of the terms in the expression
main
The main function will not be tested. Use it for your own tests.
EXAMPLE
AbstractTerm t new LinearTerm;
AbstractTerm t new PolynomialTerm;
AbstractTerm t new TrigTerm TrigType::COSINE;
cout ttoString endl; x
cout tevaluate endl;
cout ttoString endl; x
cout tevaluate endl;
cout ttoString endl; cosx
cout tevaluate endl;
Expression e new Expression;
e t;
e t;
e t;
Expression e egetDerivative;
cout etoString endl; xx cosx
cout etoString endl; xsinx
cout egetEvaluation endl;
cout egetEvaluation endl;
delete e;
delete e;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started