Advertisement
Guest User

Polynomial.h

a guest
Mar 27th, 2015
330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.35 KB | None | 0 0
  1. /*
  2.     File: Polynomial.h
  3.     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.
  4. */
  5.  
  6. #ifndef POLYNOMIAL_H
  7. #define POLYNOMIAL_H
  8.  
  9. #include <iostream>
  10. using namespace std;
  11.  
  12. struct PolyNode
  13. {
  14.     int power; // Represents the power of x
  15.     int coefficient; // Represents the coefficient corresponding to the power of x
  16.     PolyNode* node; // Pointer of the structure type that will be utilized as the main linked list.
  17. };
  18.  
  19. typedef PolyNode* PolyPtr; // Now, PolyPtr is the same thing as PolyNode*
  20.  
  21. class Polynomial
  22. {
  23.     private:
  24.         PolyPtr poly; // Variable of the pointer type.
  25.         int calculate_coefficient(string& poly_temp, string symbol); // Extra function that calculates the coefficient based on the sign (+ or -).
  26.         void remove_nodes(PolyPtr parameter); // Extra function that will delete a selected node.
  27.     public:
  28.         Polynomial(); // Default constructor
  29.         Polynomial(const Polynomial& original); // Copy constructor
  30.         Polynomial(int); // Constructor that produces the polynomial that has only one constant term
  31.         Polynomial(int,int); // Constructor that produces the 1-term polynomial whose coefficient and exponent are given by the 2 arguments.
  32.         ~Polynomial(); // Destructor
  33.         void insert_polynomial(); // Lets the user input the polynomial, and the function returns that linked list to the user.
  34.         void make_lists(int constant, int exponent); // Inserts the polynomial into a node of the linked list.
  35.         void return_polynomial(); // Outputs the polynomial to the user.
  36.         Polynomial operator =(const Polynomial& right); // If the copy constructor and destructor were defined, it is highly recommended that the assignment operator is overloaded.
  37.         friend Polynomial operator +(const Polynomial& left, const Polynomial& right); // Overloading the plus operator.
  38.         friend Polynomial operator -(const Polynomial& left, const Polynomial& right); // Overloading the minus operator.
  39.         friend Polynomial operator *(const Polynomial& left, const Polynomial& right); // Overloading the multiplication operator.
  40.         int evaluate(int value); // Evaluates the polynomial at that value.
  41. };
  42.  
  43. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement