Question

In: Computer Science

class Function {     public:     virtual double compute(double value) = 0;     virtual double differenciate(double value) = 0;...

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

Solutions

Expert Solution


Related Solutions

C++: FramedI is an interface and appears as: class FramedI { public: virtual string getText()=0; virtual...
C++: FramedI is an interface and appears as: class FramedI { public: virtual string getText()=0; virtual char getFrameChar() =0; }; You must implement the interface and call the class FramedText. It must implement the FramedI interface. Any attributes used in the FramedText class MUST be private. Create a function called void showFramedText(ostream&, FramedI&); If the text to display is "Here's my text here" and the framing character is '*', the function must output *********************** * Here's my text here *...
List.h template class List { // List class ADT              public:    virtual void...
List.h template class List { // List class ADT              public:    virtual void clear() = 0; // Inserts an item into the list at position index    virtual bool insert(const ListItemType& newItem) = 0;    // Append "it" at the end of the list    // The client must ensure that the list's capacity is not exceeded    virtual bool append(const ListItemType& newItem) = 0;    // Deletes an item from the list at a given position...
public class MyLinked {    static class Node {        public Node (double item, Node...
public class MyLinked {    static class Node {        public Node (double item, Node next) { this.item = item; this.next = next; }        public double item;        public Node next;    }    int N;    Node first;     // remove all occurrences of item from the list    public void remove (double item) {        // TODO    } Write the remove function. Do NOT add any fields to the node/list classes, do...
Please Fix Syntax Error import java.util.Scanner; public class SalaryCalc {    double Rpay = 0, Opay...
Please Fix Syntax Error import java.util.Scanner; public class SalaryCalc {    double Rpay = 0, Opay = 0;    void calPay(double hours, double rate) {        if (hours <= 40) {            Rpay = hours * rate;            Opay = 0;        } else {            double Rhr, Ohr;            Rhr = 40;            Ohr = hours - Rhr;            Rpay = Rhr * rate;   ...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y;...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y; public MyPoint() { this(0, 0); } public MyPoint(double x, double y) { this.x = x; this.y = y; } // Returns the distance between this MyPoint and other public double distance(MyPoint other) { return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.y - y, 2)); } // Determines if this MyPoint is equivalent to another MyPoint public boolean equals(MyPoint other) { return this.x == other.x &&...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y;...
Consider the following class: import java.util.Scanner; public class MyPoint { private double x; private double y; public MyPoint() { this(0, 0); } public MyPoint(double x, double y) { this.x = x; this.y = y; } // Returns the distance between this MyPoint and other public double distance(MyPoint other) { return Math.sqrt(Math.pow(other.x - x, 2) + Math.pow(other.y - y, 2)); } // Determines if this MyPoint is equivalent to another MyPoint public boolean equals(MyPoint other) { return this.x == other.x &&...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** *...
COMPLETE JAVA CODE public class Point2 { private double x; private double y;    /** * Create a point with coordinates <code>(0, 0)</code>. */ public Point2() { complete JAVA code this.set(0.0, 0.0); COMPLETE CODE }    /** * Create a point with coordinates <code>(newX, newY)</code>. * * @param newX the x-coordinate of the point * @param newY the y-coordinate of the point */ public Point2(double newX, double newY) { complete Java code this.set(newX, newY); }    /** * Create a...
A incomplete definition of a class Temperature is given below: public class Temperature { private double...
A incomplete definition of a class Temperature is given below: public class Temperature { private double value[] = {36.5, 40, 37, 38.3}; } [6] (i) Copy and put it in a new class. Write a method toString() of the class, which does not have any parameters and returns a string containing all the values separated by newlines. When the string is printed, each value should appear on a line in the ascending order of their indexes. Copy the content of...
import java.util.Random; class Conversions { public static void main(String[] args) { public static double quartsToGallons(double quarts)...
import java.util.Random; class Conversions { public static void main(String[] args) { public static double quartsToGallons(double quarts) { return quarts * 0.25; } public static double milesToFeet(double miles) { return miles * 5280; } public static double milesToInches(double miles) { return miles * 63360; } public static double milesToYards(double miles) { return miles * 1760; } public static double milesToMeters(double miles) { return miles * 1609.34; } public static double milesToKilometer(double miles) { return milesToMeters(miles) / 1000.0; } public static double...
Study the following class definition: class Car { public: Car(double speed); void start(); void accelerate(double speed);...
Study the following class definition: class Car { public: Car(double speed); void start(); void accelerate(double speed); void stop(); double get_speed() const; private: double speed; }; Which of the following options would make logical sense in the definition of the void accelerate(double speed)function? Group of answer choices this->speed = this->speed; this->speed = speed; this.speed = speed; speed1 = this->speed; Flag this Question Question 131 pts The Point class has a public function called display_point(). What is the correct way of calling...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT