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

t mode eft, xp node \"next class e f private node \"begin, last:/ begin points t

ID: 3726104 • Letter: T

Question

t mode eft, xp node "next class e f private node "begin, last:/ begin points to the first node and last points to the last node public ep: el vold assign(int, int) printequationd: string searchfint exp) The above declaration was used to create polynomial equation as a part of the assignment. Your task now is to write the code for BOTH main function and search member function A. The main function should declare an object first and then write a COMPLETE CODE to create a link list with 5 nodes using the assign member function. Also write a calling statement to the search member function and out put the result. Write a COMPLETE code for the search member function. The purpose of this function is to search B. whether the given exponent (exp) is in the list or not. If it is found return "FOUND" else return "NOT FOUND

Explanation / Answer

here is your program : ----------------------->>>>>>>>>.

#include<iostream>

using namespace std;

struct node{
int coeff;
int exp;
struct node *next;
};

class e{
node *begin,*last;

public:
  e(){
   begin = NULL;
   last = NULL;
  }
  ~e(){
   node *temp = begin;
   node *prev = begin;
   while(temp != NULL){
    prev = temp;
    temp = temp->next;
    delete prev;
   }
  }
  void assign(int coeff,int exp){
   node *temp = new node;
   temp->coeff = coeff;
   temp->exp = exp;
   temp->next = NULL;
   if(begin == NULL && last == NULL){
    begin = temp;
    last = begin;
    return;
   }else{
    last->next = temp;
    last = temp;
   }
  }
  
  void printequation(){
   cout<<endl;
   node *temp = begin;
   while(temp != NULL){
    if(temp->coeff < 0){
     cout<<"("<<temp->coeff<<")x^"<<temp->exp;
    }else{
     cout<<temp->coeff<<"x^"<<temp->exp;
    }
    if(temp->next != NULL){
     cout<<"+";
    }
    temp = temp->next;
   }
  }
  
  string search(int exp){
   node *temp = begin;
   while(temp != NULL){
    if(exp == temp->exp){
     string s = "FOUND";
     return s;
    }
    temp = temp->next;
   }
   
   string s = "NOT FOUND";
   return s;
  }
};


int main(){
e ex1;
ex1.assign(3,4);
ex1.assign(2,6);
ex1.assign(-6,2);
ex1.assign(-9,3);
ex1.assign(8,5);
ex1.printequation();
cout<<endl;
cout<<ex1.search(4)<<endl;
cout<<ex1.search(9);
}