The above declaration was used to create polynomial equation
The above declaration was used to create polynomial equation as a part of the first assignment. Your task now is to write the code for BOTH main function and sum member function. A. The main function should declare an object first and then write a COMPLETE CODE to create a link list with 9 nodes using the set member function. Also write a calling statement to the sum member function and output the result. B. Write a COMPLETE code for the sum member function. The purpose of this function is to sum the coeff of all the exponents that are even.
Solution
(A)
e::e()
{
node = NULL;
coeff = 0;
exp =0;
}
e::~e()
{
node * q;
while (node != NULL) {
q = node->next;
delete node;
node = q;
}
}
void e::set(int c, int e)
{
node* temp = node;
if (temp == NULL) {
temp = new node;
node = temp;
}
else {
while (temp->next != NULL)
temp = temp->next;
temp->next = new node;
temp = temp->next;
}
temp->coeff = c;
temp->exp = e;
temp->next = NULL;
}
void e::printequation()
{
node* temp = node;
int f = 0;
cout << endl;
while (temp != NULL)
{ if (f != 0)
{ if (temp->coeff > 0)
cout << \" + \";
else
cout << \" \";
} if (temp->exp != 0)
cout << temp->coeff << \"x^\" << temp->exp;
else
cout << temp->coeff;
temp = temp->link;
f = 1;
}
}

