Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- using namespace std;
- class Polynomial
- {
- private:
- unsigned int degree;
- double* coefficients;
- public:
- char a;
- Polynomial(unsigned int n);
- ~Polynomial();
- void setCoefficient(unsigned int i, double value);
- double getCoefficient(unsigned int i);
- double value(double x);
- friend ostream & operator<<(ostream & out, Polynomial & p)
- {
- out<<p.coefficients[p.degree]<<"x^"<<p.degree;
- for(int k=p.degree-1;k>=0;k--)
- {
- if (k==1)
- {
- if(p.coefficients[k]>0)
- out<<"+";
- if (p.coefficients[k]!=0)
- {
- out<<p.coefficients[k];
- out<<"x";
- }
- }
- else if(k==0)
- {
- if (p.coefficients[k]!=0)
- {
- if(p.coefficients[k]>0)
- out<<"+";
- out<<p.coefficients[k];
- }
- else out<<"";
- }
- else{
- if (p.coefficients[k]!=0)
- {
- if(p.coefficients[k]>0)
- out<<"+";
- out<<p.coefficients[k]<<"x^"<<k;
- }
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement