1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166

#include "polynomial.h"
polynomial::polynomial()
:fx(NULL), polyDegree(0),critPnts(NULL), numCritPnts(0), realRoots(NULL), numRealRoots(0), endRight(false), endLeft(false), deriv(NULL){}
polynomial::polynomial(const double* func, unsigned l)
:polyDegree(l),critPnts(NULL), numCritPnts(0), realRoots(NULL), numRealRoots(0), deriv(NULL)
{
fx = new double[l];
for(int i = 0; i <= l; i++)
{
fx[i] = func[i];
}
}
polynomial::polynomial(const polynomial& f)
:critPnts(NULL), polyDegree(f.polyDegree), realRoots(NULL), numCritPnts(0), numRealRoots(0), endRight(false), endLeft(false), deriv(NULL)
{
fx = new double(f.polyDegree + 1);
for(int i = 0; i <= polyDegree; i++)
{
fx[i] = f.fx[i];
}
}
polynomial::~polynomial()
{
polynomial* temp = this;
do
{
delete[] temp>fx;
delete[] temp>critPnts;
delete[] temp>realRoots;
temp = temp>deriv;
} while (temp != NULL);
}
void polynomial::derivative()
{
if (polyDegree == 1)
{
return;
}
deriv = new polynomial;
deriv>fx = new double[polyDegree];
deriv>polyDegree = polyDegree1;
for(int i = 1; i <= polyDegree; i++)
{
deriv>fx[i1] = fx[i] * i;
}
cout << *deriv << endl;
deriv>derivative();
}
polynomial polynomial::fPrime(unsigned prime)
{
polynomial* temp;
polynomial* temp2;
if (deriv == NULL)
{
this>derivative();
}
temp = this;
for (int i = 0; i < prime; i++)
{
temp = temp>deriv;
if (temp == NULL)
{
return *temp;
}
}
temp2 = new polynomial;
temp2>fx = new double[temp>polyDegree + 1];
temp2>polyDegree = temp>polyDegree;
for(int i = 0; i <= temp>polyDegree; i++)
{
temp2>fx[i] = temp>fx[i];
}
return *temp2;
}
double polynomial::f()
{
}
void polynomial::write()
{
}
ostream& operator<< (ostream& os, const polynomial& p)
{
if (p.polyDegree == 1)
{
os << p.fx[1] << "x ";
if (p.fx[0] > 0)
{
os << "+ " << p.fx[0];
}
else
{
os << " " << (p.fx[0]) *1;
}
return os;
}
if (p.polyDegree == 0)
{
if (p.fx != NULL)
{
os << p.fx[0];
}
return os;
}
os << p.fx[p.polyDegree] << "x" << p.polyDegree << " ";
for (int i = p.polyDegree 1; i >= 2; i)
{
if (p.fx[i] > 0)
{
os << "+ " << p.fx[i] << "x" << i << " ";
}
else
{
os << " " << (p.fx[i])* 1 << "x" << i << " ";
}
}
if (p.fx[1] > 0)
{
os << "+ " << p.fx[1] << "x ";
}
else
{
os << " " << (p.fx[1]) *1 << "x ";
}
if (p.fx[0] > 0)
{
os << "+ " << p.fx[0];
}
else
{
os << " " << (p.fx[0]) * 1;
}
return os;
}
 