Albar_237739.cpp - #include <iostream> using namespace std class Node public int data Node next Node Node(int Node:Node data = 0 next = NULL

Albar_237739.cpp - #include <iostream> using namespace std...

This preview shows page 1 - 3 out of 3 pages.

#include <iostream> using namespace std; class Node { public: int data; Node* next; Node(); Node(int); }; Node::Node() { data = 0; next = NULL; } Node::Node(int x) { data = x; next = NULL; } class PolyLinkedList { private: Node* head; public: PolyLinkedList(); void AppendtoList(int); void displayListElements(); int callelement(int); }; PolyLinkedList::PolyLinkedList() { head = NULL; } void PolyLinkedList::AppendtoList(int x) { Node* tempnode = new Node; tempnode->data = x; if (head == NULL) { head = tempnode; } else { Node* temppointer = head; while (temppointer->next != NULL) { temppointer = temppointer->next; } temppointer->next = tempnode; } } void PolyLinkedList::displayListElements() { int i=0; if (head == NULL)
Image of page 1

Subscribe to view the full document.

{ cout << "List is empty" << endl; } else { Node* t_ptr = head; while (t_ptr != NULL) { if(t_ptr->data!=0) { cout << t_ptr->data << "x^"<<i<<" + "; } t_ptr = t_ptr->next; i=i+1; } cout << "NULL"<<endl; } } int PolyLinkedList::callelement(int x) { int i = 1; Node* tempPointer = head; while (i < x) { tempPointer = tempPointer->next; i = i + 1; } return tempPointer->data; } int main() { PolyLinkedList Poly1, Poly2, PolySums; int userinput = 0,i=0,zeros,ord,a,L1,L2; cout << "Please enter the coefficients for variable of Polynomial #1 : "
Image of page 2
Image of page 3

Unformatted text preview: &lt;&lt; endl &lt;&lt; &quot;Enter order of polynomial: &quot;; cin&gt;&gt; L1; while (i &lt;= L1) { cout &lt;&lt; &quot;Coefficient for x^&quot; &lt;&lt; i &lt;&lt;&quot; :&quot;; cin &gt;&gt; userinput; if (i &lt;= L1) { Poly1.AppendtoList(userinput); } i=i+1; } userinput = 0,i=0; cout &lt;&lt; endl&lt;&lt;&quot;Please enter the coefficients for variable of Polynomial #2 : &quot; &lt;&lt; endl &lt;&lt; &quot;Enter order of polynomial: &quot;; cin&gt;&gt; L2; while (i &lt;= L2) { cout &lt;&lt; &quot;Coefficient for x^&quot; &lt;&lt; i &lt;&lt;&quot; :&quot;; cin &gt;&gt; userinput; if (i &lt;= L2) { Poly2.AppendtoList(userinput); } i=i+1; } if (L1 &gt; L2) { a=L1; zeros = L1 - L2; for (i = 0; i &lt; zeros; i++) { Poly2.AppendtoList(0); } } else if (L1 &lt; L2) { a= L2; zeros = L1-L2; for (i = 0; i &lt; zeros; i++) { Poly1.AppendtoList(0); } } cout &lt;&lt; endl&lt;&lt; &quot;Displaying Polynomial # 1&quot; &lt;&lt; endl; Poly1.displayListElements(); cout &lt;&lt; endl&lt;&lt; &quot;Displaying Polynomial # 2&quot; &lt;&lt; endl; Poly2.displayListElements(); a=a+1; for (i = 1; i &lt;= a; i++) { PolySums.AppendtoList(Poly1.callelement(i) + Poly2.callelement(i)); } cout &lt;&lt; endl&lt;&lt; &quot;Displaying Sum of Polynomial&quot; &lt;&lt; endl; PolySums.displayListElements(); int y; cin &gt;&gt; y; return 0; }...
View Full Document

  • Fall '19
  • Sir. Kashaf

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes