Answered step by step
Verified Expert Solution
Link Copied!

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 sub-classes 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
+0
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 ax^b
where a is of type int, b is a positive int greater than one, and x is the independent variable. If b>2, the derivative of the polynomial term is a polynomial term of the form
\pm (ab)x^(b-1)
If b=2, the derivative of the polynomial term is a linear term of the form
\pm 2ax
A TrigTerm object will represent a term of the form
\pm a cos(x)
or
\pm a sin(x)
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 cos(x)
The derivative of the cosine term is a sine term of the form
a sin(x)
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
evaluate(double)- 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. Zero-valued constant terms should not be included.
getEvaluation(double)- 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* t1= new LinearTerm(5);
AbstractTerm* t2= new PolynomialTerm(-4,3);
AbstractTerm* t3= new TrigTerm(-6, TrigType::COSINE);
cout t1->toString() endl; //+5x
cout t1->evaluate(5) endl; //25
cout t2->toString() endl; //-4x^3
cout t2->evaluate(2) endl; //-32
cout t3->toString() endl; //-6cos(x)
cout t3->evaluate(45) endl; //-4.24
Expression* e1= new Expression();
(*e1)+= t1;
(*e1)+= t2;
(*e1)+= t3;
Expression* e2= e1->getDerivative();
cout e1->toString() endl; //-4x^3+5x -6cos(x)
cout e2->toString() endl; //-12x^2+5+6sin(x)
cout e1->getEvaluation(0) endl; //-6
cout e2->getEvaluation(0) endl; //5
delete e2;
delete e1;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions