In: Computer Science
class Function
{
public:
virtual double compute(double value) = 0;
virtual double differenciate(double value) = 0;
virtual double integrate(double value) = 0;
};
class Sine : public Function
{
public:
double compute(double value); // compute sin(x) for a given x
double differenciate(double value); // compute derivative sin'(x) for a given x
double integrate(double value); // integrate sin(x) for a given x
};
class Tangent : public Function
{
public:
double compute(double value); // compute tan(x) for a given x
double differenciate(double value); // compute derivative tan'(x) for a given x
double integrate(double value); // integrate tan(x) for a given x
};
The classes represent mathematical functions, where each fucntion f(x) (e.g. sine, tangent) can be computed, differenciated and integrated for a given x.
Write a method named productRule to compute the derivative of a product of any two functions. Using the notation f’(x) to indicate the derivative of function f(x), the derivative of the product f(x)*g(x) is defined as f(x)*g’(x)+g(x)*f’(x), where f(x) and g(x) are any two given functions, and f’(x) and g’(x) are function derivatives, respectively. Your method should be applicable to any two functions derived from the Function interface. An example of the mehod call is given below:
Sine sin; // the sine function
Tangent tan; // the tangent function
double answer = sin.productRule(tan, 5.3); // compute the derivative of sin(5.3)/tan(5.3)
Use C++98