Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The main goal of this project is to define and implement a C++ class to compute

ID: 3588816 • Letter: T

Question

The main goal of this project is to define and implement a C++ class to compute with truncated power series. The UML class diagram of the Series class is drawn below. Series - degree - coefficients + Series O + to.stringo + copy) + operator- + operator+ + operator- + operator* + inverse) + operator/ + "SeriesO The class Series represents a truncated power series with doubles as coefficients. A series s(t) truncated at degree d has d+1 coefficients and is written as so+sit+s2t2+..+satt +O(t4+1), where the coefficients sk are doubles, for k going from 0 to d. This d is called the degree of the series. The degree and coefficients of a series are private data attributes. The degree is of type size.t. The type of the coefficients is vector, using the vector of the standard template library The class has three constructors. The first constructor takes only the degree as input parameter and returns a series with zero coefficients. The second constructor takes as input the degree and the constant leading coeficient of the series. The third constructor also has as input the degree and allows to specify all coefficients of the series. The second parameter is the address of a sequence of doubles, as many as the degree plus one (that is: d +1) of the series. The copy method coples the degree and the coefficients to the object the copy method is applied to. This copy method is used in the definition of the assignment operator. The addition and subtraction operators are straightforward, defined via the componentwise addition and subtraction. The multiplication of two series is the same as the multiplication of two polynomials, except that coefficients higher than the degree of the series need not be computed. The multiplicative inverse of a series is defined whenever the constant leading coefficient of the series is nonzero. The inverse z(t) of s(t) is defined via z(t) * s(t) = 1 + 0( 1). If the series 8(t) has coefficients Sk, then the coefficients zk of the inverse r(t) are computed as 1/so, = The division operator can then be implemented as the product of the numerator by the inverse of the denominator The destructor in the class, defined by the "Series method, sets the degree of the series to -1.

Explanation / Answer

#include<iostream>

#include<vector>

using namespace std;

class Series

{

private:

size_t degree;

vector<double> coefficients; // degree +1

public:

Series(int d)

{

this->degree = d;

for (int i = 0; i <= d; i++)

coefficients.push_back(0);

}

Series(int d, int sk)

{

this->degree = d;

for (int i = 0; i < d; i++)

coefficients.push_back(0);

coefficients.push_back(sk);

}

Series(int d, int *s)

{

this->degree = d;

for (int i = 0; i <= d; i++)

coefficients.push_back(s[i]);

}

Series& copy(const Series &sr)

{

this->degree = sr.degree;

for (int i = 0; i <= sr.degree; i++)

this->coefficients.push_back(sr.coefficients[i]);

return *this;

}

Series& operator=(const Series &sr)

{

return this->copy(sr);

}

Series& operator+(const Series &sr)

{

int degree = (this->degree> sr.degree)?this->degree:sr.degree;

Series res(degree);

for (int i = 0; i < degree; i++)

res.coefficients[i] = this->coefficients[i] + sr.coefficients[i];

return res;

}

Series& operator-(const Series &sr)

{

int degree = (this->degree> sr.degree) ? this->degree : sr.degree;

Series res(degree);

for (int i = 0; i < degree; i++)

res.coefficients[i] = this->coefficients[i] - sr.coefficients[i];

return res;

}

Series& operator*(const Series& sr)

{

}

Series& operator/(const Series& sr)

{

}

Series& inverse()

{

Series res(this->degree);

for (int i = 0; i < this->degree; i++)

{

double val = 0;

for (int j = 0; j < i; j++)

val += this->coefficients[i] * j;

res.coefficients[i] = (this->coefficients[i] ) / (this->coefficients[0]);

}

}

~Series()

{

degree = -1;

}

};