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

The above declaration was used to create polynomial equation as a part of the fi

ID: 3800353 • Letter: T

Question

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.

Explanation / Answer

(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;
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote