Question

Question 2 Implement a C++ class that represents a Third Degree Polynomials equation. Your class must...

Question 2 Implement a C++ class that represents a Third Degree Polynomials equation. Your class must include a default constructor, observers, mutators, equality operators and one helper functions to evaluate the equation. y=ax3+bx2+cx+d

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
using namespace std;

class Polynomial {
private:
    double a, b, c, d;
public:
    Polynomial() {}

    Polynomial(double a, double b, double c, double d) : a(a), b(b), c(c), d(d) {}

    double getA() {
        return a;
    }

    void setA(double a) {
        Polynomial::a = a;
    }

    double getB() {
        return b;
    }

    void setB(double b) {
        Polynomial::b = b;
    }

    double getC() {
        return c;
    }

    void setC(double c) {
        Polynomial::c = c;
    }

    double getD() {
        return d;
    }

    void setD(double d) {
        Polynomial::d = d;
    }

    Polynomial &operator=(const Polynomial &p) {
        a = p.a;
        b = p.b;
        c = p.c;
        d = p.d;
        return *this;
    }

    double evaluate(double x) {
        return a*x*x*x + b*x*x + c*x + d;
    }
};

int main() {
    Polynomial p(2, 3, 4, 5);
    cout << "p(2) = " << p.evaluate(2) << endl;
    return 0;
}

Add a comment
Know the answer?
Add Answer to:
Question 2 Implement a C++ class that represents a Third Degree Polynomials equation. Your class must...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the...

    Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...

  • C++ NEED AS SOON AS POSSIBLE! BigInt class is used for the mathematical operations that involve...

    C++ NEED AS SOON AS POSSIBLE! BigInt class is used for the mathematical operations that involve very big integer calculations that are outside the limit of all available primitive data types. For example, factorial of 100 contains 158 digits in it so we can’t store it in any primitive data type available. We can store as large Integer as we want in it. Your goal is to overload the operators for a generic “BigInt” class. You will need to write...

  • C++ In this assignment, you will write a class that implements a contact book entry. For...

    C++ In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class. Your Contact...

  • 3. write a c++ program: Design and implement a class called Clock that describes the time...

    3. write a c++ program: Design and implement a class called Clock that describes the time of a clock: a) Include in the class 3 constructors with one, two, and three parameters to set the hours, the minutes, and the seconds, respectively. b) Include also a default constructor that sets the member variables of the class to 00:00:00. c) Write a member function to increment the time by a given amount, and second member function to reset the clock. The...

  • Goals . Understand how to implement operator overloading in C++ Warning: Programs must compile us...

    c++ format Goals . Understand how to implement operator overloading in C++ Warning: Programs must compile using gt+ on the Computer Science Linux systems. If your code does not compile on CS machines you will get 0 for the assignment. Organize your files into folders by lab assignment. For this assignment, create a folder called Lab9. A. Read Chapter 18 B. Create a new class called RationalNumber to represent fractions. The class should have the following capabilities: 1) It should...

  • Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the c...

    C++ Question 1) Consider a class Point that models a 2-D point with x and y coordinates. Define the class point that should have the following Private data members x and y (of type int), with default values of 0 A constant ID of type int A private static integer data member named numOfPoints This data member should be o Incremented whenever a new point object is created. o Decremented whenever a point object is destructed. A default constructor An...

  • It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming...

    It must be C++ Chapter 13 Programming Challenge 2: Employee Class. See instruction: Chapter 13 Programming Challenge 2 Employee Class.pdf Program Template: // Chapter 13, Programming Challenge 2: Employee Class #include <iostream> #include <string> using namespace std; // Employee Class Declaration class Employee { private: string name; // Employee's name int idNumber; // ID number string department; // Department name string position; // Employee's position public: // TODO: Constructors // TODO: Accessors // TODO: Mutators }; // Constructor #1 Employee::Employee(string...

  • I need help implementing class string functions, any help would be appreciated, also any comments throughout...

    I need help implementing class string functions, any help would be appreciated, also any comments throughout would also be extremely helpful. Time.cpp file - #include "Time.h" #include <new> #include <string> #include <iostream> // The class name is Time. This defines a class for keeping time in hours, minutes, and AM/PM indicator. // You should create 3 private member variables for this class. An integer variable for the hours, // an integer variable for the minutes, and a char variable for...

  • For C++ This is the information about the meal class 2-1. (24 marks) Define and implement...

    For C++ This is the information about the meal class 2-1. (24 marks) Define and implement a class named Dessert, which represents a special kind of Meal. It is to be defined by inheriting from the Meal class. The Dessert class has the following constructor: Dessert (string n, int co) // creates a meal with name n, whose type // is "dessert" and cost is co The class must have a private static attribute static int nextID ; which is...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT