Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- File: Polynomial.h
- Description: The interface header file for the Polynomial class. Each node of the linked list represents a power with a coefficient (ex: 3x^2). Constructors, member functions, and operator overloading functions have been included.
- */
- #ifndef POLYNOMIAL_H
- #define POLYNOMIAL_H
- #include <iostream>
- using namespace std;
- struct PolyNode
- {
- int power; // Represents the power of x
- int coefficient; // Represents the coefficient corresponding to the power of x
- PolyNode* node; // Pointer of the structure type that will be utilized as the main linked list.
- };
- typedef PolyNode* PolyPtr; // Now, PolyPtr is the same thing as PolyNode*
- class Polynomial
- {
- private:
- PolyPtr poly; // Variable of the pointer type.
- int calculate_coefficient(string& poly_temp, string symbol); // Extra function that calculates the coefficient based on the sign (+ or -).
- void remove_nodes(PolyPtr parameter); // Extra function that will delete a selected node.
- public:
- Polynomial(); // Default constructor
- Polynomial(const Polynomial& original); // Copy constructor
- Polynomial(int); // Constructor that produces the polynomial that has only one constant term
- Polynomial(int,int); // Constructor that produces the 1-term polynomial whose coefficient and exponent are given by the 2 arguments.
- ~Polynomial(); // Destructor
- void insert_polynomial(); // Lets the user input the polynomial, and the function returns that linked list to the user.
- void make_lists(int constant, int exponent); // Inserts the polynomial into a node of the linked list.
- void return_polynomial(); // Outputs the polynomial to the user.
- Polynomial operator =(const Polynomial& right); // If the copy constructor and destructor were defined, it is highly recommended that the assignment operator is overloaded.
- friend Polynomial operator +(const Polynomial& left, const Polynomial& right); // Overloading the plus operator.
- friend Polynomial operator -(const Polynomial& left, const Polynomial& right); // Overloading the minus operator.
- friend Polynomial operator *(const Polynomial& left, const Polynomial& right); // Overloading the multiplication operator.
- int evaluate(int value); // Evaluates the polynomial at that value.
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement