Language: C++

#include<iostream> #include<math.h> #include<iomanip> using namespace std; class Node { public: int epo; float coe; Node* next; Node(){epo = 0;coe = 0;next = NULL;} Node(int n){epo = n;coe = 0;next = NULL;} Node(int epo, float coe){this->epo = epo;this->coe = coe;next = NULL;} }; class Polynomial { public: Polynomial(int n); void inser(int, float); void add(Node*); void display(); Node* polynomial; private: Node* current; }; Polynomial::Polynomial(int n) { Node* p = new Node(n); polynomial = p; current = p; p = NULL; } void Polynomial::inser(int epo, float coe) { Node* p = new Node(epo, coe); current->next = p; current = current->next; p = NULL; return; } void Polynomial::add(Node* polynomial) { Node* p = new Node(); Node* q = new Node(); Polynomial poly(0); p = this->polynomial->next; q = polynomial->next; while((p != NULL) && (q != NULL)) { while((p != NULL) && (q != NULL) && (p->epo != q->epo)) { if(p->epo > q->epo) { poly.inser(p->epo, p->coe); poly.polynomial->epo += 1; p = p->next; } else { poly.inser(q->epo, q->coe); poly.polynomial->epo += 1; q = q->next; } } if((p != NULL) && (q != NULL)) { if(p->coe + q->coe != 0) { poly.inser(p->epo, p->coe + q->coe); poly.polynomial->epo += 1; } p = p->next; q = q->next; } } while(p != NULL) { poly.inser(p->epo, p->coe); poly.polynomial->epo += 1; p = p->next; } while(q != NULL) { poly.inser(q->epo, q->coe); poly.polynomial->epo += 1; q = q->next; } poly.display(); return; } void Polynomial::display() { Node* p = new Node(); p = polynomial->next; cout << polynomial->epo; if(polynomial->epo == 0) return; for(int i = 0;i < polynomial->epo;i ++) { cout << " " << p->epo; cout << " " << setiosflags(ios::fixed) << setprecision(1) << p->coe; p = p->next; } p = NULL; } int main() { int k; cin >> k; Polynomial p1(k); int poep1[k]; float poco1[k]; for(int i = 0;i < k;i ++) { cin >> poep1[i] >> poco1[i]; p1.inser(poep1[i], poco1[i]); } cin >> k; Polynomial p2(k); int poep2[k]; float poco2[k]; for(int i = 0;i < k;i ++) { cin >> poep2[i] >> poco2[i]; p2.inser(poep2[i], poco2[i]); } p1.add(p2.polynomial); return 0; }

Compiler output:
a.cc:1:20: warning: extra tokens at end of #include directive
    1 | #include<iostream> #include<math.h> #include<iomanip> using namespace std; class Node { public: int epo; float coe; Node* next; Node(){epo = 0;coe = 0;next = NULL;} Node(int n){epo = n;coe = 0;next = NULL;} Node(int epo, float coe){this->epo = epo;this->coe = coe;next = NULL;} }; class Polynomial { public: Polynomial(int n); void inser(int, float); void add(Node*); void display(); Node* polynomial; private: Node* current; }; Polynomial::Polynomial(int n) { Node* p = new Node(n); polynomial = p; current = p; p = NULL; } void Polynomial::inser(int epo, float coe) { Node* p = new Node(epo, coe); current->next = p; current = current->next; p = NULL; return; } void Polynomial::add(Node* polynomial) { Node* p = new Node(); Node* q = new Node(); Polynomial poly(0); p = this->polynomial->next; q = polynomial->next; while((p != NULL) && (q != NULL)) { while((p != NULL) && (q != NULL) && (p->epo != q->epo)) { if(p->epo > q->epo) { poly.inser(p->epo, p->coe); poly.polynomial->epo += 1; p = p->next; } else { poly.inser(q->epo, q->coe); poly.polynomial->epo += 1; q = q->next; } } if((p != NULL) && (q != NULL)) { if(p->coe + q->coe != 0) { poly.inser(p->epo, p->coe + q->coe); poly.polynomial->epo += 1; } p = p->next; q = q->next; } } while(p != NULL) { poly.inser(p->epo, p->coe); poly.polynomial->epo += 1; p = p->next; } while(q != NULL) { poly.inser(q->epo, q->coe); poly.polynomial->epo += 1; q = q->next; } poly.display(); return; } void Polynomial::display() { Node* p = new Node(); p = polynomial->next; cout << polynomial->epo; if(polynomial->epo == 0) return; for(int i = 0;i < polynomial->epo;i ++) { cout << " " << p->epo; cout << " " << setiosflags(ios::fixed) << setprecision(1) << p->coe; p = p->next; } p = NULL; } int main() { int k; cin >> k; Polynomial p1(k); int poep1[k]; float poco1[k]; for(int i = 0;i < k;i ++) { cin >> poep1[i] >> poco1[i]; p1.inser(poep1[i], poco1[i]); } cin >> k; Polynomial p2(k); int poep2[k]; float poco2[k]; for(int i = 0;i < k;i ++) { cin >> poep2[i] >> poco2[i]; p2.inser(poep2[i], poco2[i]); } p1.add(p2.polynomial); return 0; }
      |                    ^
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/14/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
collect2: error: ld returned 1 exit status