#include "polynomialType.h" #include using namespace std; polynomialType::polynomialType(int size) : arrayListType(size) { length = size; for(int i = 0; i < size; i++) list[i] = 0; } double polynomialType::operator() (double x) { double value = 0.0; for(int i = 0; i < length; i++) { if(list[i] != 0.0) value = value + list[i] * pow(x,i); } return value; } polynomialType polynomialType::operator+ (const polynomialType& right) { int size = max(length, right.length); int i; polynomialType temp(size); for(i = 0; i < min(length, right.length); i++) temp.list[i] = list[i] + right.list[i]; if(size == length) for(i = min(length, right.length); i < length; i++) temp.list[i] = list[i]; else for(i = min(length, right.length); i < right.length; i++) temp.list[i] = right.list[i]; return temp; } polynomialType polynomialType::operator- (const polynomialType& right) { int size = max(length, right.length); int i; polynomialType temp(size); for(i = 0; i < min(length, right.length); i++) temp.list[i] = list[i] - right.list[i]; if(size == length) for(i = min(length, right.length); i < length; i++) temp.list[i] = list[i]; else for(i = min(length, right.length); i < right.length; i++) temp.list[i] = -right.list[i]; return temp; } polynomialType polynomialType::operator* (const polynomialType& right) { int m; int i; int arraySize; arraySize = (right.length +length) - 1; polynomialType temp(arraySize); for(m = 0; m < arraySize; m++) { temp.list[m] = 0; for(i = 0; i <= min(m, length); i++) { if(length > i && right.length > (m-i)) temp.list[m] += [{right.list[m - i]*list[i])]; } } return temp; } int polynomialType::min(int x, int y) { if(x <= y) return x; else return y; } int polynomialType::max(int x, int y) { if(x >= y) return x; else return y; } ostream& operator<<(ostream& os, const polynomialType& p) { int i; int indexFirstNonzeroCoeff = 0; for(i = 0; i < p.length; i++) if(p.list[i] != 0.0) { indexFirstNonzeroCoeff = i; break; } if(indexFirstNonzeroCoeff < p.length) { if(indexFirstNonzeroCoeff == 0) os<= 0.0) os<<"+ "<>(istream& is, polynomialType& p) { cout<<"The degree of this polynomial is: " <>p.list[i]; } return is; }